Adapters

Basically, an adapter does the following things:

  1. accepts some context of your application and a pyws server object,
  2. builds a pyws request object out of the context,
  3. feeds the request to the server and gets a response (pyws.server.Server.process_request method),
  4. transforms the response into something that matters in the context of your application.

Django adapter

Django adapter is a simple function:

pyws.adapters._django.serve(*args, **kwargs)

Django adapter. It has three arguments:

  1. request is a Django request object,
  2. tail is everything that’s left from an URL, which adapter is attached to,
  3. server is a pyws server object.

First two are the context of an application, function serve transforms them into a pyws request object. Then it feeds the request to the server, gets the response and transforms it into a Django response object.

Twisted Web adapter

Twisted Web adapter is a simple function:

pyws.adapters._twisted.serve(request, server)

Twisted Web adapter. It has two arguments:

  1. request is a Twisted Web request object,
  2. server is a pyws server object.

First one is the context of an application, function serve transforms it into a pyws request object. Then it feeds the request to the server, gets the response, sets header Content-Type and returns response text.

WSGI adapter

WSGI adapter adapter is an application, it can be created by this function:

pyws.adapters._wsgi.create_application(server, root_url)

WSGI adapter. It creates a simple WSGI application, that can be used with any WSGI server. The arguments are:

  1. server is a pyws server object,
  2. root_url is an URL to which the server will be bound.

An application created by the function transforms WSGI environment into a pyws request object. Then it feeds the request to the server, gets the response, sets header Content-Type and returns response text.

Table Of Contents

Previous topic

Workflow

Next topic

Server

This Page