summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-07-24 21:23:50 -0400
committerChris McDonough <chrism@plope.com>2011-07-24 21:23:50 -0400
commit4588e5b3e303813d70a466bb64d31655ef295bda (patch)
tree4de965f4247df426d58fca7db61c6d2abeb8e0cf
parentf91e0c8bebe0d18c3e65850515b8b1cb7fdbd335 (diff)
downloadpyramid-4588e5b3e303813d70a466bb64d31655ef295bda.tar.gz
pyramid-4588e5b3e303813d70a466bb64d31655ef295bda.tar.bz2
pyramid-4588e5b3e303813d70a466bb64d31655ef295bda.zip
allow handler to be a dotted name
-rw-r--r--pyramid/config.py8
-rw-r--r--pyramid/tests/test_config.py12
2 files changed, 17 insertions, 3 deletions
diff --git a/pyramid/config.py b/pyramid/config.py
index cf6fb4182..46249d14e 100644
--- a/pyramid/config.py
+++ b/pyramid/config.py
@@ -901,9 +901,10 @@ class Configurator(object):
the server.
A request handler factory (passed as ``handler_factory``) must be a
- callable which accepts two arguments: ``handler`` and ``registry``.
- ``handler`` will be the request handler being wrapped. ``registry``
- will be the Pyramid :term:`application registry` represented by this
+ callable (or a :term:`Python dotted name` to a callable) which
+ accepts two arguments: ``handler`` and ``registry``. ``handler``
+ will be the request handler being wrapped. ``registry`` will be the
+ Pyramid :term:`application registry` represented by this
Configurator. A request handler factory must return a request
handler when it is called.
@@ -954,6 +955,7 @@ class Configurator(object):
.. note:: This feature is new as of Pyramid 1.1.1.
"""
+ handler_factory = self.maybe_dotted(handler_factory)
def register():
registry = self.registry
registry.registerUtility(handler_factory, IRequestHandlerFactory,
diff --git a/pyramid/tests/test_config.py b/pyramid/tests/test_config.py
index 57ec1c044..22dd878c5 100644
--- a/pyramid/tests/test_config.py
+++ b/pyramid/tests/test_config.py
@@ -616,6 +616,18 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(f1, factory1)
self.assertEqual(f2, factory2)
+ def test_add_request_handlers_dottednames(self):
+ import pyramid.tests
+ from pyramid.interfaces import IRequestHandlerFactories
+ from pyramid.interfaces import IRequestHandlerFactory
+ config = self._makeOne()
+ config.add_request_handler('pyramid.tests', 'name1')
+ config.commit()
+ names = config.registry.queryUtility(IRequestHandlerFactories)
+ self.assertEqual(names, ['name1'])
+ f1 = config.registry.getUtility(IRequestHandlerFactory, name='name1')
+ self.assertEqual(f1, pyramid.tests)
+
def test_add_request_handlers_names_overlap(self):
from pyramid.interfaces import IRequestHandlerFactories
from pyramid.interfaces import IRequestHandlerFactory