diff options
| author | Michael Merickel <michael@merickel.org> | 2011-07-10 12:38:42 -0500 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2011-07-14 19:55:47 -0500 |
| commit | 68d12cd78c6406e21e2b861c3fcfd3b37f038953 (patch) | |
| tree | 411b27204ff6bbed099afd93fce477d7a6220ab1 | |
| parent | feb94163ea985addcc427173ffb13f4dad697525 (diff) | |
| download | pyramid-68d12cd78c6406e21e2b861c3fcfd3b37f038953.tar.gz pyramid-68d12cd78c6406e21e2b861c3fcfd3b37f038953.tar.bz2 pyramid-68d12cd78c6406e21e2b861c3fcfd3b37f038953.zip | |
Adding a global to track the last registry loaded by Pyramid.
| -rw-r--r-- | pyramid/config.py | 14 | ||||
| -rw-r--r-- | pyramid/tests/test_config.py | 6 |
2 files changed, 20 insertions, 0 deletions
diff --git a/pyramid/config.py b/pyramid/config.py index 44ce5110e..dff88b574 100644 --- a/pyramid/config.py +++ b/pyramid/config.py @@ -5,6 +5,7 @@ import sys import types import traceback import warnings +import weakref import venusian @@ -989,6 +990,14 @@ class Configurator(object): self.registry.notify(ApplicationCreated(app)) finally: self.manager.pop() + + # see the comments on p.config.last_registry to understand why + def cleanup_last_registry(ref): + global last_registry + last_registry = None + global last_registry + last_registry = weakref.ref(self.registry, cleanup_last_registry) + return app @action_method @@ -3318,3 +3327,8 @@ def isexception(o): (inspect.isclass(o) and (issubclass(o, Exception))) ) +# last_registry is a hack to keep track of the registry for the last Pyramid +# application created. This is useful to access the registry after the app +# itself has been wrapped in a WSGI stack, specifically for scripting +# purposes in pyramid.scripting. +last_registry = None diff --git a/pyramid/tests/test_config.py b/pyramid/tests/test_config.py index 002eab8e8..f49a693f0 100644 --- a/pyramid/tests/test_config.py +++ b/pyramid/tests/test_config.py @@ -672,6 +672,7 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(len(L), 1) def test_make_wsgi_app(self): + import pyramid.config from pyramid.router import Router from pyramid.interfaces import IApplicationCreated manager = DummyThreadLocalManager() @@ -683,9 +684,14 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(manager.pushed['registry'], config.registry) self.assertEqual(manager.pushed['request'], None) self.assertTrue(manager.popped) + self.assertEqual(pyramid.config.last_registry(), app.registry) self.assertEqual(len(subscriber), 1) self.assertTrue(IApplicationCreated.providedBy(subscriber[0])) + def test_uninitialized_last_registry(self): + import pyramid.config + self.assertEqual(pyramid.config.last_registry, None) + def test_include_with_dotted_name(self): from pyramid import tests config = self._makeOne() |
