A subclass of the WebOb Request class. An instance of this class is created by the router and is provided to a view callable (and to other subsystems) as the request argument.
The documentation below (save for the add_response_callback and ‘’add_finished_callback`` methods, which are defined in this subclass itself, and the attributes context, registry, root, subpath, traversed, view_name, virtual_root , and virtual_root_path, each of which is added to the request at by the router at request ingress time) are autogenerated from the WebOb source code used when this documentation was generated.
Due to technical constraints, we can’t yet display the WebOb version number from which this documentation is autogenerated, but it will be the ‘prevailing WebOb version’ at the time of the release of this repoze.bfg version. See http://http://pythonpaste.org/webob/ for further information.
The context will be available as the context attribute of the request object. It will be the context object implied by the current request. See Traversal for information about context objects.
The application registry will be available as the registry attribute of the request object. See Using the Zope Component Architecture in repoze.bfg for more information about the application registry.
The root object will be available as the root attribute of the request object. It will be the model object at which traversal started (the root). See Traversal for information about root objects.
The traversal subpath will be available as the subpath attribute of the request object. It will be a sequence containing zero or more elements (which will be Unicode objects). See Traversal for information about the subpath.
The “traversal path” will be available as the traversed attribute of the request object. It will be a sequence representing the ordered set of names that were used to traverse to the context, not including the view name or subpath. If there is a virtual root associated with the request, the virtual root path is included within the traversal path. See Traversal for more information.
The view name will be available as the view_name attribute of the request object. It will be a single string (possibly the empty string if we’re rendering a default view). See Traversal for information about view names.
The virtual root will be available as the virtual_root attribute of the request object. It will be the virtual root object implied by the current request. See Virtual Hosting for more information about virtual roots.
The virtual root path will be available as the virtual_root_path attribute of the request object. It will be a sequence representing the ordered set of names that were used to traverse to the virtual root object. See Virtual Hosting for more information about virtual roots.
If an exception was raised by a root factory or a view callable, or at various other points where repoze.bfg executes user-defined code during the processing of a request, the exception object which was caught will be available as the exception attribute of the request within a exception view, a response callback or a finished callback. If no exception occurred, the value of request.exception will be None within response and finished callbacks.
Note
The exception attribute is new in repoze.bfg 1.3.
Like .str_GET, but may decode values and keys
Like .str_POST, but may decode values and keys
alias of Response
Gets and sets and deletes the ‘HTTP_ACCEPT’ key from the environment. For more information on Accept see section 14.1. Converts it as a MIME Accept.
Gets and sets and deletes the ‘HTTP_ACCEPT_CHARSET’ key from the environment. For more information on Accept-Charset see section 14.2. Converts it as a accept header.
Gets and sets and deletes the ‘HTTP_ACCEPT_ENCODING’ key from the environment. For more information on Accept-Encoding see section 14.3. Converts it as a accept header.
Gets and sets and deletes the ‘HTTP_ACCEPT_LANGUAGE’ key from the environment. For more information on Accept-Language see section 14.4. Converts it as a accept header.
Add a callback to the set of callbacks to be called unconditionally by the router at the very end of request processing.
callback is a callable which accepts a single positional parameter: request. For example:
1 2 3 4 5 6 7 8 9 | import transaction
def commit_callback(request):
'''commit or abort the transaction associated with request'''
if request.exception is not None:
transaction.abort()
else:
transaction.commit()
request.add_finished_callback(commit_callback)
|
Finished callbacks are called in the order they’re added ( first- to most-recently- added). Finished callbacks (unlike response callbacks) are always called, even if an exception happens in application code that prevents a response from being generated.
The set of finished callbacks associated with a request are called very late in the processing of that request; they are essentially the last thing called by the router. They are called after response processing has already occurred in a top-level finally: block within the router request processing code. As a result, mutations performed to the request provided to a finished callback will have no meaningful effect, because response processing will have already occurred, and the request’s scope will expire almost immediately after all finished callbacks have been processed.
Errors raised by finished callbacks are not handled specially. They will be propagated to the caller of the repoze.bfg router application.
See also: Using Finished Callbacks.
Add a callback to the set of callbacks to be called by the router at a point after a response object is successfully created. repoze.bfg does not have a global response object: this functionality allows an application to register an action to be performed against the response once one is created.
A ‘callback’ is a callable which accepts two positional parameters: request and response. For example:
1 2 3 4 | def cache_callback(request, response):
'Set the cache_control max_age for the response'
response.cache_control.max_age = 360
request.add_response_callback(cache_callback)
|
Response callbacks are called in the order they’re added (first-to-most-recently-added). No response callback is called if an exception happens in application code, or if the response object returned by view code is invalid.
All response callbacks are called after the repoze.bfg.interfaces.INewResponse event is sent.
Errors raised by callbacks are not handled specially. They will be propagated to the caller of the repoze.bfg router application.
See also: Using Response Callbacks.
The URL including SCRIPT_NAME (no PATH_INFO or query string)
Create a blank request environ (and Request wrapper) with the given path (path should be urlencoded), and any keys from environ.
The path will become path_info, with any query string split off and used.
All necessary keys will be added to the environ, but the values you pass in will take precedence. If you pass in base_url then wsgi.url_scheme, HTTP_HOST, and SCRIPT_NAME will be filled in from that value.
Any extra keyword will be passed to __init__ (e.g., decode_param_names).
Return the content of the request body.
Access the body of the request (wsgi.input) as a file-like object.
If you set this value, CONTENT_LENGTH will also be updated (either set to -1, 0 if you delete the attribute, or if you set the attribute to a string then the length of the string).
Call the given WSGI application, returning (status_string, headerlist, app_iter)
Be sure to call app_iter.close() if it’s there.
If catch_exc_info is true, then returns (status_string, headerlist, app_iter, exc_info), where the fourth item may be None, but won’t be if there was an exception. If you don’t do this and there was an exception, the exception will be raised directly.
Gets and sets and deletes the ‘CONTENT_LENGTH’ key from the environment. For more information on CONTENT_LENGTH see section 14.13. Converts it as a int.
Gets and sets and deletes the ‘CONTENT_TYPE’ key from the environment. For more information on CONTENT_TYPE see section 14.17.
Like .str_cookies, but may decode values and keys
Copy the request and environment object.
This only does a shallow copy, except of wsgi.input
Copies the body, in cases where it might be shared with another request object and that is not desired.
This copies the body in-place, either into a StringIO object or a temporary file.
Copies the request and environment object, but turning this request into a GET along the way. If this was a POST request (or any other verb) then it becomes GET, and the request body is thrown away.
Gets and sets and deletes the ‘HTTP_DATE’ key from the environment. For more information on Date see section 14.8. Converts it as a HTTP date.
Like .call_application(application), except returns a response object with .status, .headers, and .body attributes.
This will use self.ResponseClass to figure out the class of the response object to return.
All the request headers as a case-insensitive dictionary-like object.
Host name provided in HTTP_HOST, with fall-back to SERVER_NAME
The URL through the host (no path)
Gets and sets and deletes the ‘HTTP_IF_MATCH’ key from the environment. For more information on If-Match see section 14.24. Converts it as a ETag.
Gets and sets and deletes the ‘HTTP_IF_MODIFIED_SINCE’ key from the environment. For more information on If-Modified-Since see section 14.25. Converts it as a HTTP date.
Gets and sets and deletes the ‘HTTP_IF_NONE_MATCH’ key from the environment. For more information on If-None-Match see section 14.26. Converts it as a ETag.
Gets and sets and deletes the ‘HTTP_IF_RANGE’ key from the environment. For more information on If-Range see section 14.27. Converts it as a IfRange object.
Gets and sets and deletes the ‘HTTP_IF_UNMODIFIED_SINCE’ key from the environment. For more information on If-Unmodified-Since see section 14.28. Converts it as a HTTP date.
Returns a boolean if X-Requested-With is present and XMLHttpRequest
Note: this isn’t set by every XMLHttpRequest request, it is only set if you are using a Javascript library that sets it (or you set the header yourself manually). Currently Prototype and jQuery are known to set this header.
This forces environ['wsgi.input'] to be seekable. That is, if it doesn’t have a seek method already, the content is copied into a StringIO or temporary file.
The choice to copy to StringIO is made from self.request_body_tempfile_limit
Gets and sets and deletes the ‘HTTP_MAX_FORWARDS’ key from the environment. For more information on Max-Forwards see section 14.31. Converts it as a int.
Gets and sets and deletes the ‘REQUEST_METHOD’ key from the environment.
Like .str_params, but may decode values and keys
The path of the request, without host or query string
Gets and sets and deletes the ‘PATH_INFO’ key from the environment.
Returns the next segment on PATH_INFO, or None if there is no next segment. Doesn’t modify the environment.
‘Pops’ off the next segment of PATH_INFO, pushing it onto SCRIPT_NAME, and returning the popped segment. Returns None if there is nothing left on PATH_INFO.
Does not return '' when there’s an empty segment (like /path//path); these segments are just ignored.
The path of the request, without host but with query string
The URL including SCRIPT_NAME and PATH_INFO, but not QUERY_STRING
Wraps a decorator, with a deprecation warning or error
Gets and sets and deletes the ‘HTTP_PRAGMA’ key from the environment. For more information on Pragma see section 14.32.
Gets and sets and deletes the ‘QUERY_STRING’ key from the environment.
Wraps a decorator, with a deprecation warning or error
Gets and sets and deletes the ‘HTTP_RANGE’ key from the environment. For more information on Range see section 14.35. Converts it as a Range object.
Gets and sets and deletes the ‘HTTP_REFERER’ key from the environment. For more information on Referer see section 14.36.
Gets and sets and deletes the ‘HTTP_REFERER’ key from the environment. For more information on Referer see section 14.36.
Resolve other_url relative to the request URL.
If to_application is True, then resolve it relative to the URL with only SCRIPT_NAME
Gets and sets and deletes the ‘REMOTE_ADDR’ key from the environment.
Gets and sets and deletes the ‘REMOTE_USER’ key from the environment.
Remove headers that make the request conditional.
These headers can cause the response to be 304 Not Modified, which in some cases you may not want to be possible.
This does not remove headers like If-Match, which are used for conflict detection.
Gets and sets and deletes the ‘wsgi.url_scheme’ key from the environment.
Gets and sets and deletes the ‘SCRIPT_NAME’ key from the environment.
Gets and sets and deletes the ‘SERVER_NAME’ key from the environment.
Gets and sets and deletes the ‘SERVER_PORT’ key from the environment. Converts it as a int.
Return a MultiDict containing all the variables from the QUERY_STRING.
Return a MultiDict containing all the variables from a form request. Returns an empty dict-like object for non-form requests.
Form requests are typically POST requests, however PUT requests with an appropriate Content-Type are also supported.
Return a plain dictionary of cookies as found in the request.
A dictionary-like object containing both the parameters from the query string and request body.
Wraps a decorator, with a deprecation warning or error
Wraps a decorator, with a deprecation warning or error
The full request URL, including QUERY_STRING
Return any positional variables matched in the URL.
Takes values from environ['wsgiorg.routing_args']. Systems like routes set this value.
Return any named variables matched in the URL.
Takes values from environ['wsgiorg.routing_args']. Systems like routes set this value.
Gets and sets and deletes the ‘HTTP_USER_AGENT’ key from the environment. For more information on User-Agent see section 14.43.