From 0dc26efaddf70c02cac7e84245666340f13abd29 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 16 Oct 2009 00:47:13 +0000 Subject: - Add ``zcml_configure`` to ``repoze.bfg.testing`` module API. This function populates a component registry from a ZCML file for testing purposes. --- repoze/bfg/configuration.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'repoze/bfg/configuration.py') diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py index 629a58047..7ea74853c 100644 --- a/repoze/bfg/configuration.py +++ b/repoze/bfg/configuration.py @@ -4,6 +4,9 @@ import threading import zope.component +from zope.configuration import xmlconfig +from zope.configuration.config import ConfigurationMachine + from zope.component import getGlobalSiteManager from zope.component import getSiteManager @@ -23,7 +26,6 @@ from repoze.bfg.settings import get_options from repoze.bfg.threadlocal import get_current_registry from repoze.bfg.threadlocal import manager from repoze.bfg.urldispatch import RoutesRootFactory -from repoze.bfg.zcml import zcml_configure def make_registry(root_factory, package=None, filename='configure.zcml', authentication_policy=None, authorization_policy=None, @@ -132,3 +134,17 @@ class DefaultRootFactory: # factory") in BFG 0.9.X and before self.__dict__.update(environ['bfg.routes.matchdict']) +def zcml_configure(name, package): + """ Given a ZCML filename as ``name`` and a Python package as + ``package`` which the filename should be relative to, load the + ZCML into the current ZCML registry. + + .. note:: This feature is new as of :mod:`repoze.bfg` 1.1. + """ + context = ConfigurationMachine() + xmlconfig.registerCommonDirectives(context) + context.package = package + xmlconfig.include(context, name, package) + context.execute_actions(clear=False) + return context.actions + -- cgit v1.2.3