Пример #1
0
def load_zcml(self, spec='configure.zcml', lock=threading.Lock()):
    """ 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)."""
    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]

    registry = self.registry
    self.manager.push({'registry':registry, 'request':None})
    context = self._ctx
    if context is None:
        context = self._ctx = self._make_context(self.autocommit)

    # 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 pass
    # execute=self.autocommit to xmlconfig.file below, which will cause
    # the actions implied by the ZCML that was parsed to be committed
    # right away once parsing is finished if autocommit is True.
    context = GroupingContextDecorator(context)
    context.autocommit = False 

    lock.acquire()
    try:
        context.package = package
        xmlconfig.file(filename, package, context=context,
                       execute=self.autocommit)
    finally:
        lock.release()
        self.manager.pop()

    return registry