diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-10-28 23:12:41 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-10-28 23:12:41 +0000 |
| commit | 85078f4eb39c6827973292a628cdf5ff6b34249a (patch) | |
| tree | 2ec4d723643bfe73d2bd8f3f8e16415bc3e4acd4 | |
| parent | b8a620bbb842c59336f8513e0d97de1074e815dc (diff) | |
| download | pyramid-85078f4eb39c6827973292a628cdf5ff6b34249a.tar.gz pyramid-85078f4eb39c6827973292a628cdf5ff6b34249a.tar.bz2 pyramid-85078f4eb39c6827973292a628cdf5ff6b34249a.zip | |
- If the ``render_view_to_response`` function was called, if the
view was found and called, but it returned something that did not
implement IResponse, the error would pass by unflagged. This was
noticed when I created a view function that essentially returned
None, but received a NotFound error rather than a ValueError when
the view was rendered. This was fixed.
| -rw-r--r-- | CHANGES.txt | 11 | ||||
| -rw-r--r-- | docs/conf.py | 4 | ||||
| -rw-r--r-- | repoze/bfg/router.py | 4 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_view.py | 21 | ||||
| -rw-r--r-- | repoze/bfg/view.py | 25 | ||||
| -rw-r--r-- | setup.py | 2 |
6 files changed, 53 insertions, 14 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index a8a810fab..dcbe01bb3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,14 @@ +0.4.1 (10/28/2008) + + Bug Fixes + + - If the ``render_view_to_response`` function was called, if the + view was found and called, but it returned something that did not + implement IResponse, the error would pass by unflagged. This was + noticed when I created a view function that essentially returned + None, but received a NotFound error rather than a ValueError when + the view was rendered. This was fixed. + 0.4.0 (10/03/2008) Docs diff --git a/docs/conf.py b/docs/conf.py index 5efd96dfe..9b50d2343 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -51,9 +51,9 @@ copyright = '2008, Agendaless Consulting' # other places throughout the built documents. # # The short X.Y version. -version = '0.4.0' +version = '0.4.1' # The full version, including alpha/beta/rc tags. -release = '0.4.0' +release = '0.4.1' # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py index febc7ad28..2850b14e3 100644 --- a/repoze/bfg/router.py +++ b/repoze/bfg/router.py @@ -60,10 +60,6 @@ class Router(object): app = HTTPNotFound(request.url) return app(environ, start_response) - if not is_response(response): - raise ValueError('response did not implement IResponse: %r' - % response) - dispatch(NewResponse(response)) start_response(response.status, response.headerlist) diff --git a/repoze/bfg/tests/test_view.py b/repoze/bfg/tests/test_view.py index 6eee8fbab..3636692a8 100644 --- a/repoze/bfg/tests/test_view.py +++ b/repoze/bfg/tests/test_view.py @@ -124,6 +124,27 @@ class RenderViewToResponseTests(unittest.TestCase, BaseTest): response = renderer(context, request, name='registered', secure=False) self.assertEqual(response.status, '200 OK') + + def test_call_view_response_doesnt_implement_IResponse(self): + context = DummyContext() + from zope.interface import Interface + from zope.interface import directlyProvides + from repoze.bfg.interfaces import IRequest + class IContext(Interface): + pass + directlyProvides(context, IContext) + response = 'abc' + view = make_view(response) + self._registerView(view, 'registered', IContext, IRequest) + environ = self._makeEnviron() + from webob import Request + request = Request(environ) + directlyProvides(request, IRequest) + renderer = self._getFUT() + self.assertRaises(ValueError, renderer, context, request, + name='registered', secure=False) + + class RenderViewToIterableTests(unittest.TestCase, BaseTest): def _getFUT(self): from repoze.bfg.view import render_view_to_iterable diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py index 5426b53e5..0012019e7 100644 --- a/repoze/bfg/view.py +++ b/repoze/bfg/view.py @@ -6,15 +6,20 @@ from repoze.bfg.interfaces import IViewPermission from repoze.bfg.interfaces import IView from repoze.bfg.security import Unauthorized +_marker = () + def render_view_to_response(context, request, name='', secure=True): """ Render the view named ``name`` against the specified ``context`` and ``request`` to an object implementing ``repoze.bfg.interfaces.IResponse`` or ``None`` if no such view exists. This function will return ``None`` if a corresponding - view cannot be found. If ``secure`` is ``True``, and the view is - protected by a permission, the permission will be checked before - calling the view function. If the permission check disallows view - execution (based on the current security policy), a + view cannot be found. Additionally, this function will raise a + ``ValueError`` if a view function is found and called but the view + returns an object which does not implement + ``repoze.bfg.interfaces.IResponse``. If ``secure`` is ``True``, + and the view is protected by a permission, the permission will be + checked before calling the view function. If the permission check + disallows view execution (based on the current security policy), a ``repoze.bfg.security.Unauthorized`` exception will be raised; its ``args`` attribute explains why the view access was disallowed. If ``secure`` is ``False``, no permission checking is done.""" @@ -27,7 +32,15 @@ def render_view_to_response(context, request, name='', secure=True): result = permission(security_policy) if not result: raise Unauthorized(result) - return queryMultiAdapter((context, request), IView, name=name) + response = queryMultiAdapter((context, request), IView, name=name, + default=_marker) + if response is _marker: + return None + + if not is_response(response): + raise ValueError('response did not implement IResponse: %r' % response) + + return response def render_view_to_iterable(context, request, name='', secure=True): """ Render the view named ``name`` against the specified @@ -50,8 +63,6 @@ def render_view_to_iterable(context, request, name='', secure=True): response = render_view_to_response(context, request, name, secure) if response is None: return None - if not is_response(response): - raise ValueError('response did not implement IResponse: %r' % response) return response.app_iter def render_view(context, request, name='', secure=True): @@ -12,7 +12,7 @@ # ############################################################################## -__version__ = '0.4.0' +__version__ = '0.4.1' import os |
