Package brisa :: Package core :: Module webserver
[hide private]
[frames] | no frames]

Module webserver

source code

WSGI-based webserver module. Includes a few built-in adapters for working with different WSGI servers.

If possible, an adapter will be automatically assigned to a WebServer instance - if not passed by the user.

For retrieving the available adapters, use get_available_adapters(). The results can be passed to the WebServer, e.g. WebServer(adapter=some_adapter) where some_adapter was retrieved with get_available_adapters().

Classes [hide private]
  Request
Request wrapper class.
  Response
Response wrapper class.
  StaticFile
Object that matches with a file and makes it available on the server.
  Resource
Represents a resource or a folder on the webserver.
  CustomResource
Same as Resource.
  AdapterInterface
Common interface for WSGI-servers adapters.
  CherrypyAdapter
Cherrypy WSGI server adapter.
  PasteAdapter
Paste WSGI server adapter.
  CircuitsWebAdapter
circuits.web WSGI server adapter.
  WebServer
Webserver class.
Functions [hide private]
string
simple_response(code, start_response, extra_msg=None)
Performs a simple response for a request.
source code
string
response(code, start_response, msg)
Performs a response for a request without wrapping in a html template.
source code
 
get_byte_ranges(r, clen)
Based on a Range header and on the content length of a file, returns a list of byte ranges requested.
source code
 
chunk_generator(f, chunk_size, max_chunked)
Generates chunks of a file.
source code
 
setup_single_part_response(r, rng, clen)
Setups a response object for a single part response.
source code
 
setup_multi_part_response(r, rngs, clen, content_type)
Setups a response object for a multi part response, based on the byte ranges requested.
source code
 
client_host(server_host)
Return the host on which a client can connect to the given listener.
source code
 
check_port(host, port, timeout=1.0)
Raises an error if the given port is not free on the given host.
source code
 
get_preferred_adapter()
Returns the preferred adapter, located at brisa.webserver_adapter config entry.
source code
 
get_available_adapters()
Returns a list of the available adapters.
source code
Variables [hide private]
  log = log.getLogger('core.webserver')
  invalid_path_exists = 'path does not exist'
  invalid_path_abs = 'path must be absolute'
  invalid_path_dir = 'path must be a file'
  http_codes = {100: 'Continue', 101: 'Switching Protocols', 200...
  chunks_size = 2** 16
  simple_template = '<html><head><title>%s</title><body>%s</body...
  adapters = {'cherrypy': CherrypyAdapter, 'paste': PasteAdapter...
Function Details [hide private]

simple_response(code, start_response, extra_msg=None)

source code 

Performs a simple response for a request. Usually used for returning errors or empty pages. For example, start_response(404, start_response, 'File not available on the server') will return a page to the user with the 404 status and this message on the body, wrapped in a simple html template.

Parameters:
  • code (integer) - status code present on http_codes dict
  • start_response (callable) - start_response wsgi function
  • extra_msg (string) - message that goes on the body. If not supplied, the status message will take its place on the body.
Returns: string
final message to return as response body

Note: this function also sends the headers

response(code, start_response, msg)

source code 

Performs a response for a request without wrapping in a html template.

Parameters:
  • code (integer) - status code present on http_codes dict
  • start_response (callable) - start_response wsgi function
  • msg (string) - message that goes on the body. If not supplied, the status message will take its place on the body.
Returns: string
final message to return as response body

Note: this function also sends the headers

get_byte_ranges(r, clen)

source code 

Based on a Range header and on the content length of a file, returns a list of byte ranges requested. Returns None if the header was invalid and an empty list in case of invalid range.

Based on Cherrypy 3.1 implementation.

Parameters:
  • r - range header
  • clen - content length

chunk_generator(f, chunk_size, max_chunked)

source code 

Generates chunks of a file. Stops when reaches the max_chunked value of generated chunks.

setup_single_part_response(r, rng, clen)

source code 

Setups a response object for a single part response. Based on Cherrypy 3.1 implementation.

Parameters:
  • r - response object
  • rng - 2-tuple of the form (start, stop) with the byte range requested
  • clen - length of the body file

setup_multi_part_response(r, rngs, clen, content_type)

source code 

Setups a response object for a multi part response, based on the byte ranges requested. Based on Cherrypy 3.1 implementation.

Parameters:
  • r - response object
  • rngs - list of ranges
  • clen - length of the body file

client_host(server_host)

source code 

Return the host on which a client can connect to the given listener.

Copyright (c) 2002-2008, CherryPy Team (team@cherrypy.org)

check_port(host, port, timeout=1.0)

source code 

Raises an error if the given port is not free on the given host.

Copyright (c) 2002-2008, CherryPy Team (team@cherrypy.org)


Variables Details [hide private]

http_codes

Value:
{100: 'Continue', 101: 'Switching Protocols', 200: 'OK', 201: 'Created\
', 202: 'Accepted', 203: 'Non-Authoritative Information', 204: 'No Con\
tent', 205: 'Reset Content', 206: 'Partial Content', 300: 'Multiple Ch\
oices', 301: 'Moved Permanently', 302: 'Found', 303: 'See Other', 304:\
 'Not Modified', 305: 'Use Proxy', 307: 'Temporary Redirect', 400: 'Ba\
d Request', 401: 'Unauthorized', 403: 'Forbidden', 404: 'Not Found', 4\
05: 'Method Not Allowed', 416: 'Requested range not satisfiable', 417:\
 'Expectation Failed', 500: 'Internal Server Error', 501: 'Not Impleme\
...

simple_template

Value:
'<html><head><title>%s</title><body>%s</body></html>'

adapters

Value:
{'cherrypy': CherrypyAdapter, 'paste': PasteAdapter, 'circuits.web': C\
ircuitsWebAdapter}