From 49304cecdf2c51888ee4ff42ec6496207186ad9b Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 2 Nov 2009 12:23:26 +0000 Subject: - 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:: Like any framework event, a subscriber function should expect one parameter: ``event``. --- repoze/bfg/events.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'repoze/bfg/events.py') 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 -- cgit v1.2.3