Utility methods for working with WSGI servers
tacker.wsgi.
ActionDispatcher
¶Bases: object
Maps method name to local methods through action name.
default
(data)¶dispatch
(*args, **kwargs)¶Find and call local method.
tacker.wsgi.
Application
¶Bases: object
Base WSGI application wrapper. Subclasses need to implement __call__.
factory
(global_config, **local_config)¶Used for paste app factories in paste.deploy config files.
Any local configuration (that is, values under the [app:APPNAME] section of the paste config) will be passed into the __init__ method as kwargs.
A hypothetical configuration would look like:
[app:wadl] latest_version = 1.3 paste.app_factory = nova.api.fancy_api:Wadl.factory
which would result in a call to the Wadl class as
import tacker.api.fancy_api fancy_api.Wadl(latest_version=‘1.3’)
You could of course re-implement the factory method in subclasses, but using the kwarg passing it shouldn’t be necessary.
tacker.wsgi.
Controller
¶Bases: object
WSGI app that dispatched to methods.
WSGI app that reads routing information supplied by RoutesMiddleware and calls the requested action method upon itself. All action methods must, in addition to their normal parameters, accept a ‘req’ argument which is the incoming wsgi.Request. They raise a webob.exc exception, or return a dict which will be serialized by requested content type.
tacker.wsgi.
Debug
(application)¶Bases: tacker.wsgi.Middleware
Middleware for debugging.
Helper class that can be inserted into any WSGI application chain to get information about the request and response.
print_generator
(app_iter)¶Print contents of a wrapper string iterator when iterated.
tacker.wsgi.
DefaultMethodController
¶Bases: object
Controller that handles the OPTIONS request method.
This controller handles the OPTIONS request method and any of the HTTP methods that are not explicitly implemented by the application.
options
(request, **kwargs)¶Return a response that includes the ‘Allow’ header.
Return a response that includes the ‘Allow’ header listing the methods that are implemented. A 204 status code is used for this response.
reject
(request, **kwargs)¶Return a 405 method not allowed error.
As a convenience, the ‘Allow’ header with the list of implemented methods is included in the response as well.
tacker.wsgi.
DictSerializer
¶Bases: tacker.wsgi.ActionDispatcher
Default request body serialization.
default
(data)¶serialize
(data, action='default')¶tacker.wsgi.
Fault
(exception)¶Bases: webob.exc.HTTPException
Wrap webob.exc.HTTPException to provide API friendly response.
tacker.wsgi.
JSONDeserializer
¶Bases: tacker.wsgi.TextDeserializer
default
(datastring)¶tacker.wsgi.
JSONDictSerializer
¶Bases: tacker.wsgi.DictSerializer
Default JSON request body serialization.
default
(data)¶tacker.wsgi.
Middleware
(application)¶Bases: object
Base WSGI middleware wrapper.
These classes require an application to be initialized that will be called next. By default the middleware will simply call its wrapped app, or you can override __call__ to customize its behavior.
factory
(global_config, **local_config)¶Used for paste app factories in paste.deploy config files.
Any local configuration (that is, values under the [filter:APPNAME] section of the paste config) will be passed into the __init__ method as kwargs.
A hypothetical configuration would look like:
[filter:analytics] redis_host = 127.0.0.1 paste.filter_factory = nova.api.analytics:Analytics.factory
which would result in a call to the Analytics class as
import nova.api.analytics analytics.Analytics(app_from_paste, redis_host=‘127.0.0.1’)
You could of course re-implement the factory method in subclasses, but using the kwarg passing it shouldn’t be necessary.
process_request
(req)¶Called on each request.
If this returns None, the next application down the stack will be executed. If it returns a response then that response will be returned and execution will stop here.
process_response
(response)¶Do whatever you’d like to the response.
tacker.wsgi.
Request
(environ, charset=None, unicode_errors=None, decode_param_names=None, **kw)¶Bases: webob.request.Request
best_match_content_type
()¶Determine the most acceptable content-type.
best_match_language
()¶Determines best available locale from the Accept-Language header.
Returns: | the best language match or None if the ‘Accept-Language’ header was not available in the request. |
---|
context
¶get_content_type
()¶tacker.wsgi.
RequestDeserializer
(body_deserializers=None, headers_deserializer=None)¶Bases: object
Break up a Request object into more useful pieces.
deserialize
(request)¶Extract necessary pieces of the request.
Parameters: | request – Request object |
---|---|
Returns: | tuple of expected controller action name, dictionary of keyword arguments to pass to the controller, the expected content type of the response |
deserialize_body
(request, action)¶deserialize_headers
(request, action)¶get_action_args
(request_environment)¶Parse dictionary created by routes library.
get_body_deserializer
(content_type)¶get_expected_content_type
(request)¶tacker.wsgi.
RequestHeadersDeserializer
¶Bases: tacker.wsgi.ActionDispatcher
Default request headers deserializer.
default
(request)¶deserialize
(request, action)¶tacker.wsgi.
Resource
(controller, deserializer=None, serializer=None)¶Bases: tacker.wsgi.Application
WSGI app that handles (de)serialization and controller dispatch.
WSGI app that reads routing information supplied by RoutesMiddleware and calls the requested action method upon its controller. All controller action methods must accept a ‘req’ argument, which is the incoming wsgi.Request. If the operation is a PUT or POST, the controller method must also accept a ‘body’ argument (the deserialized request body). They may raise a webob.exc exception or return a dict, which will be serialized by requested content type.
dispatch
(request, action, action_args)¶Find action-spefic method on controller and call it.
tacker.wsgi.
ResourceExceptionHandler
¶Bases: object
Context manager to handle Resource exceptions.
Used when processing exceptions generated by API implementation methods. Converts most exceptions to Fault exceptions, with the appropriate logging.
tacker.wsgi.
ResponseHeaderSerializer
¶Bases: tacker.wsgi.ActionDispatcher
Default response headers serialization.
default
(response, data)¶serialize
(response, data, action)¶tacker.wsgi.
ResponseObject
(obj, code=None, headers=None)¶Bases: object
Bundles a response object
Object that app methods may return in order to allow its response to be modified by extensions in the code. Its use is optional (and should only be used if you really know what you are doing).
code
¶Retrieve the response status.
headers
¶Retrieve the headers.
serialize
(request, content_type)¶Serializes the wrapped object.
Utility method for serializing the wrapped object. Returns a webob.Response object.
Header values are set to the appropriate Python type and encoding demanded by PEP 3333: whatever the native str type is.
tacker.wsgi.
ResponseSerializer
(body_serializers=None, headers_serializer=None)¶Bases: object
Encode the necessary pieces into a response object.
get_body_serializer
(content_type)¶serialize
(response_data, content_type, action='default')¶Serialize a dict into a string and wrap in a wsgi.Request object.
Parameters: |
|
---|
serialize_body
(response, data, content_type, action)¶serialize_headers
(response, data, action)¶tacker.wsgi.
Router
(mapper)¶Bases: object
WSGI middleware that maps incoming requests to WSGI apps.
factory
(global_config, **local_config)¶Return an instance of the WSGI Router class.
tacker.wsgi.
Serializer
(metadata=None)¶Bases: object
Serializes and deserializes dictionaries to certain MIME types.
deserialize
(datastring, content_type)¶Deserialize a string to a dictionary.
The string must be in the format of a supported MIME type.
get_deserialize_handler
(content_type)¶serialize
(data, content_type)¶Serialize a dictionary into the specified content type.
tacker.wsgi.
Server
(name, threads=1000)¶Bases: object
Server class to manage multiple WSGI sockets and applications.
host
¶port
¶start
(application, port, host='0.0.0.0', workers=0)¶Run a WSGI server with the given application.
stop
()¶wait
()¶Wait until all servers have completed running.
tacker.wsgi.
TextDeserializer
¶Bases: tacker.wsgi.ActionDispatcher
Default request body deserialization.
default
(datastring)¶deserialize
(datastring, action='default')¶tacker.wsgi.
WorkerService
(service, application)¶Bases: oslo_service.service.ServiceBase
Wraps a worker to be handled by ProcessLauncher.
reset
()¶Reset service.
Called in case service running in daemon mode receives SIGHUP.
start
()¶Start service.
stop
()¶Stop service.
wait
()¶Wait for service to complete.
tacker.wsgi.
ZipDeserializer
¶Bases: tacker.wsgi.ActionDispatcher
default
(body_file)¶deserialize
(body_file, action='default')¶tacker.wsgi.
config_opts
()¶tacker.wsgi.
encode_body
(body)¶Encode unicode body.
WebOb requires to encode unicode body used to update response body.
tacker.wsgi.
expected_errors
(errors)¶Decorator for Restful API methods which specifies expected exceptions.
Specify which exceptions may occur when an API method is called. If an unexpected exception occurs then return a 500 instead and ask the user of the API to file a bug report.
tacker.wsgi.
response
(code)¶Attaches response code to a method.
This decorator associates a response code with a method. Note that the function attributes are directly manipulated; the method is not wrapped.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.