- New method named ``pyramid.request.Request.is_response``. This method
should be used instead of the ``pyramid.view.is_response`` function, which
has been deprecated.
- Deprecated ``pyramid.view.is_response`` function in favor of (newly-added)
``pyramid.request.Request.is_response`` method. Determining if an object
is truly a valid response object now requires access to the registry, which
is only easily available as a request attribute. The
``pyramid.view.is_response`` function will still work until it is removed,
but now may return an incorrect answer under some (very uncommon)
circumstances.
| | |
| | | among other things, the ``conditional_response`` feature of WebOb response |
| | | objects will now behave properly. |
| | | |
| | | - New method named ``pyramid.request.Request.is_response``. This method |
| | | should be used instead of the ``pyramid.view.is_response`` function, which |
| | | has been deprecated. |
| | | |
| | | Bug Fixes |
| | | --------- |
| | | |
| | |
| | | 1.0 and before). In a future version, these methods will be removed |
| | | entirely. |
| | | |
| | | - Deprecated ``pyramid.view.is_response`` function in favor of (newly-added) |
| | | ``pyramid.request.Request.is_response`` method. Determining if an object |
| | | is truly a valid response object now requires access to the registry, which |
| | | is only easily available as a request attribute. The |
| | | ``pyramid.view.is_response`` function will still work until it is removed, |
| | | but now may return an incorrect answer under some (very uncommon) |
| | | circumstances. |
| | | |
| | | Behavior Changes |
| | | ---------------- |
| | | |
| | |
| | | |
| | | - To subclass or not subclass http exceptions. |
| | | |
| | | - Deprecate view.is_response? |
| | | |
| | | - Move is_response to response.py? |
| | | |
| | | - Create add_response_adapter Configurator API? |
| | | |
| | | - Make sure registering IResponse adapter for webob.Response doesn't make it |
| | | impossible to register an IResponse adapter for an interface that a |
| | | webob.Response happens to implement. |
| | | |
| | | - Run whatsitdoing tests. |
| | | |
| | | - Docs mention ``exception.args[0]`` as a way to get messages; check that |
| | | this works. |
| | | |
| | |
| | | default=Response) |
| | | return response_factory() |
| | | |
| | | def is_response(self, ob): |
| | | """ Return ``True`` if the object passed as ``ob`` is a valid |
| | | response object, ``False`` otherwise.""" |
| | | registry = self.registry |
| | | adapted = registry.queryAdapterOrSelf(ob, IResponse) |
| | | if adapted is None: |
| | | return False |
| | | return adapted is ob |
| | | |
| | | # b/c dict interface for "root factory" code that expects a bare |
| | | # environ. Explicitly omitted dict methods: clear (unnecessary), |
| | | # copy (implemented by WebOb), fromkeys (unnecessary); deprecated |
| | |
| | | self.assertEqual(result, 'abc') |
| | | self.assertEqual(info.args, |
| | | ('pyramid.tests:static/foo.css', request, {}) ) |
| | | |
| | | def test_is_response_false(self): |
| | | request = self._makeOne({}) |
| | | request.registry = self.config.registry |
| | | self.assertEqual(request.is_response('abc'), False) |
| | | |
| | | def test_is_response_false_adapter_is_not_self(self): |
| | | from pyramid.interfaces import IResponse |
| | | request = self._makeOne({}) |
| | | request.registry = self.config.registry |
| | | def adapter(ob): |
| | | return object() |
| | | class Foo(object): |
| | | pass |
| | | foo = Foo() |
| | | request.registry.registerAdapter(adapter, (Foo,), IResponse) |
| | | self.assertEqual(request.is_response(foo), False) |
| | | |
| | | def test_is_response_adapter_true(self): |
| | | from pyramid.interfaces import IResponse |
| | | request = self._makeOne({}) |
| | | request.registry = self.config.registry |
| | | class Foo(object): |
| | | pass |
| | | foo = Foo() |
| | | def adapter(ob): |
| | | return ob |
| | | request.registry.registerAdapter(adapter, (Foo,), IResponse) |
| | | self.assertEqual(request.is_response(foo), True) |
| | | |
| | | class TestRequestDeprecatedMethods(unittest.TestCase): |
| | | def setUp(self): |
| | |
| | | self.assertEqual(s, 'anotherview') |
| | | |
| | | class TestIsResponse(unittest.TestCase): |
| | | def setUp(self): |
| | | from zope.deprecation import __show__ |
| | | __show__.off() |
| | | |
| | | def tearDown(self): |
| | | from zope.deprecation import __show__ |
| | | __show__.on() |
| | | |
| | | def _callFUT(self, *arg, **kw): |
| | | from pyramid.view import is_response |
| | | return is_response(*arg, **kw) |
| | |
| | | """ Return ``True`` if ``ob`` implements the interface implied by |
| | | :ref:`the_response`. ``False`` if not. |
| | | |
| | | .. note:: This isn't a true interface or subclass check. Instead, it's a |
| | | duck-typing check, as response objects are not obligated to be of a |
| | | particular class or provide any particular Zope interface.""" |
| | | |
| | | # response objects aren't obligated to implement a Zope interface, |
| | | # so we do it the hard way |
| | | .. warning:: This function is deprecated as of :app:`Pyramid` 1.1. New |
| | | code should not use it. Instead, new code should use the |
| | | :func:`pyramid.request.Request.is_response` method.""" |
| | | if ( hasattr(ob, 'app_iter') and hasattr(ob, 'headerlist') and |
| | | hasattr(ob, 'status') ): |
| | | return True |
| | | return False |
| | | |
| | | deprecated( |
| | | 'is_response', |
| | | 'pyramid.view.is_response is deprecated as of Pyramid 1.1. Use ' |
| | | 'pyramid.request.Request.is_response instead.') |