The wsgi module builds upon the classes defined in the
cgi module to allow code originally
written with the WSGI
protocol in mind to be used unchanged with the jonpy modules.
Note: This module is currently experimental.
To use existing jonpy code with WSGI a server connector, simply use
wsgi.Application to convert your
cgi.Handler class into a
WSGI "application".
Example:
import jon.cgi as cgi
import jon.wsgi as wsgi
class Handler(cgi.Handler):
def process(self, req):
req.set_header("Content-Type", "text/plain")
req.write("Hello, world!\n")
application = wsgi.Application(Handler)
To use jonpy server connectors with WSGI applications, simply use
wsgi.create_handler to convert
your WSGI application into a
cgi.Handler class.
Example:
import jon.cgi as cgi
import jon.wsgi as wsgi
def simple_app(environ, start_response):
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
start_response(status, response_headers)
return ["Hello world!\n"]
cgi.CGIRequest(wsgi.create_handler(simple_app)).process()
Application implements a WSGI application that responds to
requests by calling the specified jonpy handler.
__init__(self, handler_type, request_type=Request)handler_type: cgi.Handler subclass
request_type: wsgi.Request subclass
Creates a new WSGI application object that responds to requests by calling
the provided jonpy handler. The optional request_type parameter
can be used to specify alternative Request classes to use - for
example, wsgi.GZipRequest.
Request subclasses the
cgi.Request class and implements
the methods using WSGI's interface.
For convenience, this class provides the standard
Request class with the
cgi.GZipMixIn already mixed
in.
Example:
cgi.CGIRequest(wsgi.create_handler(simple_app, wsgi.GZipRequest)).process()
Handler subclasses the
cgi.Handler class and implements
the methods using WSGI's interface.
This class is identical to Handler,
except that it uses
cgi.DebugHandlerMixIn so
that if an exception is thrown by a template page then a traceback will be
sent to the browser. This class may be used during development to aid debugging
but should never be used in a production environment since it will leak private
information to the browser.
create_handler(application, handler_type=Handler)create_handler creates a
cgi.Handler type that responds to
requests by calling the specified WSGI application. The optional
handler_type can be used to specify alternate parent classes
for the handler - for example,
cgi.DebugHandler.
$Id: wsgi.html,v c0f5f983a7fc 2010/03/23 01:07:17 jon $