本文整理汇总了Python中zope.configuration.config.ConfigurationMachine.package方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationMachine.package方法的具体用法?Python ConfigurationMachine.package怎么用?Python ConfigurationMachine.package使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zope.configuration.config.ConfigurationMachine
的用法示例。
在下文中一共展示了ConfigurationMachine.package方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_zcml
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
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
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
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: test_neither_file_nor_files_passed
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
def test_neither_file_nor_files_passed(self):
from zope.configuration.config import ConfigurationMachine
from zope.configuration.tests import samplepackage
context = ConfigurationMachine()
context.package = samplepackage
fqn = _packageFile(samplepackage, 'configure.zcml')
self._callFUT(context)
self.assertEqual(len(context.actions), 0)
self.assertEqual(len(context._seen_files), 1)
self.assertIn(fqn, context._seen_files)
示例4: zcml_configure
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
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
示例5: file
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
def file(name, package=None, context=None, execute=True):
"""Execute a zcml file
"""
if context is None:
context = ConfigurationMachine()
registerCommonDirectives(context)
context.package = package
include(context, name, package)
if execute:
context.execute_actions()
return context
示例6: test_neither_file_nor_files_passed_already_seen
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
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)
示例7: test_actions_have_parents_includepath
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
def test_actions_have_parents_includepath(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()
fqp = _packageFile(tests, 'configure.zcml')
registerCommonDirectives(context)
before_stack = context.stack[:]
context.package = tests
# dummy action, path from "previous" include
context.includepath = (fqp,)
def _callable():
raise AssertionError("should not be called")
context.actions.append({'discriminator': None,
'callable': _callable,
})
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), 4)
action = context.actions[0]
self.assertEqual(action['discriminator'], None)
self.assertEqual(action['callable'], _callable)
action = context.actions[1]
self.assertEqual(action['callable'], simple.file_registry.append)
self.assertEqual(action['includepath'], (fqp,))
self.assertEqual(action['args'][0].path,
_packageFile(tests, 'simple.py'))
action = context.actions[2]
self.assertEqual(action['callable'], simple.file_registry.append)
self.assertEqual(action['includepath'], (fqp,))
self.assertEqual(action['args'][0].path,
_packageFile(tests, 'simple.zcml'))
action = context.actions[3]
self.assertEqual(action['callable'], simple.file_registry.append)
self.assertEqual(action['includepath'], (fqp,))
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)
示例8: test_wo_execute_w_context
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
def test_wo_execute_w_context(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()
context.package = samplepackage
registerCommonDirectives(context)
file_name = path("samplepackage", "configure.zcml")
logger = LoggerStub()
with _Monkey(xmlconfig, logger=logger):
ret = self._callFUT('configure.zcml', context=context,
execute=False)
self.assertTrue(ret is context)
self.assertEqual(len(logger.debugs), 1)
self.assertEqual(logger.debugs[0], ('include %s', (file_name,), {}))
self.assertEqual(len(foo.data), 0)
self.assertEqual(len(context.actions), 1)
action = context.actions[0]
self.assertEqual(action['discriminator'],
(('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
示例9: register_path
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
def register_path(config, spec, discovery=False, indexes=[], request_type=None):
""" Add a skin path to the current configuration state.
If ``discovery`` is enabled, the path will automatically be
monitored for changes.
The ``indexes`` argument is an optional list of view registrations
with the provided names.
The ``request_type`` option decides the request type for which to
make the registration.
"""
package_name, path = resolve_asset_spec(spec)
if package_name is not None:
path = pkg_resources.resource_filename(package_name, path)
else:
path = caller_path(path)
if package_name is None: # absolute filename
package = config.package
else:
__import__(package_name)
package = sys.modules[package_name]
context = ConfigurationMachine()
context.registry = config.registry
context.autocommit = False
context.package = package
context.route_prefix = getattr(config, 'route_prefix', None)
directive = skins(context, path, discovery, request_type)
for index in indexes:
directive.view(config, index)
for action in directive():
config.action(*action)
示例10: load_zcml
# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import package [as 别名]
def load_zcml(self, spec='configure.zcml', lock=threading.Lock(), features=()):
""" Load configuration from a :term:`ZCML` file into the
current configuration state. The ``spec`` argument is an
absolute filename, a relative filename, or a :term:`asset
specification`, defaulting to ``configure.zcml`` (relative to
the package of the method's caller).
The ``features`` argument can be any iterable of strings. These are useful
for conditionally including or excluding parts of a :term:`ZCML` file.
"""
package_name, filename = self._split_spec(spec)
if package_name is None: # absolute filename
package = self.package
else:
__import__(package_name)
package = sys.modules[package_name]
# To avoid breaking people's expectations of how ZCML works, we
# cannot autocommit ZCML actions incrementally. If we commit actions
# incrementally, configuration outcome will be controlled purely by
# ZCML directive execution order, which isn't what anyone who uses
# ZCML expects. So we don't autocommit each ZCML directive action
# while parsing is happening, but we do make sure to commit right
# after parsing if autocommit it True.
context = ConfigurationMachine()
for feature in features:
context.provideFeature(feature)
context.registry = self.registry
context.autocommit = False
context.route_prefix = getattr(self, 'route_prefix', None)
context.package = package
registerCommonDirectives(context)
self.manager.push({'registry':self.registry, 'request':None})
lock.acquire()
try:
# old_action_state will be None for Pyramid 1.0 and 1.1, but
# not for 1.2
old_action_state = getattr(self.registry, 'action_state', None)
if old_action_state is not None:
# For Pyramid 1.2+, we need to assign a temporary action state to
# the registry, because the configurator actions must populate
# the context's action list (instead of the registry action
# state's action list) in order for includeOverrides to work
# properly.
from pyramid.config import ActionState
self.registry.action_state = ActionState()
self.registry.action_state.actions = context.actions
xmlconfig.file(filename, package, context=context,
execute=False)
finally:
if old_action_state is not None:
# if we reassigned the action state, restore the old one (1.2 only)
self.registry.action_state = old_action_state
lock.release()
self.manager.pop()
_ctx = self._ctx
if _ctx is None: # pragma: no cover ; will never be true under 1.2a5+
_ctx = self._ctx = self._make_context(self.autocommit)
_ctx.actions.extend(context.actions)
if self.autocommit:
self.commit()
return self.registry