summaryrefslogtreecommitdiff
path: root/repoze/bfg/events.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-11-02 12:23:26 +0000
committerChris McDonough <chrism@agendaless.com>2009-11-02 12:23:26 +0000
commit49304cecdf2c51888ee4ff42ec6496207186ad9b (patch)
tree82172ae270dfd0d5d972f65d4669c93219c9f469 /repoze/bfg/events.py
parent32d95886503540052d9b7075c9ce3326b042bb08 (diff)
downloadpyramid-49304cecdf2c51888ee4ff42ec6496207186ad9b.tar.gz
pyramid-49304cecdf2c51888ee4ff42ec6496207186ad9b.tar.bz2
pyramid-49304cecdf2c51888ee4ff42ec6496207186ad9b.zip
- Add a new event type: ``repoze.bfg.events.AfterTraversal``. Events
of this type will be sent after traversal is completed, but before any view code is invoked. Like ``repoze.bfg.events.NewRequest``, This event will have a single attribute: ``request`` representing the current request. Unlike the request attribute of ``repoze.bfg.events.NewRequest`` however, during an AfterTraversal event, the request object will possess attributes set by the traverser, most notably ``context``, which will be the context used when a view is found and invoked. The interface ``repoze.bfg.events.IAfterTraversal`` can be used to subscribe to the event. For example:: <subscriber for="repoze.bfg.interfaces.IAfterTraversal" handler="my.app.handle_after_traverse"/> Like any framework event, a subscriber function should expect one parameter: ``event``.
Diffstat (limited to 'repoze/bfg/events.py')
-rw-r--r--repoze/bfg/events.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/repoze/bfg/events.py b/repoze/bfg/events.py
index 54f60c294..14e47ca3f 100644
--- a/repoze/bfg/events.py
+++ b/repoze/bfg/events.py
@@ -1,5 +1,6 @@
from zope.interface import implements
+from repoze.bfg.interfaces import IAfterTraversal
from repoze.bfg.interfaces import INewRequest
from repoze.bfg.interfaces import INewResponse
from repoze.bfg.interfaces import IWSGIApplicationCreatedEvent
@@ -23,6 +24,20 @@ class NewResponse(object):
def __init__(self, response):
self.response = response
+class AfterTraversal(object):
+ implements(IAfterTraversal)
+ """ An instance of this class is emitted as an event after the
+ repoze.bfg router performs traversal (but before any view code is
+ executed). The instance has an attribute, ``request``, which is
+ the request object returned by the view. Notably, the request
+ object will have an attribute named ``context``, which is the
+ context that will be provided to the view which will eventually be
+ called, as well as other attributes defined by the traverser.
+ This class implements the
+ ``repoze.bfg.interfaces.IAfterTraversal`` interface."""
+ def __init__(self, request):
+ self.request = request
+
class WSGIApplicationCreatedEvent(object):
""" An instance of this class is emitted as an event whenever a
``repoze.bfg`` application starts. The instance has an attribute,
@@ -32,7 +47,5 @@ class WSGIApplicationCreatedEvent(object):
implements(IWSGIApplicationCreatedEvent)
def __init__(self, app):
self.app = app
+ self.object = app
- @property
- def object(self):
- return self.app