This module provides helper routines with work directly on a WSGI environment to solve common requirements.
get_cookies(environ)
parse_querystring(environ)
parse_formvars(environ, include_get_vars=True)
- construct_url(environ, with_query_string=True, with_path_info=True,
script_name=None, path_info=None, querystring=None)
path_info_split(path_info)
path_info_pop(environ)
resolve_relative_url(url, environ)
Return a plain dictionary of cookies as found in the request.
Unlike get_cookies this returns a dictionary, not a SimpleCookie object. For incoming cookies a dictionary fully represents the information. Like get_cookies this caches and checks the cache.
Parses a query string into a list like [(name, value)]. Caches this value in case parse_querystring is called again for the same request.
You can pass the result to dict(), but be aware that keys that appear multiple times will be lost (only the last value will be preserved).
Parses the request, returning a MultiDict of form variables.
If include_get_vars is true then GET (query string) variables will also be folded into the MultiDict.
All values should be strings, except for file uploads which are left as FieldStorage instances.
If the request was not a normal form request (e.g., a POST with an XML body) then environ['wsgi.input'] won’t be read.
Reconstructs the URL from the WSGI environment.
You may override SCRIPT_NAME, PATH_INFO, and QUERYSTRING with the keyword arguments.
‘Pops’ off the next segment of PATH_INFO, pushing it onto SCRIPT_NAME, and returning that segment.
For instance:
>>> def call_it(script_name, path_info):
... env = {'SCRIPT_NAME': script_name, 'PATH_INFO': path_info}
... result = path_info_pop(env)
... print 'SCRIPT_NAME=%r; PATH_INFO=%r; returns=%r' % (
... env['SCRIPT_NAME'], env['PATH_INFO'], result)
>>> call_it('/foo', '/bar')
SCRIPT_NAME='/foo/bar'; PATH_INFO=''; returns='bar'
>>> call_it('/foo/bar', '')
SCRIPT_NAME='/foo/bar'; PATH_INFO=''; returns=None
>>> call_it('/foo/bar', '/')
SCRIPT_NAME='/foo/bar/'; PATH_INFO=''; returns=''
>>> call_it('', '/1/2/3')
SCRIPT_NAME='/1'; PATH_INFO='/2/3'; returns='1'
>>> call_it('', '//1/2')
SCRIPT_NAME='//1'; PATH_INFO='/2'; returns='1'
An object that represents the headers as present in a WSGI environment.
This object is a wrapper (with no internal state) for a WSGI request object, representing the CGI-style HTTP_* keys as a dictionary. Because a CGI environment can only hold one value for each key, this dictionary is single-valued (unlike outgoing headers).