本文整理汇总了Python中zope.configuration.xmlconfig.registerCommonDirectives函数的典型用法代码示例。如果您正苦于以下问题:Python registerCommonDirectives函数的具体用法?Python registerCommonDirectives怎么用?Python registerCommonDirectives使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了registerCommonDirectives函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_zcml
def load_zcml(self, zcml_asset_specification):
def _get_site_manager(context=None):
return self
if ':' not in zcml_asset_specification:
import alpaca
config_package = alpaca
config_file = zcml_asset_specification
else:
package_name, config_file = zcml_asset_specification.split(':')
__import__(package_name)
config_package = sys.modules[package_name]
context = ConfigurationMachine()
context.package = config_package
xmlconfig.registerCommonDirectives(context)
xmlconfig.file(
config_file,
package=config_package,
context=context,
execute=False
)
getSiteManager.sethook(_get_site_manager)
try:
context.execute_actions()
finally:
getSiteManager.reset()
示例2: test_w_file_passed
def test_w_file_passed(self):
from zope.configuration import xmlconfig
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
from zope.configuration import tests
from zope.configuration.tests import simple
context = ConfigurationMachine()
registerCommonDirectives(context)
before_stack = context.stack[:]
context.package = tests
fqn = _packageFile(tests, 'simple.zcml')
logger = LoggerStub()
with _Monkey(xmlconfig, logger=logger):
self._callFUT(context, 'simple.zcml')
self.assertEqual(len(logger.debugs), 1)
self.assertEqual(logger.debugs[0], ('include %s', (fqn,), {}))
self.assertEqual(len(context.actions), 3)
action = context.actions[0]
self.assertEqual(action['callable'], simple.file_registry.append)
self.assertEqual(action['includepath'], (fqn,))
self.assertEqual(action['args'][0].path,
_packageFile(tests, 'simple.py'))
action = context.actions[1]
self.assertEqual(action['callable'], simple.file_registry.append)
self.assertEqual(action['includepath'], (fqn,))
self.assertEqual(action['args'][0].path,
_packageFile(tests, 'simple.zcml'))
action = context.actions[2]
self.assertEqual(action['callable'], simple.file_registry.append)
self.assertEqual(action['includepath'], (fqn,))
self.assertEqual(action['args'][0].path,
_packageFile(tests, '__init__.py'))
self.assertEqual(context.stack, before_stack)
self.assertEqual(len(context._seen_files), 1)
self.assertIn(fqn, context._seen_files)
示例3: _make_context
def _make_context(self, autocommit=False):
context = PyramidConfigurationMachine()
registerCommonDirectives(context)
context.registry = self.registry
context.autocommit = autocommit
context.route_prefix = self.route_prefix
return context
示例4: configure
def configure(arguments):
# Enable venuasianconfiguration
if HAS_VENUSIANCONFIGURATION:
import venusianconfiguration
venusianconfiguration.enable()
# BBB: Support Zope's global configuration context
if HAS_ZOPE:
try:
import Zope2.App.zcml
config = Zope2.App.zcml._context or ConfigurationMachine()
except (ImportError, AttributeError):
config = ConfigurationMachine()
else:
config = ConfigurationMachine()
# Parse and evaluate configuration and plugins
registerCommonDirectives(config)
import transmogrifier
xmlconfig.include(config, package=transmogrifier, file='meta.zcml')
xmlconfig.include(config, package=transmogrifier, file='configure.zcml')
# Resolve includes
for include in set(arguments.get('--include')):
package, filename = parse_include(include)
if package and filename:
package = importlib.import_module(package)
xmlconfig.include(config, package=package, file=filename)
elif package and HAS_VENUSIANCONFIGURATION:
# Support including single module in the current working directory
import venusianconfiguration
venusianconfiguration.venusianscan(package, config)
config.execute_actions()
示例5: test_w_files_passed_and_package
def test_w_files_passed_and_package(self):
from zope.configuration import xmlconfig
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
context = ConfigurationMachine()
registerCommonDirectives(context)
before_stack = context.stack[:]
fqn1 = _packageFile(samplepackage, 'baz1.zcml')
fqn2 = _packageFile(samplepackage, 'baz2.zcml')
fqn3 = _packageFile(samplepackage, 'baz3.zcml')
logger = LoggerStub()
with _Monkey(xmlconfig, logger=logger):
self._callFUT(context, package=samplepackage, files='baz*.zcml')
self.assertEqual(len(logger.debugs), 3)
self.assertEqual(logger.debugs[0], ('include %s', (fqn1,), {}))
self.assertEqual(logger.debugs[1], ('include %s', (fqn2,), {}))
self.assertEqual(logger.debugs[2], ('include %s', (fqn3,), {}))
self.assertEqual(len(context.actions), 2)
action = context.actions[0]
self.assertEqual(action['callable'], foo.data.append)
self.assertEqual(action['includepath'], (fqn2,))
self.assertIsInstance(action['args'][0], foo.stuff)
self.assertEqual(action['args'][0].args, (('x', (b'foo')), ('y', 2)))
action = context.actions[1]
self.assertEqual(action['callable'], foo.data.append)
self.assertEqual(action['includepath'], (fqn3,))
self.assertIsInstance(action['args'][0], foo.stuff)
self.assertEqual(action['args'][0].args, (('x', (b'foo')), ('y', 3)))
self.assertEqual(context.stack, before_stack)
self.assertEqual(len(context._seen_files), 3)
self.assertIn(fqn1, context._seen_files)
self.assertIn(fqn2, context._seen_files)
self.assertIn(fqn3, context._seen_files)
示例6: __main__
def __main__():
# Enable logging
logging.basicConfig(level=logging.INFO)
# Parse cli arguments
arguments = docopt(__doc__)
# Parse and evaluate configuration and plugins
config = ConfigurationMachine()
registerCommonDirectives(config)
xmlconfig.include(config, package=collective.transmogrifier,
file='meta.zcml')
xmlconfig.include(config, package=collective.transmogrifier,
file='configure.zcml')
config.execute_actions()
if arguments.get('--list'):
blueprints = dict(getUtilitiesFor(ISectionBlueprint))
pipelines = map(configuration_registry.getConfiguration,
configuration_registry.listConfigurationIds())
print """
Available blueprints
--------------------
{0:s}
Available pipelines
-------------------
{1:s}
""".format('\n'.join(sorted(blueprints.keys())),
'\n'.join(['{0:s}\n {1:s}: {2:s}'.format(
p['id'], p['title'], p['description'])
for p in pipelines]))
return
# Load optional overrides
overrides = {}
overrides_path = arguments.get('--overrides')
if overrides_path and not os.path.isabs(overrides_path):
overrides_path = os.path.join(os.getcwd(), overrides_path)
if overrides_path:
parser = ConfigParser.RawConfigParser()
parser.optionxform = str # case sensitive
with open(overrides_path) as fp:
parser.readfp(fp)
overrides.update(dict(((section, dict(parser.items(section)))
for section in parser.sections())))
# Initialize optional context
context_path = arguments.get('--context')
if context_path is None:
context = dict()
else:
context_module_path, context_class_name = context_path.rsplit('.', 1)
context_module = importlib.import_module(context_module_path)
context = getattr(context_module, context_class_name)()
# Transmogrify
for pipeline in arguments.get('<pipeline>'):
ITransmogrifier(context)(pipeline, **overrides)
示例7: load_configuration
def load_configuration(zcml, features=()):
logging.info('Loading configuration from %s' % zcml)
context = config.ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
for feature in features:
context.provideFeature(feature)
context = xmlconfig.file(zcml, context=context, execute=True)
return context
示例8: setUp
def setUp(self):
setHooks()
context = config.ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
for feature in self.features:
context.provideFeature(feature)
self.context = self._load_zcml(context)
provideHandler(events.append, (None,))
示例9: stackConfigurationContext
def stackConfigurationContext(context=None, name='not named'):
"""Return a new ``ConfigurationMachine`` configuration context that
is a clone of the passed-in context. If no context is passed in, a fresh
configuration context is returned.
"""
from copy import deepcopy
from zope.interface import Interface
from zope.interface.adapter import AdapterRegistry
from zope.configuration.xmlconfig import registerCommonDirectives
clone = NamedConfigurationMachine(name)
# Prime this so that the <meta:redefinePermission /> directive won't lose
# track of it across our stacked configuration machines
clone.permission_mapping = {}
if context is None:
registerCommonDirectives(clone)
logger.debug('New configuration context %s', clone)
return clone
# Copy over simple attributes
clone.info = deepcopy(context.info)
clone.i18n_strings = deepcopy(context.i18n_strings)
clone.package = deepcopy(context.package)
clone.basepath = deepcopy(context.basepath)
clone.includepath = deepcopy(context.includepath)
clone._seen_files = deepcopy(context._seen_files)
clone._features = deepcopy(context._features)
try:
clone.permission_mapping = deepcopy(context.permission_mapping)
except AttributeError:
pass
# Note: We don't copy ``stack`` or ``actions`` since these are used during
# ZCML file processing only
# Copy over documentation registry
clone._docRegistry = [tuple(list(entry))for entry in context._docRegistry]
# Copy over the directive registry
for key, registry in context._registry.items():
newRegistry = clone._registry.setdefault(key, AdapterRegistry())
for adapterRegistration in registry._adapters:
if adapterRegistration not in newRegistry._adapters:
for interface, info in adapterRegistration.items():
if Interface in info:
factory = info[Interface][u'']
newRegistry.register([interface], Interface, '',
factory)
logger.debug('Configuration context %s cloned from %s', clone, context)
return clone
示例10: testSetUp
def testSetUp(cls, test=None):
cls.context = ConfigurationMachine()
registerCommonDirectives(cls.context)
import transmogrifier
xmlconfig.file('meta.zcml', transmogrifier, context=cls.context)
xmlconfig.file('configure.zcml', transmogrifier, context=cls.context)
cls.tempdir = tempfile.mkdtemp('transmogrifierTestConfigs')
示例11: _configure
def _configure(self=None,
set_up_packages=(),
features=('devmode', 'testmode'),
context=None,
package=None):
features = set(features) if features is not None else set()
# This is normally created by a slug, but tests may not always
# load the slug
if os.getenv('DATASERVER_DIR_IS_BUILDOUT'): # pragma: no cover
features.add('in-buildout')
# zope.component.globalregistry conveniently adds
# a zope.testing.cleanup.CleanUp to reset the globalSiteManager
if context is None and (features or package):
context = config.ConfigurationMachine()
context.package = package
xmlconfig.registerCommonDirectives(context)
for feature in features:
context.provideFeature(feature)
if set_up_packages:
logger.debug("Configuring %s with features %s", set_up_packages, features)
for i in set_up_packages:
__traceback_info__ = (i, self)
if isinstance(i, tuple):
filename = i[0]
package = i[1]
else:
filename = 'configure.zcml'
package = i
if isinstance(package, six.string_types):
package = dottedname.resolve(package)
try:
context = xmlconfig.file(filename, package=package, context=context)
except IOError as e:
# Did we pass in a test module (__name__) and there is no
# configuration in that package? In that case, we want to
# configure the parent package for sure
module_path = getattr(package, '__file__', '')
if (module_path
and 'tests' in module_path
and os.path.join(os.path.dirname(module_path), filename) == e.filename):
parent_package_name = '.'.join(package.__name__.split('.')[:-2])
package = dottedname.resolve(parent_package_name)
context = xmlconfig.file(filename, package=package, context=context)
else: # pragma: no cover
raise
return context
示例12: setup_config
def setup_config(package, zcml_file):
zcml_file = os.path.join(os.path.dirname(package.__file__),
zcml_file)
setHooks()
context = config.ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
return xmlconfig.file(zcml_file,
package=package,
context=context, execute=True)
示例13: test_w_empty_xml
def test_w_empty_xml(self):
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
from zope.configuration.xmlconfig import ZopeSAXParseException
from zope.configuration._compat import StringIO
context = ConfigurationMachine()
registerCommonDirectives(context)
exc = self.assertRaises(ZopeSAXParseException,
self._callFUT, StringIO(), context)
self.assertEqual(str(exc._v), '<string>:1:0: no element found')
示例14: setUp
def setUp(self):
# Previous test layer might be buggy and have left things
# behind, so clear everything ourselves before doing setup
# (like ZopeLite)
layerCleanUp()
# Set up this test layer.
context = config.ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
self.context = self._load_zcml(context)
provideHandler(events.append, (None,))
示例15: zcml_configure
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.
"""
context = ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
context.package = package
xmlconfig.include(context, name, package)
context.execute_actions(clear=False) # the raison d'etre
return context.actions