paste.wsgiwrappers – Wrapper functions for WSGI request and response¶
WSGI Wrappers for a Request and Response
The WSGIRequest and WSGIResponse objects are light wrappers to make it easier to deal with an incoming request and sending a response.
Module Contents¶
- class paste.wsgiwrappers.WSGIRequest(environ)¶
WSGI Request API Object
This object represents a WSGI request with a more friendly interface. This does not expose every detail of the WSGI environment, and attempts to express nothing beyond what is available in the environment dictionary.
The only state maintained in this object is the desired
charset, its associatederrorshandler, and thedecode_param_namesoption.The incoming parameter values will be automatically coerced to unicode objects of the
charsetencoding whencharsetis set. The incoming parameter names are not decoded to unicode unless thedecode_param_namesoption is enabled.When unicode is expected,
charsetwill overridden by the the value of theContent-Typeheader’s charset parameter if one was specified by the client.The class variable
defaultsspecifies default values forcharset,errors, andlangauge. These can be overridden for the current request via the registry.The
languagedefault value is considered the fallback during i18n translations to ensure in odd cases that mixed languages don’t occur should thelanguagefile contain the string but not another language in the accepted languages list. Thelanguagevalue only applies when getting a list of accepted languages from the HTTP Accept header.This behavior is duplicated from Aquarium, and may seem strange but is very useful. Normally, everything in the code is in “en-us”. However, the “en-us” translation catalog is usually empty. If the user requests
["en-us", "zh-cn"]and a translation isn’t found for a string in “en-us”, you don’t want gettext to fallback to “zh-cn”. You want it to just use the string itself. Hence, if a string isn’t found in thelanguagecatalog, the string in the source code will be used.All other state is kept in the environment dictionary; this is essential for interoperability.
You are free to subclass this object.
- class paste.wsgiwrappers.WSGIResponse(content=b'', mimetype=None, code=200)¶
A basic HTTP response with content, headers, and out-bound cookies
The class variable
defaultsspecifies default values forcontent_type,charsetanderrors. These can be overridden for the current request via the registry.