Utility functions and classes available for use by Controllers
Pylons subclasses the WebOb webob.Request and webob.Response classes to provide backwards compatible functions for earlier versions of Pylons as well as add a few helper functions to assist with signed cookies.
WebOb Request subclass
The WebOb webob.Request has no charset, or other defaults. This subclass adds defaults, along with several methods for backwards compatibility with paste.wsgiwrappers.WSGIRequest.
Legacy method to return the webob.Request.accept_charset
Extract a signed cookie of name from the request
The cookie is expected to have been created with Response.signed_cookie, and the secret should be the same as the one used to sign it.
Any failure in the signature of the data will result in None being returned.
WebOb Response subclass
The WebOb Response has no default content type, or error defaults. This subclass adds defaults, along with several methods for backwards compatibility with paste.wsgiwrappers.WSGIResponse.
The body of the response, as a str. This will read in the entire app_iter if necessary.
Save a signed cookie with secret signature
Saves a signed cookie of the pickled data. All other keyword arguments that WebOb.set_cookie accepts are usable and passed to the WebOb set_cookie method after creating the signed cookie value.
Aborts the request immediately by returning an HTTP exception
In the event that the status_code is a 300 series error, the detail attribute will be used as the Location header should one not be specified in the headers attribute.
Use the HTTP Entity Tag cache for Browser side caching
If a “If-None-Match” header is found, and equivilant to key, then a 304 HTTP message will be returned with the ETag to tell the browser that it should use its current cache of the page.
Otherwise, the ETag header will be added to the response headers.
Suggested use is within a Controller Action like so:
import pylons class YourController(BaseController): def index(self): etag_cache(key=1) return render('/splash.mako')
This works because etag_cache will raise an HTTPNotModified exception if the ETag received matches the key provided.
Forward the request to a WSGI application. Returns its response.