Package wsgiref :: Module util
[hide private]
[frames] | no frames]

Module util

Miscellaneous WSGI-related Utilities

Classes [hide private]
FileWrapper
Wrapper to convert file-like objects to iterables
Functions [hide private]
 
guess_scheme(environ)
Return a guess for whether 'wsgi.url_scheme' should be 'http' or 'https'
 
application_uri(environ)
Return the application's base URI (no PATH_INFO or QUERY_STRING)
 
request_uri(environ, include_query=1)
Return the full request URI, optionally including the query string
 
shift_path_info(environ)
Shift a name from PATH_INFO to SCRIPT_NAME, returning it
 
setup_testing_defaults(environ)
Update 'environ' with trivial defaults for testing purposes
True if D has a key k, else False
_hoppish(D, k)
 
is_hop_by_hop(header_name)
Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header

Imports: posixpath


Function Details [hide private]

shift_path_info(environ)

 

Shift a name from PATH_INFO to SCRIPT_NAME, returning it

If there are no remaining path segments in PATH_INFO, return None. Note: 'environ' is modified in-place; use a copy if you need to keep the original PATH_INFO or SCRIPT_NAME.

Note: when PATH_INFO is just a '/', this returns '' and appends a trailing '/' to SCRIPT_NAME, even though empty path segments are normally ignored, and SCRIPT_NAME doesn't normally end in a '/'. This is intentional behavior, to ensure that an application can tell the difference between '/x' and '/x/' when traversing to objects.

setup_testing_defaults(environ)

 

Update 'environ' with trivial defaults for testing purposes

This adds various parameters required for WSGI, including HTTP_HOST, SERVER_NAME, SERVER_PORT, REQUEST_METHOD, SCRIPT_NAME, PATH_INFO, and all of the wsgi.* variables. It only supplies default values, and does not replace any existing settings for these variables.

This routine is intended to make it easier for unit tests of WSGI servers and applications to set up dummy environments. It should *not* be used by actual WSGI servers or applications, since the data is fake!