From d0b398eeb8ce9e1b13b2c93674e220d804d2de2e Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 27 Nov 2009 04:46:05 +0000 Subject: - The ``repoze.bfg.testing.setUp`` function now accepts three extra optional keyword arguments: ``registry``, ``request`` and ``hook_zca``. If the ``registry`` argument is not ``None``, the argument will be treated as the registry that is set as the "current registry" (it will be returned by ``repoze.bfg.threadlocal.get_current_registry``) for the duration of the test. If the ``registry`` argument is ``None`` (the default), a new registry is created and used for the duration of the test. The value of the ``request`` argument is used as the "current request" (it will be returned by ``repoze.bfg.threadlocal.get_current_request``) for the duration of the test; it defaults to ``None``. If ``hook_zca`` is ``True`` (the default), the ``zope.component.getSiteManager`` function will be hooked with a function that returns the value of ``registry`` (or the default-created registry if ``registry`` is ``None``) instead of the registry returned by ``zope.component.getGlobalSiteManager``, causing the Zope Component Architecture API (``getSiteManager``, ``getAdapter``, ``getUtility``, and so on) to use the registry we're using for testing instead of the global ZCA registry. - The ``repoze.bfg.testing.tearDown`` function now accepts an ``unhook_zca`` argument. If this argument is ``True`` (the default), ``zope.component.getSiteManager.reset()`` will be called, causing the "base" registry to once again start returnining the result of ``zope.component.getSiteManager``. - Remove hook_zca and unhook_zca methods from Configurator. --- repoze/bfg/configuration.py | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) (limited to 'repoze/bfg/configuration.py') diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py index 02e402796..1dd41b0d1 100644 --- a/repoze/bfg/configuration.py +++ b/repoze/bfg/configuration.py @@ -103,11 +103,6 @@ class Configurator(object): application. If it is ``None``, a default root factory will be used. - If ``zcml_file`` is passed, it should be a filename relative to - the caller package, an absolute filename, or a :term:`resource - specification`. The file it refers to should contain - :term:`ZCML`. The ZCML represented in this file will be loaded. - If ``authentication_policy`` is passed, it should be an instance of an :term:`authentication policy`. @@ -253,33 +248,6 @@ class Configurator(object): # API - def hook_zca(self): - """ - If this method is called, the configurator will run - ``zope.component.getSiteManager.sethook( - repoze.bfg.threadlocals.get_current_registry)``. This causes - the ``zope.component.getSiteManager`` API to return the - :mod:`repoze.bfg` thread local registry. This has the effect - of causing ``zope.component`` thread local API functions such - as ``getUtility`` and ``getMultiAdapter`` to use the - :mod:`repoze.bfg` registry instead of the global Zope registry - during the scope of every :mod:`repoze.bfg` :term:`request`. - """ - from zope.component import getSiteManager - getSiteManager.sethook(get_current_registry) - - def unhook_zca(self): - """ - If this method is called, the configurator constructor will - run ``zope.component.getSiteManager.reset()``. This causes - the ``zope.component.getSiteManager`` API to return the - original registry assigned to it (usually the Zope global - registry), effectively undoing the work of the ``hook_zca`` - method. - """ - from zope.component import getSiteManager - getSiteManager.reset() - def add_subscriber(self, subscriber, iface=None): """ Add an event subscriber for the event stream implied by the supplied ``iface`` interface. The ``subscriber`` argument @@ -1023,12 +991,17 @@ def _accept_wrap(view, accept): return accept_view # note that ``options`` is a b/w compat alias for ``settings`` and -# ``Configurator`` is a testing dep inj +# ``Configurator`` and getSiteManager is a testing dep inj def make_app(root_factory, package=None, filename='configure.zcml', - settings=None, options=None, Configurator=Configurator): + settings=None, options=None, Configurator=Configurator, + getSiteManager=None): """ Return a Router object, representing a fully configured ``repoze.bfg`` WSGI application. + .. warning:: Use of this function is deprecated as of + :mod:`repoze.bfg` 1.2. You should instead use a + ``Configurator`` as shown in :ref:`configuration_narr`. + ``root_factory`` must be a callable that accepts a :term:`request` object and which returns a traversal root object. The traversal root returned by the root factory is the *default* traversal root; @@ -1065,7 +1038,9 @@ def make_app(root_factory, package=None, filename='configure.zcml', settings = settings or options or {} config = Configurator(package=package, settings=settings, root_factory=root_factory) - config.hook_zca() + if getSiteManager is None: + from zope.component import getSiteManager + getSiteManager.sethook(get_current_registry) zcml_file = settings.get('configure_zcml', filename) config.load_zcml(zcml_file) return config.make_wsgi_app() -- cgit v1.2.3