summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2013-09-08 21:24:04 -0400
committerChris McDonough <chrism@plope.com>2013-09-08 21:24:04 -0400
commit8fe57d871af1321b0e2b853c559d8e5c127db5fa (patch)
tree5cfc294d918c5a0451f33a83e2fb5212f12af60b
parentfdf30b3bb6f47d93d2f255a09e75be0c33d54789 (diff)
downloadpyramid-8fe57d871af1321b0e2b853c559d8e5c127db5fa.tar.gz
pyramid-8fe57d871af1321b0e2b853c559d8e5c127db5fa.tar.bz2
pyramid-8fe57d871af1321b0e2b853c559d8e5c127db5fa.zip
- Removed the ability to influence and query a ``pyramid.request.Request``
object as if it were a dictionary. Previously it was possible to use methods like ``__getitem__``, ``get``, ``items``, and other dictlike methods to access values in the WSGI environment. This behavior had been deprecated since Pyramid 1.1. Use methods of ``request.environ`` (a real dictionary) instead.
-rw-r--r--CHANGES.txt7
-rw-r--r--pyramid/compat.py2
-rw-r--r--pyramid/request.py89
-rw-r--r--pyramid/testing.py9
-rw-r--r--pyramid/tests/test_request.py157
5 files changed, 12 insertions, 252 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 69547ad46..641219a8b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -91,6 +91,13 @@ Backwards Incompatibilities
``pyramid.config.Configurator.add_static_view`` function too, because it
delegates to ``add_route``.
+- Removed the ability to influence and query a ``pyramid.request.Request``
+ object as if it were a dictionary. Previously it was possible to use methods
+ like ``__getitem__``, ``get``, ``items``, and other dictlike methods to
+ access values in the WSGI environment. This behavior had been deprecated
+ since Pyramid 1.1. Use methods of ``request.environ`` (a real dictionary)
+ instead.
+
1.5a1 (2013-08-30)
==================
diff --git a/pyramid/compat.py b/pyramid/compat.py
index 222810b3b..bfa345b88 100644
--- a/pyramid/compat.py
+++ b/pyramid/compat.py
@@ -160,7 +160,7 @@ if PY3: # pragma: no cover
return d.values()
def iterkeys_(d):
return d.keys()
-else:
+else: # pragma: no cover
def iteritems_(d):
return d.iteritems()
def itervalues_(d):
diff --git a/pyramid/request.py b/pyramid/request.py
index 5c064d3ef..2cf0613f7 100644
--- a/pyramid/request.py
+++ b/pyramid/request.py
@@ -1,7 +1,5 @@
import json
-from zope.deprecation import deprecate
-from zope.deprecation.deprecation import deprecated
from zope.interface import implementer
from zope.interface.interface import InterfaceClass
@@ -15,9 +13,6 @@ from pyramid.interfaces import (
)
from pyramid.compat import (
- iterkeys_,
- itervalues_,
- iteritems_,
text_,
bytes_,
native_,
@@ -32,85 +27,6 @@ from pyramid.util import InstancePropertyMixin
class TemplateContext(object):
pass
-class DeprecatedRequestMethodsMixin(object):
-
- # 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
- # as of Pyramid 1.1.
-
- dictlike = ('Use of the request as a dict-like object is deprecated as '
- 'of Pyramid 1.1. Use dict-like methods of "request.environ" '
- 'instead.')
-
- @deprecate(dictlike)
- def __contains__(self, k):
- return self.environ.__contains__(k)
-
- @deprecate(dictlike)
- def __delitem__(self, k):
- return self.environ.__delitem__(k)
-
- @deprecate(dictlike)
- def __getitem__(self, k):
- return self.environ.__getitem__(k)
-
- @deprecate(dictlike)
- def __iter__(self):
- return iter(self.environ)
-
- @deprecate(dictlike)
- def __setitem__(self, k, v):
- self.environ[k] = v
-
- @deprecate(dictlike)
- def get(self, k, default=None):
- return self.environ.get(k, default)
-
- @deprecate(dictlike)
- def has_key(self, k):
- return k in self.environ
-
- @deprecate(dictlike)
- def items(self):
- return self.environ.items()
-
- @deprecate(dictlike)
- def iteritems(self):
- return iteritems_(self.environ)
-
- @deprecate(dictlike)
- def iterkeys(self):
- return iterkeys_(self.environ)
-
- @deprecate(dictlike)
- def itervalues(self):
- return itervalues_(self.environ)
-
- @deprecate(dictlike)
- def keys(self):
- return self.environ.keys()
-
- @deprecate(dictlike)
- def pop(self, k):
- return self.environ.pop(k)
-
- @deprecate(dictlike)
- def popitem(self):
- return self.environ.popitem()
-
- @deprecate(dictlike)
- def setdefault(self, v, default):
- return self.environ.setdefault(v, default)
-
- @deprecate(dictlike)
- def update(self, v, **kw):
- return self.environ.update(v, **kw)
-
- @deprecate(dictlike)
- def values(self):
- return self.environ.values()
-
class CallbackMethodsMixin(object):
response_callbacks = ()
finished_callbacks = ()
@@ -220,9 +136,8 @@ class CallbackMethodsMixin(object):
callback(self)
@implementer(IRequest)
-class Request(BaseRequest, DeprecatedRequestMethodsMixin, URLMethodsMixin,
- CallbackMethodsMixin, InstancePropertyMixin,
- LocalizerRequestMixin):
+class Request(BaseRequest, URLMethodsMixin, CallbackMethodsMixin,
+ InstancePropertyMixin, LocalizerRequestMixin):
"""
A subclass of the :term:`WebOb` Request class. An instance of
this class is created by the :term:`router` and is provided to a
diff --git a/pyramid/testing.py b/pyramid/testing.py
index 36c690117..789047ab3 100644
--- a/pyramid/testing.py
+++ b/pyramid/testing.py
@@ -34,12 +34,8 @@ from pyramid.threadlocal import (
manager,
)
-from pyramid.request import (
- DeprecatedRequestMethodsMixin,
- CallbackMethodsMixin,
- )
-
from pyramid.i18n import LocalizerRequestMixin
+from pyramid.request import CallbackMethodsMixin
from pyramid.url import URLMethodsMixin
from pyramid.util import InstancePropertyMixin
@@ -286,8 +282,7 @@ class DummySession(dict):
@implementer(IRequest)
-class DummyRequest(DeprecatedRequestMethodsMixin, URLMethodsMixin,
- CallbackMethodsMixin, InstancePropertyMixin,
+class DummyRequest(URLMethodsMixin, CallbackMethodsMixin, InstancePropertyMixin,
LocalizerRequestMixin):
""" A DummyRequest object (incompletely) imitates a :term:`request` object.
diff --git a/pyramid/tests/test_request.py b/pyramid/tests/test_request.py
index 565c6377e..6cd72fc59 100644
--- a/pyramid/tests/test_request.py
+++ b/pyramid/tests/test_request.py
@@ -308,163 +308,6 @@ class TestRequest(unittest.TestCase):
self.assertEqual(1, request.db)
self.assertEqual(1, request.db)
-class TestRequestDeprecatedMethods(unittest.TestCase):
- def setUp(self):
- self.config = testing.setUp()
- from zope.deprecation import __show__
- __show__.off()
-
- def tearDown(self):
- testing.tearDown()
- from zope.deprecation import __show__
- __show__.on()
-
- def _getTargetClass(self):
- from pyramid.request import Request
- return Request
-
- def _makeOne(self, environ=None):
- if environ is None:
- environ = {}
- return self._getTargetClass()(environ)
-
- def test___contains__(self):
- environ ={'zooma':1}
- inst = self._makeOne(environ)
- self.assertTrue('zooma' in inst)
-
- def test___delitem__(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- del inst['zooma']
- self.assertFalse('zooma' in environ)
-
- def test___getitem__(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- self.assertEqual(inst['zooma'], 1)
-
- def test___iter__(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- iterator = iter(inst)
- self.assertEqual(list(iterator), list(iter(environ)))
-
- def test___setitem__(self):
- environ = {}
- inst = self._makeOne(environ)
- inst['zooma'] = 1
- self.assertEqual(environ, {'zooma':1})
-
- def test_get(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- self.assertEqual(inst.get('zooma'), 1)
-
- def test_has_key(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- self.assertEqual(inst.has_key('zooma'), True)
-
- def test_items(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- self.assertEqual(inst.items(), environ.items())
-
- def test_iteritems(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- self.assertEqual(list(inst.iteritems()), list(iteritems_(environ)))
-
- def test_iterkeys(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- self.assertEqual(list(inst.iterkeys()), list(iterkeys_(environ)))
-
- def test_itervalues(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- self.assertEqual(list(inst.itervalues()), list(itervalues_(environ)))
-
- def test_keys(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- self.assertEqual(inst.keys(), environ.keys())
-
- def test_pop(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- popped = inst.pop('zooma')
- self.assertEqual(environ, {})
- self.assertEqual(popped, 1)
-
- def test_popitem(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- popped = inst.popitem()
- self.assertEqual(environ, {})
- self.assertEqual(popped, ('zooma', 1))
-
- def test_setdefault(self):
- environ = {}
- inst = self._makeOne(environ)
- marker = []
- result = inst.setdefault('a', marker)
- self.assertEqual(environ, {'a':marker})
- self.assertEqual(result, marker)
-
- def test_update(self):
- environ = {}
- inst = self._makeOne(environ)
- inst.update({'a':1}, b=2)
- self.assertEqual(environ, {'a':1, 'b':2})
-
- def test_values(self):
- environ = {'zooma':1}
- inst = self._makeOne(environ)
- result = list(inst.values())
- self.assertEqual(result, list(environ.values()))
-
- def test_response_content_type(self):
- inst = self._makeOne()
- self.assertFalse(hasattr(inst, 'response_content_type'))
- inst.response_content_type = 'abc'
- self.assertEqual(inst.response_content_type, 'abc')
- del inst.response_content_type
- self.assertFalse(hasattr(inst, 'response_content_type'))
-
- def test_response_headerlist(self):
- inst = self._makeOne()
- self.assertFalse(hasattr(inst, 'response_headerlist'))
- inst.response_headerlist = 'abc'
- self.assertEqual(inst.response_headerlist, 'abc')
- del inst.response_headerlist
- self.assertFalse(hasattr(inst, 'response_headerlist'))
-
- def test_response_status(self):
- inst = self._makeOne()
- self.assertFalse(hasattr(inst, 'response_status'))
- inst.response_status = 'abc'
- self.assertEqual(inst.response_status, 'abc')
- del inst.response_status
- self.assertFalse(hasattr(inst, 'response_status'))
-
- def test_response_charset(self):
- inst = self._makeOne()
- self.assertFalse(hasattr(inst, 'response_charset'))
- inst.response_charset = 'abc'
- self.assertEqual(inst.response_charset, 'abc')
- del inst.response_charset
- self.assertFalse(hasattr(inst, 'response_charset'))
-
- def test_response_cache_for(self):
- inst = self._makeOne()
- self.assertFalse(hasattr(inst, 'response_cache_for'))
- inst.response_cache_for = 'abc'
- self.assertEqual(inst.response_cache_for, 'abc')
- del inst.response_cache_for
- self.assertFalse(hasattr(inst, 'response_cache_for'))
-
class Test_route_request_iface(unittest.TestCase):
def _callFUT(self, name):
from pyramid.request import route_request_iface