diff options
| author | Chris McDonough <chrism@plope.com> | 2011-08-14 21:12:23 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-08-14 21:12:23 -0400 |
| commit | 27443561a9b837684af726b1aec2b5a98b22d494 (patch) | |
| tree | 5fed50635ceb7c04b0e129b15fecc47c90b31c3a | |
| parent | 42d31c1c6355a7d6c72393ca668d7d200a994da3 (diff) | |
| download | pyramid-27443561a9b837684af726b1aec2b5a98b22d494.tar.gz pyramid-27443561a9b837684af726b1aec2b5a98b22d494.tar.bz2 pyramid-27443561a9b837684af726b1aec2b5a98b22d494.zip | |
- ``pyramid.testing.DummyRequest`` now implements the
``add_finished_callback`` and ``add_response_callback`` methods.
| -rw-r--r-- | CHANGES.txt | 3 | ||||
| -rw-r--r-- | TODO.txt | 22 | ||||
| -rw-r--r-- | pyramid/request.py | 69 | ||||
| -rw-r--r-- | pyramid/testing.py | 12 |
4 files changed, 48 insertions, 58 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 60dac0d2a..c5cf8b248 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -52,6 +52,9 @@ Features will be ``None`` until an exception is caught by the Pyramid router, after which it will be the result of ``sys.exc_info()``. +- ``pyramid.testing.DummyRequest`` now implements the + ``add_finished_callback`` and ``add_response_callback`` methods. + Internal -------- @@ -11,32 +11,22 @@ Should-Have during a config.include (they are related, so just exposing the currently underscored-private _set_auth* methods won't cut it). -- Come up with an analogue of repoze.zodbconn that doesn't require a closer - in the pipeline and use it in the ZODB scaffold and tutorial. - - Merge Michael's route group work. - Deprecate pyramid.security.view_execution_permitted (it only works for traversal). -- Make "localizer" a property of request (instead of requiring - "get_localizer(request)" - -- Fix tutorials that use ``route_url``, ``route_path``, ``resource_url``, - ``static_url``, and ``current_route_url`` functions to use methods of the - request instead. - -- Make ``current_route_url`` a method of request. - -- Create a ``current_route_path`` function and make it a method of request. - -- "static_path" API (omit host and port). - - Kill off ``bfg.routes`` envvars in router. - Debugging setting for detecting why authenticated_userid(request) might return None. +- Make "localizer" a property of request (instead of requiring + "get_localizer(request)"? + +- Create a ``current_route_path`` function and make it a method of request? + +- "static_path" API (omit host and port)? Nice-to-Have ------------ diff --git a/pyramid/request.py b/pyramid/request.py index 640b0bd97..03717031d 100644 --- a/pyramid/request.py +++ b/pyramid/request.py @@ -19,7 +19,7 @@ from pyramid.url import URLMethodsMixin class TemplateContext(object): pass -class DeprecatedRequestMethods(object): +class DeprecatedRequestMethodsMixin(object): # b/c dict interface for "root factory" code that expects a bare # environ. Explicitly omitted dict methods: clear (unnecessary), @@ -175,41 +175,9 @@ class DeprecatedRequestMethods(object): response_cache_for, rr_dep % ('cache_for', 'cache_expires')) - -class Request(BaseRequest, DeprecatedRequestMethods, URLMethodsMixin): - """ - A subclass of the :term:`WebOb` Request class. An instance of - this class is created by the :term:`router` and is provided to a - view callable (and to other subsystems) as the ``request`` - argument. - - The documentation below (save for the ``add_response_callback`` and - ``add_finished_callback`` methods, which are defined in this subclass - itself, and the attributes ``context``, ``registry``, ``root``, - ``subpath``, ``traversed``, ``view_name``, ``virtual_root`` , and - ``virtual_root_path``, each of which is added to the request by the - :term:`router` at request ingress time) are autogenerated from the WebOb - source code used when this documentation was generated. - - Due to technical constraints, we can't yet display the WebOb - version number from which this documentation is autogenerated, but - it will be the 'prevailing WebOb version' at the time of the - release of this :app:`Pyramid` version. See - http://pythonpaste.org/webob/ for further information. - """ - implements(IRequest) +class CallbackMethodsMixin(object): response_callbacks = () finished_callbacks = () - exception = None - exc_info = None - matchdict = None - matched_route = None - - @reify - def tmpl_context(self): - """ Template context (for Pylons apps) """ - return TemplateContext() - def add_response_callback(self, callback): """ Add a callback to the set of callbacks to be called by the @@ -315,6 +283,39 @@ class Request(BaseRequest, DeprecatedRequestMethods, URLMethodsMixin): callback = callbacks.pop(0) callback(self) +class Request(BaseRequest, DeprecatedRequestMethodsMixin, URLMethodsMixin, + CallbackMethodsMixin): + """ + A subclass of the :term:`WebOb` Request class. An instance of + this class is created by the :term:`router` and is provided to a + view callable (and to other subsystems) as the ``request`` + argument. + + The documentation below (save for the ``add_response_callback`` and + ``add_finished_callback`` methods, which are defined in this subclass + itself, and the attributes ``context``, ``registry``, ``root``, + ``subpath``, ``traversed``, ``view_name``, ``virtual_root`` , and + ``virtual_root_path``, each of which is added to the request by the + :term:`router` at request ingress time) are autogenerated from the WebOb + source code used when this documentation was generated. + + Due to technical constraints, we can't yet display the WebOb + version number from which this documentation is autogenerated, but + it will be the 'prevailing WebOb version' at the time of the + release of this :app:`Pyramid` version. See + http://pythonpaste.org/webob/ for further information. + """ + implements(IRequest) + exception = None + exc_info = None + matchdict = None + matched_route = None + + @reify + def tmpl_context(self): + """ Template context (for Pylons apps) """ + return TemplateContext() + @reify def session(self): """ Obtain the :term:`session` object associated with this diff --git a/pyramid/testing.py b/pyramid/testing.py index 7e5bb50d1..86333b5fc 100644 --- a/pyramid/testing.py +++ b/pyramid/testing.py @@ -25,7 +25,8 @@ from pyramid.security import Everyone from pyramid.security import has_permission from pyramid.threadlocal import get_current_registry from pyramid.threadlocal import manager -from pyramid.request import DeprecatedRequestMethods +from pyramid.request import DeprecatedRequestMethodsMixin +from pyramid.request import CallbackMethodsMixin from pyramid.url import URLMethodsMixin _marker = object() @@ -621,7 +622,8 @@ class DummySession(dict): def get_csrf_token(self): return self.get('_csrft_', None) -class DummyRequest(DeprecatedRequestMethods, URLMethodsMixin): +class DummyRequest(DeprecatedRequestMethodsMixin, URLMethodsMixin, + CallbackMethodsMixin): """ A DummyRequest object (incompletely) imitates a :term:`request` object. The ``params``, ``environ``, ``headers``, ``path``, and @@ -654,7 +656,6 @@ class DummyRequest(DeprecatedRequestMethods, URLMethodsMixin): host = 'example.com:80' content_length = 0 query_string = '' - response_callbacks = () charset = 'UTF-8' script_name = '' _registry = None @@ -699,11 +700,6 @@ class DummyRequest(DeprecatedRequestMethods, URLMethodsMixin): self.session = DummySession() self.__dict__.update(kw) - def add_response_callback(self, callback): - if not self.response_callbacks: - self.response_callbacks = [] - self.response_callbacks.append(callback) - def _get_registry(self): if self._registry is None: return get_current_registry() |
