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


Python ConfigurationMachine.provideFeature方法代码示例

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


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

示例1: load_zcml

# 需要导入模块: from zope.configuration.config import ConfigurationMachine [as 别名]
# 或者: from zope.configuration.config.ConfigurationMachine import provideFeature [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
开发者ID:jinty,项目名称:pyramid_zcml,代码行数:68,代码来源:__init__.py


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