当前位置: 首页>>代码示例>>Python>>正文


Python ConfigurationMachine.config_class方法代码示例

本文整理汇总了Python中zope.configuration.config.ConfigurationMachine.config_class方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationMachine.config_class方法的具体用法?Python ConfigurationMachine.config_class怎么用?Python ConfigurationMachine.config_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zope.configuration.config.ConfigurationMachine的用法示例。


在下文中一共展示了ConfigurationMachine.config_class方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: xmlconfig

# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import config_class [as 别名]
        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.config_class = type(config)
            context.autocommit = True
            context.registry = config.registry
            context.route_prefix = None
            context.actions = config.action_state.actions
            context.introspection = False

            registerCommonDirectives(context)

            string(s, context=context, execute=False)
            config.commit()
开发者ID:Pylons,项目名称:pyramid_skins,代码行数:19,代码来源:test_doctests.py

示例2: load_zcml

# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import config_class [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 = resolve_asset_spec(spec, self.package_name)
    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.package = package
    context.route_prefix = getattr(self, 'route_prefix', None)
    context.introspection = getattr(self, 'introspection', True)
    context.config_class = self.__class__
    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()

    self._ctx.actions.extend(context.actions)
    if self.autocommit:
        self.commit()

    return self.registry
开发者ID:Pylons,项目名称:pyramid_zcml,代码行数:66,代码来源:__init__.py


注:本文中的zope.configuration.config.ConfigurationMachine.config_class方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。