diff options
| -rw-r--r-- | CHANGES.txt | 11 | ||||
| -rw-r--r-- | TODO.txt | 2 | ||||
| -rw-r--r-- | docs/narr/events.rst | 4 | ||||
| -rw-r--r-- | repoze/bfg/events.py | 11 | ||||
| -rw-r--r-- | repoze/bfg/interfaces.py | 1 | ||||
| -rw-r--r-- | repoze/bfg/router.py | 2 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_events.py | 11 |
7 files changed, 31 insertions, 11 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 1228ef4aa..bddef2b4f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,10 @@ Features ``repoze.bfg.request`` API chapter. It can be used to influence response values before a concrete response object has been created. +- The ``repoze.bfg.interfaces.INewResponse`` interface now includes a + ``request`` attribute; as a result, a handler for INewResponse now + has access to the request which caused the response. + - Each of the follow methods of the Configurator now allow the below-named arguments to be passed as "dotted name strings" (e.g. "foo.bar.baz") rather than as actual implementation objects @@ -85,6 +89,9 @@ Documentation new ``repoze.bfg.request`` API chapter. Some content was moved from this chapter into the API documentation itself. +- Various changes to denote that Python dotted names are now allowed + as input to Configurator methods. + Internal -------- @@ -96,6 +103,10 @@ Internal ``repoze.bfg.request.Request.add_response_callback`` takes its place. +- The ``repoze.bfg.events.NewResponse`` class's construct has changed: + it now must be created with ``(request, response)`` rather than + simply ``(response)``. + 1.3a9 (2010-08-22) ================== @@ -59,8 +59,6 @@ - Raise an exception when a value in response_headerlist is not a string or decide to encode. -- Make NewResponse event carry request. - - Change docs so that we dont use INewReponse, but instead just NewResponse (likewise for INewRequest, etc). diff --git a/docs/narr/events.rst b/docs/narr/events.rst index 6b46cfd9c..35e4120dc 100644 --- a/docs/narr/events.rst +++ b/docs/narr/events.rst @@ -202,5 +202,7 @@ because the interface defined at know that :class:`repoze.bfg.interfaces.INewResponse` events have a ``response`` attribute, which is a response object constructed by your application, because the interface defined at -:class:`repoze.bfg.interfaces.INewResponse` says it must. +:class:`repoze.bfg.interfaces.INewResponse` says it must +(:class:`repoze.bfg.interfaces.INewResponse` objects also have a +``request``). diff --git a/repoze/bfg/events.py b/repoze/bfg/events.py index 22822eeeb..dd4f2eacc 100644 --- a/repoze/bfg/events.py +++ b/repoze/bfg/events.py @@ -82,8 +82,12 @@ class NewRequest(object): class NewResponse(object): """ An instance of this class is emitted as an :term:`event` whenever any :mod:`repoze.bfg` view returns a :term:`response`. - The instance has an attribute, ``response``, which is the response - object returned by the view. This class implements the + + The instance has two attributes:``request``, which is the request + which caused the response, and ``response``, which is the response + object returned by a view or renderer. + + This class implements the :class:`repoze.bfg.interfaces.INewResponse` interface. .. note:: @@ -96,7 +100,8 @@ class NewResponse(object): :class:`repoze.bfg.interfaces.INewRequest` event. """ implements(INewResponse) - def __init__(self, response): + def __init__(self, request, response): + self.request = request self.response = response class AfterTraversal(object): diff --git a/repoze/bfg/interfaces.py b/repoze/bfg/interfaces.py index 086c93f3a..86e2206e3 100644 --- a/repoze/bfg/interfaces.py +++ b/repoze/bfg/interfaces.py @@ -16,6 +16,7 @@ class INewRequest(Interface): class INewResponse(Interface): """ An event type that is emitted whenever any :mod:`repoze.bfg` view returns a response.""" + request = Attribute('The request object') response = Attribute('The response object') class IWSGIApplicationCreatedEvent(Interface): diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py index 8f96bb798..277ee559b 100644 --- a/repoze/bfg/router.py +++ b/repoze/bfg/router.py @@ -157,7 +157,7 @@ class Router(object): request._process_response_callbacks(response) # process the response - has_listeners and registry.notify(NewResponse(response)) + has_listeners and registry.notify(NewResponse(request, response)) start_response(status, headers) return app_iter diff --git a/repoze/bfg/tests/test_events.py b/repoze/bfg/tests/test_events.py index c258c4ad2..c122f4744 100644 --- a/repoze/bfg/tests/test_events.py +++ b/repoze/bfg/tests/test_events.py @@ -31,8 +31,8 @@ class NewResponseEventTests(unittest.TestCase): from repoze.bfg.events import NewResponse return NewResponse - def _makeOne(self, response): - return self._getTargetClass()(response) + def _makeOne(self, request, response): + return self._getTargetClass()(request, response) def test_class_implements(self): from repoze.bfg.interfaces import INewResponse @@ -43,13 +43,16 @@ class NewResponseEventTests(unittest.TestCase): def test_instance_implements(self): from repoze.bfg.interfaces import INewResponse from zope.interface.verify import verifyObject + request = DummyRequest() response = DummyResponse() - inst = self._makeOne(response) + inst = self._makeOne(request, response) verifyObject(INewResponse, inst) def test_ctor(self): + request = DummyRequest() response = DummyResponse() - inst = self._makeOne(response) + inst = self._makeOne(request, response) + self.assertEqual(inst.request, request) self.assertEqual(inst.response, response) class WSGIAppEventTests(unittest.TestCase): |
