cherrypy._cpwsgi module¶
WSGI interface (see PEP 333 and 3333).
Note that WSGI environ keys and values are ‘native strings’; that is, whatever the type of “” is. For Python 2, that’s a byte string; for Python 3, it’s a unicode string. But PEP 3333 says: “even if Python’s str type is actually Unicode “under the hood”, the content of native strings must still be translatable to bytes via the Latin-1 encoding!”
- class cherrypy._cpwsgi.AppResponse(environ, start_response, cpapp)[source]¶
Bases:
object
WSGI response iterable for CherryPy applications.
- headerNames = {'CONTENT_LENGTH': 'Content-Length', 'CONTENT_TYPE': 'Content-Type', 'HTTP_CGI_AUTHORIZATION': 'Authorization', 'REMOTE_ADDR': 'Remote-Addr', 'REMOTE_HOST': 'Remote-Host'}¶
- class cherrypy._cpwsgi.CPWSGIApp(cpapp, pipeline=None)[source]¶
Bases:
object
A WSGI application object for a CherryPy Application.
- config = {}¶
A dict whose keys match names listed in the pipeline.
Each value is a further dict which will be passed to the corresponding named WSGI callable (from the pipeline) as keyword arguments.
- head = None¶
Rather than nest all apps in the pipeline on each call, it’s only done the first time, and the result is memoized into self.head. Set this to None again if you change self.pipeline after calling self.
- pipeline = [('ExceptionTrapper', <class 'cherrypy._cpwsgi.ExceptionTrapper'>), ('InternalRedirector', <class 'cherrypy._cpwsgi.InternalRedirector'>)]¶
A list of (name, wsgiapp) pairs.
Each ‘wsgiapp’ MUST be a constructor that takes an initial, positional ‘nextapp’ argument, plus optional keyword arguments, and returns a WSGI application (that takes environ and start_response arguments). The ‘name’ can be any you choose, and will correspond to keys in self.config.
- response_class¶
The class to instantiate and return as the next app in the WSGI chain.
alias of
AppResponse
- class cherrypy._cpwsgi.ExceptionTrapper(nextapp, throws=(<class 'KeyboardInterrupt'>, <class 'SystemExit'>))[source]¶
Bases:
object
WSGI middleware that traps exceptions.
- class cherrypy._cpwsgi.InternalRedirector(nextapp, recursive=False)[source]¶
Bases:
object
WSGI middleware that handles raised cherrypy.InternalRedirect.
- class cherrypy._cpwsgi.VirtualHost(default, domains=None, use_x_forwarded_host=True)[source]¶
Bases:
object
Select a different WSGI application based on the Host header.
This can be useful when running multiple sites within one CP server. It allows several domains to point to different applications. For example:
root = Root() RootApp = cherrypy.Application(root) Domain2App = cherrypy.Application(root) SecureApp = cherrypy.Application(Secure()) vhost = cherrypy._cpwsgi.VirtualHost( RootApp, domains={ 'www.domain2.example': Domain2App, 'www.domain2.example:443': SecureApp, }, ) cherrypy.tree.graft(vhost)
- default = None¶
The default WSGI application.
Required.
- domains = {}¶
application} pairs. The incoming “Host” request header is looked up in this dict, and, if a match is found, the corresponding WSGI application will be called instead of the default. Note that you often need separate entries for “example.com” and “www.example.com”. In addition, “Host” headers may contain the port number.
- Type:
A dict of {host header value
- use_x_forwarded_host = True¶
If True (the default), any “X-Forwarded-Host” request header will be used instead of the “Host” header. This is commonly added by HTTP servers (such as Apache) when proxying.