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.
) |
sys.stdin
, sys.stdout
,
sys.stderr
and os.environ
. This is useful when you have
a WSGI application and want to run it as a CGI script. Simply invoke
CGIHandler().run(app)
, where app
is 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 wsgi.multithread
and wsgi.multiprocess
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
uses a 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:
app) |
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:
data) |
) |
) |
wsgi.input
of the request currently being processed.
) |
wsgi.errors
of 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.multithread
environment
variable. It defaults to true in BaseHandler, but may have
a different default (or be set by the constructor) in the other
subclasses.
wsgi.multiprocess
environment
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_once
environment
variable. It defaults to false in BaseHandler, but
CGIHandler sets it to true by default.
os.environ
at
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_SOFTWARE
WSGI 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_SOFTWARE
key 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:
exc_info) |
(type, value, traceback)
tuple. The default
implementation simply writes the traceback to the request's
wsgi.errors
stream 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.
environ, start_response) |
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 text/plain
.
Methods and attributes for PEP 333's ``Optional Platform-Specific File Handling'' feature:
wsgi.file_wrapper
factory, or None
. The default value
of this attribute is the FileWrapper class from
wsgiref.util.
) |
Miscellaneous methods and attributes:
Status:
header.
This attribute's default value is true in BaseHandler, but false in BaseCGIHandler and CGIHandler.
"1.0"
.
See About this document... for information on suggesting changes.