Package wsgiwapi :: Module application
[frames] | no frames]

Module application

source code

Create a WSGI application providing a web API.
Classes
  JsonResponse
A class used to return a JSON response with a specific status code.
  ValidationError
Exception used to indicate that parameters failed validation.
  Resource
A resource, used to support a set of different methods at a given URI.
  MethodSwitch
A resource, used to support a set of different methods at a given URI.
Functions
 
apply_request_checks_and_transforms(request, props)
Apply all the checks and transforms listed in props to a request.
source code
 
apply_response_checks_and_transforms(request, response, props)
Apply all the checks and transforms listed in props to a response.
source code
 
handle_validation_error(err)
Default handler for validation errors.
source code
 
unflatten_urls(flat_urls)
Unflatten a sequence or dict of url components.
source code
 
make_application(urls, autodoc=None, validation_error_handler=handle_validation_error, logger=None)
Make a web application for a given set of URLs.
source code
 
make_server(app, bind_addr, *args, **kwargs)
Make a server for an application.
source code
Function Details

apply_request_checks_and_transforms(request, props)

source code 

Apply all the checks and transforms listed in props to a request.

This is typically called from a decorator, and the props are read from the decorated function.

apply_response_checks_and_transforms(request, response, props)

source code 

Apply all the checks and transforms listed in props to a response.

This is typically called from a decorator, and the props are read from the decorated function.

handle_validation_error(err)

source code 

Default handler for validation errors.

Returns a Response with status code 400.

make_application(urls, autodoc=None, validation_error_handler=handle_validation_error, logger=None)

source code 

Make a web application for a given set of URLs.

  • urls is a dict of urls to support: keys are url components, values are either sub dictionaries, or callables.
  • logger is a callable which returns a Logger. When the application object returned is instantiated, it will call this callable, and use the returned object for logging.

FIXME - document the other parameters to this function.

make_server(app, bind_addr, *args, **kwargs)

source code 

Make a server for an application.

This uses CherryPy's standalone WSGI server. The first argument is the WSGI application to run; all subsequent arguments are passed directly to the server. The CherryPyWSGIServer is accessible as wsgiwapi.cpwsgiserver: see the documentation in that module for calling details.

Note that you will always need to set the bind_addr parameter; this is a (host, port) tuple for TCP sockets, or a filename for UNIX sockets. The host part may be set to '0.0.0.0' to listen on all active IPv4 interfaces (or similarly, '::' to listen on all active IPv6 interfaces).