Toolserver:Python WSGI

The Python Web Server Gateway Interface is a standard interface between web servers and Python web applications or frameworks, to promote web application portability across a variety of web servers. It is fully defined in PEP 333

It uses methods similar to CGI, so that Python programs are easily ported to WSGI.

Converting CGI to WSGI
WSGI consists of an application and a gateway. The gateway translates the CGI/FCGI/SCGI/AJP request to WSGI. The stable server has Flup installed as WSGI gateway.

The application must first register itself with the WSGI gateway by providing a callable object to the gateway (a function or an object that implements __call__). When a request comes in the gateway will call the application via this callable, passing on a function start_response and an environ dictionary.

This callable should return an iterable object, such as a list or a string. This data will be passed to the client. Note that by using generators it is possible to send data while the function is still being executed. However, only yield values after start_response has been called.

Files should have the .fcgi extension.

environ
The environ dict provides CGI variables in a similar fashion as CGI. The stdin used in CGI to read postdata is replaced by environ['wsgi.input'], which is a file like object. For more information see the specification.

start_response
The start_response function is a function that indicates that sending data may start. It accepts the parameters status and headers, which indicate the HTTP status code and HTTP headers to return.

Flup
The web server has flup installed, which acts as a gateway for WSGI. Flup supports CGI, FastCGI, SimpleCGI and Apache JServ Protocol, making it useable on both the regular toolserver as the stable server.