Request factory¶
-
class
tangled.web.request.Request(environ, app, *args, **kwargs)[source]¶ Default request factory.
Every request has a reference to its application context (i.e.,
request.app).-
abort(status_code, *args, **kwargs)[source]¶ Abort the request by raising a WSGIHTTPException.
This is a convenience so resource modules don’t need to import exceptions from
webob.exc.
-
get_setting(*args, **kwargs)[source]¶ Get an app setting.
Simply delegates to
tangled.web.app.Application.get_setting().
-
helpers¶ Get helpers for this request.
Returns a
Helpersinstance; all the helpers added viatangled.web.app.Application.add_helper()will be accessible as methods of this instance.
-
make_url(path, query=None, fragment=None, *, _fully_qualified=True)[source]¶ Generate a URL.
pathshould be application-relative (that is, it should not include SCRIPT_NAME).querycan be a string, a dict, or a sequence. Seemake_query_string()for details.If
fragmentis passed it will be quoted usingurllib.parse.quote()with no “safe” characters (i.e., all special characters will be quoted).
-
on_finished(callback, *args, **kwargs)[source]¶ Add a finished callback.
Callbacks must have the signature
(app, response). They can also take additional positional and keyword args–*argsand**kwargswill be passed along to thecallback.Finished callbacks are always called regardless of whether an error occurred while processing the request. They are called just before the Tangled application returns to its caller.
All finished callbacks will be called. If any of them raises an exception, a
RequestFinishedExceptionwill be raised and a “500 Internal Server Error” response will be returned in place of the original response.Raising instances of
webob.exc.WSGIHTTPExceptionin finished callbacks is an error.The
responseobject can be inspected to see if an error occurred while processing the request. If theresponseisNone, the request failed hard (i.e., there was an uncaught exception before the response could be created).This can be used as a decorator in the simple case where the
callbackdoesn’t take any additional args.
-
resource_config¶ Get info for the resource associated with this request.
Note
This can’t be safely accessed until after the resource has been found and set for this request.
-
resource_path(resource, urlvars=None, **kwargs)[source]¶ Generate a URL path (with SCRIPT_NAME) for a resource.
-
response¶ Create the default response object for this request.
The response is initialized with attributes set via
@config:status,location, andresponse_attrs.If no status code was set via
@config, we try our best to set it to something sane here based on content type and method.If
locationis set butstatusisn’t, the response’s status is set toDEFAULT_REDIRECT_STATUS.The location can also be set to one of the special values ‘REFERER’ or ‘CAME_FROM’. The former redirects back to the refering page. The latter redirects to whatever is set in the
came_fromrequest parameter.TODO: Check origin of referer and came from.
Note
See note in
resource_config().
-
response_content_type¶ Get the content type to use for the response.
This retrieves the content types the resource is configured to handle then selects the best match for the requested content type. If the resource isn’t explicitly configured to handle any types or of there’s no best match, the default content type will be used.
Note
This can’t be safely accessed until after the resource has been found and set for this request.
-
static_url(path, query=None, **kwargs)[source]¶ Generate a static URL from
path.pathshould always be an application-relative path like ‘/static/images/logo.png’. SCRIPT_NAME will be prepended bymake_url().
-