This module provides base handler classes for implementing WSGI servers and gateways. These base classes handle most of the work of communicating with a WSGI application, as long as they are given a CGI-like environment, along with input, output, and error streams.
os.environ. This is useful when you have a WSGI application and want to run it as a CGI script. Simply invoke
appis the WSGI application object you wish to invoke.
This class is a subclass of BaseCGIHandler that sets
wsgi.run_once to true,
wsgi.multithread to false, and
wsgi.multiprocess to true, and always uses sys and
os to obtain the necessary CGI streams and environment.
|stdin, stdout, stderr, environ [, multithread=True [, multiprocess=False]])|
Similar to CGIHandler, but instead of using the sys and
os modules, the CGI environment and I/O streams are specified
explicitly. The multithread and multiprocess values are
used to set the
flags for any applications run by the handler instance.
This class is a subclass of SimpleHandler intended for use with
software other than HTTP ``origin servers''. If you are writing a
gateway protocol implementation (such as CGI, FastCGI, SCGI, etc.) that
Status: header to send an HTTP status, you probably want
to subclass this instead of SimpleHandler.
|stdin, stdout, stderr, environ [,multithread=True [, multiprocess=False]])|
Similar to BaseCGIHandler, but designed for use with HTTP origin servers. If you are writing an HTTP server implementation, you will probably want to subclass this instead of BaseCGIHandler
This class is a subclass of BaseHandler. It overrides the __init__(), get_stdin(), get_stderr(), add_cgi_vars(), _write(), and _flush() methods to support explicitly setting the environment and streams via the constructor. The supplied environment and streams are stored in the stdin, stdout, stderr, and environ attributes.
BaseHandler instances have only one method intended for external use:
All of the other BaseHandler methods are invoked by this method in the process of running the application, and thus exist primarily to allow customizing the process.
The following methods MUST be overridden in a subclass:
wsgi.inputof the request currently being processed.
wsgi.errorsof the request currently being processed.
Here are some other methods and attributes you may wish to override. This list is only a summary, however, and does not include every method that can be overridden. You should consult the docstrings and source code for additional information before attempting to create a customized BaseHandler subclass.
Attributes and methods for customizing the WSGI environment:
wsgi.multithreadenvironment variable. It defaults to true in BaseHandler, but may have a different default (or be set by the constructor) in the other subclasses.
wsgi.multiprocessenvironment variable. It defaults to true in BaseHandler, but may have a different default (or be set by the constructor) in the other subclasses.
wsgi.run_onceenvironment variable. It defaults to false in BaseHandler, but CGIHandler sets it to true by default.
os.environat the time that wsgiref.handlers was imported, but subclasses can either create their own at the class or instance level. Note that the dictionary should be considered read-only, since the default value is shared between multiple classes and instances.
SERVER_SOFTWAREWSGI environment variable, and also to set a default
Server:header in HTTP responses. It is ignored for handlers (such as BaseCGIHandler and CGIHandler) that are not HTTP origin servers.
SERVER_SOFTWAREkey if not present, as long as the origin_server attribute is a true value and the server_software attribute is set.
Methods and attributes for customizing exception handling:
(type, value, traceback)tuple. The default implementation simply writes the traceback to the request's
wsgi.errorsstream and flushes it. Subclasses can override this method to change the format or retarget the output, mail the traceback to an administrator, or whatever other action may be deemed suitable.
None, all frames are included.
This method can access the current error information using
sys.exc_info(), and should pass that information to
start_response when calling it (as described in the ``Error
Handling'' section of PEP 333).
The default implementation just uses the error_status, error_headers, and error_body attributes to generate an output page. Subclasses can override this to produce more dynamic error output.
Note, however, that it's not recommended from a security perspective to spit out diagnostics to any old user; ideally, you should have to do something special to enable diagnostic output, which is why the default implementation doesn't include any.
(name, value)tuples), as described in PEP 333. The default list just sets the content type to
Methods and attributes for PEP 333's ``Optional Platform-Specific File Handling'' feature:
None. The default value of this attribute is the FileWrapper class from wsgiref.util.
Miscellaneous methods and attributes:
This attribute's default value is true in BaseHandler, but false in BaseCGIHandler and CGIHandler.
See About this document... for information on suggesting changes.