pylons.controllers.util– Controller Utility functions¶
Utility functions and classes available for use by Controllers
Pylons subclasses the WebOb
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.
Request(environ, charset=None, unicode_errors=None, decode_param_names=None, **kw)¶
WebOb Request subclass
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
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.
Response(body=None, status=None, headerlist=None, app_iter=None, content_type=None, conditional_response=None, **kw)¶
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
Saves a signed cookie of the pickled data. All other keyword
WebOb.set_cookie accepts are usable and
passed to the WebOb set_cookie method after creating the signed
abort(status_code=None, detail='', headers=None, comment=None)¶
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
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.