cheroot.wsgi
module¶
This class holds Cheroot WSGI server implementation.
Simplest example on how to use this server:
from cheroot import wsgi
def my_crazy_app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
return [b'Hello world!']
addr = '0.0.0.0', 8070
server = wsgi.Server(addr, my_crazy_app)
server.start()
The Cheroot WSGI server can serve as many WSGI applications as you want in one instance by using a PathInfoDispatcher:
path_map = {
'/': my_crazy_app,
'/blog': my_blog_app,
}
d = wsgi.PathInfoDispatcher(path_map)
server = wsgi.Server(addr, d)
-
class
cheroot.wsgi.
Gateway
(req)¶ Bases:
cheroot.server.Gateway
A base class to interface HTTPServer with WSGI.
-
classmethod
gateway_map
()¶ Create a mapping of gateways and their versions.
- Returns:
- dict[tuple[int,int],class]: map of gateway version and
corresponding class
-
get_environ
()¶ Return a new environ dict targeting the given wsgi.version.
-
respond
()¶ Process the current request.
From PEP 333:
The start_response callable must not actually transmit the response headers. Instead, it must store them for the server or gateway to transmit only after the first iteration of the application return value that yields a NON-EMPTY string, or upon the application’s first invocation of the write() callable.
-
start_response
(status, headers, exc_info=None)¶ WSGI callable to begin the HTTP response.
-
write
(chunk)¶ WSGI callable to write unbuffered data to the client.
This method is also used internally by start_response (to write data from the iterable returned by the WSGI application).
-
classmethod
-
class
cheroot.wsgi.
Gateway_10
(req)¶ Bases:
cheroot.wsgi.Gateway
A Gateway class to interface HTTPServer with WSGI 1.0.x.
-
get_environ
()¶ Return a new environ dict targeting the given wsgi.version.
-
version
= (1, 0)¶
-
-
class
cheroot.wsgi.
Gateway_u0
(req)¶ Bases:
cheroot.wsgi.Gateway_10
A Gateway class to interface HTTPServer with WSGI u.0.
WSGI u.0 is an experimental protocol, which uses Unicode for keys and values in both Python 2 and Python 3.
-
get_environ
()¶ Return a new environ dict targeting the given wsgi.version.
-
version
= ('u', 0)¶
-
-
class
cheroot.wsgi.
PathInfoDispatcher
(apps)¶ Bases:
object
A WSGI dispatcher for dispatch based on the PATH_INFO.
-
class
cheroot.wsgi.
Server
(bind_addr, wsgi_app, numthreads=10, server_name=None, max=- 1, request_queue_size=5, timeout=10, shutdown_timeout=5, accepted_queue_size=- 1, accepted_queue_timeout=10, peercreds_enabled=False, peercreds_resolve_enabled=False)¶ Bases:
cheroot.server.HTTPServer
A subclass of HTTPServer which calls a WSGI application.
-
property
numthreads
¶ Set minimum number of threads.
-
wsgi_version
= (1, 0)¶ The version of WSGI to produce.
-
property
-
cheroot.wsgi.
WSGIGateway
¶ alias of
cheroot.wsgi.Gateway
-
cheroot.wsgi.
WSGIGateway_10
¶ alias of
cheroot.wsgi.Gateway_10
-
cheroot.wsgi.
WSGIGateway_u0
¶ alias of
cheroot.wsgi.Gateway_u0
-
cheroot.wsgi.
WSGIPathInfoDispatcher
¶ alias of
cheroot.wsgi.PathInfoDispatcher
-
cheroot.wsgi.
WSGIServer
¶ alias of
cheroot.wsgi.Server