pants.web.wsgi
¶
pants.web.wsgi
implements a WSGI compatibility class that lets you run
WSGI applications using the Pants HTTPServer
.
Currently, this module uses the PEP 333 standard. Future releases will add
support for PEP 3333, as well as the ability to host a Pants
Application
from a standard WSGI server.
WSGIConnector
¶
-
class
pants.web.wsgi.
WSGIConnector
(application, debug=False)[source]¶ This class functions as a request handler for the Pants
HTTPServer
that wraps WSGI applications to allow them to work correctly.Class instances are callable, and when called with a
HTTPRequest
instance, they construct a WSGI environment and invoke the application.from pants import Engine from pants.http import HTTPServer from pants.web import WSGIConnector def hello_app(environ, start_response): start_response("200 OK", {"Content-Type": "text/plain"}) return ["Hello, World!"] connector = WSGIConnector(hello_app) HTTPServer(connector).listen() Engine.instance().start()
WSGIConnector
supports sending responses withTransfer-Encoding: chunked
and will do so automatically when the WSGI application’s response does not contain information about the response’s length.Argument Description application The WSGI application that will handle incoming requests. debug Optional. Whether or not to display tracebacks and additional debugging information for a request within 500 Internal Server Error
pages.-
attach
(application, rule, methods=('HEAD', 'GET', 'POST', 'PUT'))[source]¶ Attach the WSGIConnector to an instance of
Application
at the given route.You may use route variables to strip information out of a URL. In the event that variables exist, they will be made available within the WSGI environment under the key wsgiorg.routing_args
Warning
When using WSGIConnector within an Application, WSGIConnector expects the final variable in the rule to capture the remainder of the URL, and it treats the last variable as containing the value for the
PATH_INFO
variable in the WSGI environment. This method adds such a variable automatically. However, if you add the WSGIConnector manually you will have to be prepared.Argument Description application The Application
to attach to.rule The path to serve requests from. methods Optional. The HTTP methods to accept.
-