application module.
The application object is simply a WSGI callable object.
middleware is any callable of the following contract:
def middleware(request, following):
if following:
response = following(request)
else:
response
return response
middleware_factory is a factory that initialize middleware:
def middleware_factory(options):
return middleware
middleware_factory can return None, this can be useful for some sort of initialization that needs to be run during application bootstrap.
Checks if user is accessing protected resource via SSL and if not, issue permanent redirect to HTTPS location.
enabled - whenever to do any checks (defaults to True).
Example:
@secure
def my_view(request):
...
return response
Using enabled:
@secure(enabled=False)
def my_view(request):
...
return response
cache module
WSGI wrapper that returns response headers and buffer.
Build etag function based on hasher algorithm and crc32.
cachepolicy module.
Controls cache specific http headers.
Provides the current value of the entity tag for the requested variant.
Not valid for no-cache cacheability, raise AssertionError.
The Expires entity-header field gives the date/time after which the response is considered stale.
Not valid for no-cache cacheability, raise AssertionError.
The Last-Modified entity-header field indicates the date and time at which the origin server believes the variant was last modified.
Not valid for no-cache cacheability, raise AssertionError.
Accept a response whose age is no greater than the specified time in seconds.
delta can be int or datetime.timedelta.
Not valid for no-cache cacheability, raise AssertionError.
Because a cache MAY be configured to ignore a server’s specified expiration time, and because a client request MAY include a max-stale directive (which has a similar effect), the protocol also includes a mechanism for the origin server to require revalidation of a cache entry on any subsequent use.
Raises AssertionError if proxy-revalidave is set.
The specified field-name(s) MUST NOT be sent in the response to a subsequent request without successful revalidation with the origin server.
Not valid for no-cache cacheability.
The purpose of the no-store directive is to prevent the inadvertent release or retention of sensitive information.
The cache or proxy MUST NOT change any aspect of the entity-body that is specified by this header, including the value of the entity-body itself.
Indicates that part of the response message is intended for a single user and MUST NOT be cached by a shared cache.
Only valid for public cacheability.
The proxy-revalidate directive has the same meaning as the must- revalidate directive, except that it does not apply to non-shared user agent caches.
Raises AssertionError if must-revalidave is set.
If a response includes an s-maxage directive, then for a shared cache (but not for a private cache), the maximum age specified by this directive overrides the maximum age specified by either the max-age directive or the Expires header. Accept a response whose age is no greater than the specified time in seconds.
delta can be int or datetime.timedelta.
Not valid for no-cache cacheability, raise AssertionError.
The Vary field value indicates the set of request-header fields that fully determines, while the response is fresh, whether a cache is permitted to use the response to reply to a subsequent request without revalidation.
Not valid for no-cache cacheability, raise AssertionError.
cacheprofile module.
Combines a number of setting applicable to http cache policy as well as server side cache.
Designed to compose a key depending on number of values, including: query, form, environ.
Key by cookies.
timestamp -> UTC datetime from a POSIX timestamp (like time.time()).
config module.
def bootstrap_http_defaults(options):
""" Bootstraps http default options.
"""
options.setdefault('ENCODING', 'UTF-8')
options.setdefault('MAX_CONTENT_LENGTH', 4 * 1024 * 1024)
options.setdefault('HTTP_COOKIE_DOMAIN', None)
options.setdefault('HTTP_COOKIE_SECURE', False)
options.setdefault('HTTP_COOKIE_HTTPONLY', False)
return None
cookie module.
HTTP Cookie http://www.ietf.org/rfc/rfc2109.txt
domain, secure and httponly are taken from config if not set.
Returns a cookie to be deleted by browser.
Returns Set-Cookie response header.
functional module.
Form class represent HTML form. It stores form tag attributes, params that can be used in form submission as well as related HTML elements.
FormTarget finds forms and elements like input, select, etc.
Page form submit use case.
WSGI client simulates WSGI requests in order to accomplish functional testing for any WSGI application.
Submits given form. Takes action and method form attributes into account.
Builds WSGI environment.
The content_type takes priority over params to use stream or content.
method module.
Decorator that accepts only particular HTTP request method if constraint is a string:
@accept_method('GET')
def my_view(request):
response = ...
return response
or HTTP request methods if constraint is a list or tuple:
@accept_method(('GET', 'POST'))
def my_view(request):
response = ...
return response
method constraint must be in uppercase.
middleware module.
WSGI environ cache adapter middleware.
HTTP cache middleware.
WSGI environ cache adapter middleware factory.
parser module.
Parse cookie string and return a dictionary where key is a name of the cookie and value is cookie value.
request module.
response module.
HTTP response.
Response headers Content-Length and Cache-Control must not be set by user code directly. Use HTTPCachePolicy instead (HTTPResponse.cache).
Redirect response to absolute_url and sets status_code.
Returns a string that describes the specified HTTP status code.
Shortcut function to return ajax redirect response.
Browsers incorrectly handle redirect response to ajax request, so we return status code 207 that javascript is capable to receive and process browser redirect.
Here is an example for jQuery:
$.ajax({
// ...
success: function(data, textStatus, jqXHR) {
if (jqXHR.status == 207) {
window.location.replace(
jqXHR.getResponseHeader('Location'));
} else {
// ...
}
}
});
Shortcut function to return redirect response.
The HTTP response status code 302 Found is a common way of performing a redirection.
Shortcut function to return a response with given status code.
Shortcut function to return permanent redirect response.
The HTTP response status code 301 Moved Permanently is used for permanent redirection.
Shortcut function to return redirect response.
The HTTP response status code 302 Found is a common way of performing a redirection.
Shortcut function to return see other redirect response.
The HTTP response status code 303 See Other is the correct manner in which to redirect web applications to a new URI, particularly after an HTTP POST has been performed.
This response indicates that the correct response can be found under a different URI and should be retrieved using a GET method. The specified URI is not a substitute reference for the original resource.
Shortcut function to return temporary redirect response.
In this occasion, the request should be repeated with another URI, but future requests can still use the original URI. In contrast to 303, the request method should not be changed when reissuing the original request. For instance, a POST request must be repeated using another POST request.
transforms module
Allows gzip compression.
compress_level - the compression level, between 1 and 9, where 1 is the least compression (fastest) and 9 is the most (slowest)
min_length - sets the minimum length, in bytes, of the first chunk in response that will be compressed. Responses shorter than this byte-length will not be compressed.
vary - enables response header “Vary: Accept-Encoding”.