From bca03fcb8df46485d722156da4f2f7685f234ab8 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 27 Apr 2011 16:20:47 -0400 Subject: - Previously, ``pyramid.request.Request`` inherited from ``webob.request.Request`` and implemented ``__getattr__``, ``__setattr__`` and ``__delattr__`` itself in order to overidde "adhoc attr" WebOb behavior where attributes of the request are stored in the environ. Now, ``pyramid.request.Request`` object inherits from (the more recent) ``webob.request.BaseRequest`` instead of ``webob.request.Request``, which provides the same behavior. ``pyramid.request.Request`` no longer implements its own ``__getattr__``, ``__setattr__`` or ``__delattr__`` as a result. --- CHANGES.txt | 10 ++++++++++ pyramid/request.py | 10 ++-------- pyramid/tests/test_request.py | 6 ++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d329c260d..7d469551a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -211,6 +211,16 @@ Behavior Changes the perspective of the downstream application (for example, ``SCRIPT_NAME`` will now never possess a trailing slash). +- Previously, ``pyramid.request.Request`` inherited from + ``webob.request.Request`` and implemented ``__getattr__``, ``__setattr__`` + and ``__delattr__`` itself in order to overidde "adhoc attr" WebOb behavior + where attributes of the request are stored in the environ. Now, + ``pyramid.request.Request`` object inherits from (the more recent) + ``webob.request.BaseRequest`` instead of ``webob.request.Request``, which + provides the same behavior. ``pyramid.request.Request`` no longer + implements its own ``__getattr__``, ``__setattr__`` or ``__delattr__`` as a + result. + Dependencies ------------ diff --git a/pyramid/request.py b/pyramid/request.py index 0fe8b9379..e5feecd4f 100644 --- a/pyramid/request.py +++ b/pyramid/request.py @@ -1,7 +1,7 @@ from zope.interface import implements from zope.interface.interface import InterfaceClass -from webob import Request as WebobRequest +from webob import BaseRequest from pyramid.interfaces import IRequest from pyramid.interfaces import ISessionFactory @@ -10,7 +10,6 @@ from pyramid.interfaces import IResponseFactory from pyramid.exceptions import ConfigurationError from pyramid.decorator import reify from pyramid.response import Response -from pyramid.traversal import quote_path_segment from pyramid.url import resource_url from pyramid.url import route_url from pyramid.url import static_url @@ -19,7 +18,7 @@ from pyramid.url import route_path class TemplateContext(object): pass -class Request(WebobRequest): +class Request(BaseRequest): """ A subclass of the :term:`WebOb` Request class. An instance of this class is created by the :term:`router` and is provided to a @@ -321,11 +320,6 @@ class Request(WebobRequest): default=Response) return response_factory() - # override default WebOb "environ['adhoc_attr']" mutation behavior - __getattr__ = object.__getattribute__ - __setattr__ = object.__setattr__ - __delattr__ = object.__delattr__ - # 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) diff --git a/pyramid/tests/test_request.py b/pyramid/tests/test_request.py index 60d59ece6..cdd9aa51e 100644 --- a/pyramid/tests/test_request.py +++ b/pyramid/tests/test_request.py @@ -83,7 +83,7 @@ class TestRequest(unittest.TestCase): from pyramid.exceptions import ConfigurationError inst = self._makeOne({}) inst.registry = self.config.registry - self.assertRaises(ConfigurationError, inst.__getattr__, 'session') + self.assertRaises(ConfigurationError, getattr, inst, 'session') def test_setattr_and_getattr_dotnotation(self): inst = self._makeOne({}) @@ -91,9 +91,11 @@ class TestRequest(unittest.TestCase): self.assertEqual(inst.foo, 1) def test_setattr_and_getattr(self): - inst = self._makeOne({}) + environ = {} + inst = self._makeOne(environ) setattr(inst, 'bar', 1) self.assertEqual(getattr(inst, 'bar'), 1) + self.assertEqual(environ, {}) # make sure we're not using adhoc attrs def test___contains__(self): environ ={'zooma':1} -- cgit v1.2.3