コード例 #1
0
ファイル: test_doctests.py プロジェクト: Pylons/pyramid_skins
        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()
コード例 #2
0
        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()
コード例 #3
0
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.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
コード例 #4
0
ファイル: __init__.py プロジェクト: Pylons/pyramid_zcml
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