Package gluon :: Module wsgiserver
[hide private]
[frames] | no frames]

Module wsgiserver

source code

high-speed, production ready, thread pooled, generic WSGI server.

Simplest example on how to use this module directly
(without using CherryPy's application machinery):

    from cherrypy import wsgiserver
    
    def my_crazy_app(environ, start_response):
        status = '200 OK'
        response_headers = [('Content-type','text/plain')]
        start_response(status, response_headers)
        return ['Hello world!
']
    
    server = wsgiserver.CherryPyWSGIServer(
                ('0.0.0.0', 8070), my_crazy_app,
                server_name='www.cherrypy.example')
    
The CherryPy WSGI server can serve as many WSGI applications 
as you want in one instance by using a WSGIPathInfoDispatcher:
    
    d = WSGIPathInfoDispatcher({'/': my_crazy_app, '/blog': my_blog_app})
    server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 80), d)
    
Want SSL support? Just set these attributes:
    
    server.ssl_certificate = <filename>
    server.ssl_private_key = <filename>
    
    if __name__ == '__main__':
        try:
            server.start()
        except KeyboardInterrupt:
            server.stop()

This won't call the CherryPy engine (application side) at all, only the
WSGI server, which is independant from the rest of CherryPy. Don't
let the name "CherryPyWSGIServer" throw you; the name merely reflects
its origin, not its coupling.

Classes [hide private]
  WSGIPathInfoDispatcher
A WSGI dispatcher for dispatch based on the PATH_INFO.
  MaxSizeExceeded
  SizeCheckWrapper
Wraps a file-like object, raising MaxSizeExceeded if too large.
  HTTPRequest
An HTTP Request (and response).
  NoSSLError
Exception raised when a client speaks HTTP to an HTTPS socket.
  SSL_fileobject
Faux file object attached to a socket object.
  HTTPConnection
An HTTP connection (active socket).
  WorkerThread
Thread which continuously polls a Queue for Connection objects.
  ThreadPool
A Request Queue for the CherryPyWSGIServer which pools threads.
  SSLConnection
A thread-safe wrapper for an SSL.Connection.
  CherryPyWSGIServer
An HTTP server for WSGI.
Functions [hide private]
 
plat_specific_errors(*errnames)
Return error numbers for all errors in errnames on this platform.
source code
 
_ssl_wrap_method(method, is_reader=False)
Wrap the given method with SSL error-trapping.
source code
 
format_exc(limit=None)
Like print_exc() but return a string.
source code
Variables [hide private]
  quoted_slash = re.compile(r'(?i)%2F')
  socket_errors_to_ignore = [32, 64, 65, 54, 60, 61, 'timed out']
  socket_errors_nonblocking = [35]
  comma_separated_headers = ['ACCEPT', 'ACCEPT-CHARSET', 'ACCEPT...
  _SHUTDOWNREQUEST = None
Function Details [hide private]

plat_specific_errors(*errnames)

source code 

Return error numbers for all errors in errnames on this platform.

The 'errno' module contains different global constants depending on the specific platform (OS). This function will return the list of numeric values for a given list of potential names.

_ssl_wrap_method(method, is_reader=False)

source code 
Wrap the given method with SSL error-trapping.

is_reader: if False (the default), EOF errors will be raised.
    If True, EOF errors will return "" (to emulate normal sockets).

format_exc(limit=None)

source code 

Like print_exc() but return a string. Backport for Python 2.3.


Variables Details [hide private]

comma_separated_headers

Value:
['ACCEPT',
 'ACCEPT-CHARSET',
 'ACCEPT-ENCODING',
 'ACCEPT-LANGUAGE',
 'ACCEPT-RANGES',
 'ALLOW',
 'CACHE-CONTROL',
 'CONNECTION',
...