本文整理汇总了Python中zope.configuration.xmlconfig.registerCommonDirectives函数的典型用法代码示例。如果您正苦于以下问题:Python registerCommonDirectives函数的具体用法?Python registerCommonDirectives怎么用?Python registerCommonDirectives使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了registerCommonDirectives函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:msiedlarek,项目名称:alpaca,代码行数:25,代码来源:registry.py
示例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)
开发者ID:zopefoundation,项目名称:zope.configuration,代码行数:35,代码来源:test_xmlconfig.py
示例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
开发者ID:thegeekinside,项目名称:pyramid,代码行数:7,代码来源:__init__.py
示例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()
开发者ID:collective,项目名称:transmogrifier,代码行数:35,代码来源:main.py
示例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)
开发者ID:zopefoundation,项目名称:zope.configuration,代码行数:35,代码来源:test_xmlconfig.py
示例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)
开发者ID:datakurre,项目名称:collective.transmogrifier,代码行数:59,代码来源:runner.py
示例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
开发者ID:avnik,项目名称:nanozope,代码行数:8,代码来源:bootstrap.py
示例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,))
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:8,代码来源:testlayer.py
示例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
开发者ID:plone,项目名称:plone.testing,代码行数:58,代码来源:zca.py
示例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')
开发者ID:Teekuningas,项目名称:transmogrifier,代码行数:9,代码来源:testing.py
示例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
开发者ID:NextThought,项目名称:nti.testing,代码行数:56,代码来源:base.py
示例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)
开发者ID:goschtl,项目名称:fernlehrgang,代码行数:10,代码来源:testing.py
示例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')
开发者ID:aregee,项目名称:Mailman,代码行数:10,代码来源:test_xmlconfig.py
示例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,))
开发者ID:infrae,项目名称:infrae.testing,代码行数:11,代码来源:layers.py
示例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
开发者ID:markramm,项目名称:pyramid,代码行数:12,代码来源:zcml.py
示例16: test_w_empty_xml
def test_w_empty_xml(self):
from io import StringIO
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
from zope.configuration.xmlconfig import ZopeSAXParseException
context = ConfigurationMachine()
registerCommonDirectives(context)
with self.assertRaises(ZopeSAXParseException) as exc:
self._callFUT(StringIO(), context)
self.assertEqual(str(exc.exception.evalue),
'<string>:1:0: no element found')
开发者ID:zopefoundation,项目名称:zope.configuration,代码行数:12,代码来源:test_xmlconfig.py
示例17: test_registry_actions_can_be_pickled_and_unpickled
def test_registry_actions_can_be_pickled_and_unpickled(self):
import repoze.lemonade.tests.fixtureapp as package
from zope.configuration import xmlconfig
from zope.configuration import config
context = config.ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
context.package = package
xmlconfig.include(context, 'configure.zcml', package)
context.execute_actions(clear=False)
actions = context.actions
import cPickle
dumped = cPickle.dumps(actions, -1)
new = cPickle.loads(dumped)
self.assertEqual(len(actions), len(new))
开发者ID:marchon,项目名称:repoze.lemonade,代码行数:14,代码来源:test_zcml.py
示例18: load_zcml
def load_zcml(*args):
"""We rely on grok to load the configuration for our modules, but we depend on some libraries which
have only zcml based configuration, thus we need to load only those we need."""
from zope.configuration.config import ConfigurationMachine
from zope.configuration import xmlconfig
context = ConfigurationMachine()
xmlconfig.registerCommonDirectives(context)
for i in args:
xmlconfig.include(context, "configure.zcml", context.resolve(i))
context.execute_actions()
开发者ID:carriercomm,项目名称:opennode-management,代码行数:14,代码来源:core.py
示例19: xmlconfig
def xmlconfig(s, config=config):
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
from zope.configuration.xmlconfig import string
context = ConfigurationMachine()
context.autocommit = True
context.registry = config.registry
context.route_prefix = None
context.actions = config.action_state.actions
registerCommonDirectives(context)
string(s, context=context, execute=False)
config.commit()
开发者ID:mmariani,项目名称:pyramid_skins,代码行数:15,代码来源:test_doctests.py
示例20: test_neither_file_nor_files_passed_already_seen
def test_neither_file_nor_files_passed_already_seen(self):
from zope.configuration import xmlconfig
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
from zope.configuration.tests import samplepackage
context = ConfigurationMachine()
registerCommonDirectives(context)
context.package = samplepackage
fqn = _packageFile(samplepackage, 'configure.zcml')
context._seen_files.add(fqn)
logger = LoggerStub()
with _Monkey(xmlconfig, logger=logger):
self._callFUT(context) #skips
self.assertEqual(len(logger.debugs), 0)
self.assertEqual(len(context.actions), 0)
开发者ID:zopefoundation,项目名称:zope.configuration,代码行数:15,代码来源:test_xmlconfig.py
注:本文中的zope.configuration.xmlconfig.registerCommonDirectives函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论