summaryrefslogtreecommitdiff
path: root/docs/api
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-07-23 19:57:34 -0400
committerChris McDonough <chrism@plope.com>2011-07-23 19:57:34 -0400
commitb723792bfc43dc3d4446837c48d78c9258697e6d (patch)
tree0bc5d640acb8cbf4b84d13aeb3b5726c9c839a80 /docs/api
parent5191e63deb8d3408eb5138aa00e5f9ef4e5e8e22 (diff)
downloadpyramid-b723792bfc43dc3d4446837c48d78c9258697e6d.tar.gz
pyramid-b723792bfc43dc3d4446837c48d78c9258697e6d.tar.bz2
pyramid-b723792bfc43dc3d4446837c48d78c9258697e6d.zip
- New method: ``pyramid.request.Request.add_view_mapper``. A view wrapper is
used to wrap the found view callable before it is called by Pyramid's router. This is a feature usually only used by framework extensions, to provide, for example, view timing support. A view wrapper factory must be a callable which accepts three arguments: ``view_callable``, ``request``, and ``exc``. It must return a view callable. The view callable returned by the factory must implement the ``context, request`` view callable calling convention. For example:: import time def wrapper_factory(view_callable, request, exc): def wrapper(context, request): start = time.time() result = view_callable(context, request) end = time.time() request.view_timing = end - start return result return wrapper The ``view_callable`` argument to the factory will be the view callable found by Pyramid via view lookup. The ``request`` argument to the factory will be the current request. The ``exc`` argument to the factory will be an Exception object if the found view is an exception view; it will be ``None`` otherwise. View wrappers only last for the duration of a single request. You can add such a factory for every request by using the ``pyramid.events.NewRequest`` subscriber:: from pyramid.events import subscriber, NewRequest @subscriber(NewRequest) def newrequest(event): event.request.add_view_wrapper(wrapper_factory) If more than one view wrapper is registered during a single request, a 'later' view wrapper factory will be called with the result of its directly former view wrapper factory as its ``view_callable`` argument; this chain will be returned to Pyramid as a single view callable.
Diffstat (limited to 'docs/api')
-rw-r--r--docs/api/request.rst2
1 files changed, 2 insertions, 0 deletions
diff --git a/docs/api/request.rst b/docs/api/request.rst
index 404825d1b..58532bbd1 100644
--- a/docs/api/request.rst
+++ b/docs/api/request.rst
@@ -154,6 +154,8 @@
.. automethod:: add_finished_callback
+ .. automethod:: add_view_wrapper
+
.. automethod:: route_url
.. automethod:: route_path