From 4588e5b3e303813d70a466bb64d31655ef295bda Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 24 Jul 2011 21:23:50 -0400 Subject: allow handler to be a dotted name --- pyramid/config.py | 8 +++++--- pyramid/tests/test_config.py | 12 ++++++++++++ 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 -- cgit v1.2.3