summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2013-09-09 21:32:10 -0400
committerChris McDonough <chrism@plope.com>2013-09-09 21:32:10 -0400
commit27190e533abf642f6fd6698016c91fee35e663a0 (patch)
treeb46633ac0c3b9979df0d2de23b24ecd6691319e2
parent65fe0c9152027981c3b6011282ceb3d1062daa21 (diff)
downloadpyramid-27190e533abf642f6fd6698016c91fee35e663a0.tar.gz
pyramid-27190e533abf642f6fd6698016c91fee35e663a0.tar.bz2
pyramid-27190e533abf642f6fd6698016c91fee35e663a0.zip
rename _register_response_adapters method to add_default_response_adapters and change its implementation so it uses add_response_adapter instead of mutating registry directly
-rw-r--r--pyramid/config/__init__.py14
-rw-r--r--pyramid/config/adapters.py7
-rw-r--r--pyramid/tests/test_config/test_init.py8
3 files changed, 19 insertions, 10 deletions
diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py
index 870f8b84d..19c47cbd9 100644
--- a/pyramid/config/__init__.py
+++ b/pyramid/config/__init__.py
@@ -333,7 +333,6 @@ class Configurator(
self._fix_registry()
self._set_settings(settings)
- self._register_response_adapters()
if isinstance(debug_logger, string_types):
debug_logger = logging.getLogger(debug_logger)
@@ -343,6 +342,7 @@ class Configurator(
registry.registerUtility(debug_logger, IDebugLogger)
+ self.add_default_response_adapters()
self.add_default_renderers()
self.add_default_view_predicates()
self.add_default_route_predicates()
@@ -362,12 +362,12 @@ class Configurator(
self.commit()
- # self.commit() should not be called after this point because the
- # following registrations should be treated as analogues of methods
- # called by the user after configurator construction. Rationale:
- # user-supplied implementations should be preferred rather than
- # add-on author implementations with the help of automatic conflict
- # resolution.
+ # self.commit() should not be called within this method after this
+ # point because the following registrations should be treated as
+ # analogues of methods called by the user after configurator
+ # construction. Rationale: user-supplied implementations should be
+ # preferred rather than add-on author implementations with the help of
+ # automatic conflict resolution.
if authentication_policy and not authorization_policy:
authorization_policy = ACLAuthorizationPolicy() # default
diff --git a/pyramid/config/adapters.py b/pyramid/config/adapters.py
index 0a74e76b4..f6a652e3d 100644
--- a/pyramid/config/adapters.py
+++ b/pyramid/config/adapters.py
@@ -1,3 +1,5 @@
+from webob import Response as WebobResponse
+
from functools import update_wrapper
from zope.interface import Interface
@@ -193,10 +195,9 @@ class AdaptersConfiguratorMixin(object):
intr['type'] = type_or_iface
self.action(discriminator, register, introspectables=(intr,))
- def _register_response_adapters(self):
+ def add_default_response_adapters(self):
# cope with WebOb response objects that aren't decorated with IResponse
- from webob import Response as WebobResponse
- self.registry.registerSelfAdapter((WebobResponse,), IResponse)
+ self.add_response_adapter(None, WebobResponse)
@action_method
def add_traverser(self, adapter, iface=None):
diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py
index a0333b66d..d6dba17f6 100644
--- a/pyramid/tests/test_config/test_init.py
+++ b/pyramid/tests/test_config/test_init.py
@@ -227,6 +227,14 @@ class ConfiguratorTests(unittest.TestCase):
config = self._makeOne(introspection=False)
self.assertEqual(config.introspection, False)
+ def test_ctor_default_webob_response_adapter_registered(self):
+ from webob import Response as WebobResponse
+ response = WebobResponse()
+ from pyramid.interfaces import IResponse
+ config = self._makeOne(autocommit=True)
+ result = config.registry.queryAdapter(response, IResponse)
+ self.assertEqual(result, response)
+
def test_with_package_module(self):
from pyramid.tests.test_config import test_init
import pyramid.tests