Chris McDonough
2013-09-10 27190e533abf642f6fd6698016c91fee35e663a0
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
3 files modified
29 ■■■■■ changed files
pyramid/config/__init__.py 14 ●●●● patch | view | raw | blame | history
pyramid/config/adapters.py 7 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_config/test_init.py 8 ●●●●● patch | view | raw | blame | history
pyramid/config/__init__.py
@@ -333,7 +333,6 @@
        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 @@
        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 @@
        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
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 @@
        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):
pyramid/tests/test_config/test_init.py
@@ -227,6 +227,14 @@
        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