summaryrefslogtreecommitdiff
path: root/repoze
diff options
context:
space:
mode:
Diffstat (limited to 'repoze')
-rw-r--r--repoze/bfg/configuration.py14
-rw-r--r--repoze/bfg/tests/test_configuration.py14
2 files changed, 28 insertions, 0 deletions
diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py
index f9c70e02d..08fc0da0a 100644
--- a/repoze/bfg/configuration.py
+++ b/repoze/bfg/configuration.py
@@ -261,6 +261,19 @@ class Configurator(object):
self._set_authentication_policy(authentication)
self._set_authorization_policy(authorization)
+ def _fix_registry(self):
+ """ Fix up a ZCA component registry that is not a
+ repoze.bfg.registry.Registry by adding analogues of
+ ``has_listeners`` and ``notify`` through monkey-patching."""
+
+ if not hasattr(self.registry, 'notify'):
+ def notify(*events):
+ [ _ for _ in self.registry.subscribers(events, None) ]
+ self.registry.notify = notify
+
+ if not hasattr(self.registry, 'has_listeners'):
+ self.registry.has_listeners = True
+
# API
def setup_registry(self, settings=None, root_factory=None,
@@ -283,6 +296,7 @@ class Configurator(object):
security policies, renderers, and a debug logger using the
configurator's current registry, as per the descriptions in
the Configurator constructor."""
+ self._fix_registry()
self._set_settings(settings)
self._set_root_factory(root_factory)
if debug_logger is None:
diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py
index ba306f26b..db960e2e9 100644
--- a/repoze/bfg/tests/test_configuration.py
+++ b/repoze/bfg/tests/test_configuration.py
@@ -173,6 +173,20 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(config.registry.getUtility(IRendererFactory, 'yeah'),
renderer)
+ def test_setup_registry_fixed(self):
+ class DummyRegistry(object):
+ def subscribers(self, events, name):
+ self.events = events
+ return events
+ def registerUtility(self, impl, iface, name=None, info=None):
+ pass
+ reg = DummyRegistry()
+ config = self._makeOne(reg)
+ config.setup_registry()
+ self.assertEqual(reg.has_listeners, True)
+ self.assertEqual(reg.notify(1), None)
+ self.assertEqual(reg.events, (1,))
+
def test_setup_registry_custom_settings(self):
from repoze.bfg.registry import Registry
from repoze.bfg.interfaces import ISettings