示例#1
0
 def __new__(self, features=None):
     context = config.ConfigurationMachine()
     xmlconfig.registerCommonDirectives(context)
     for feature in (features or []):
         context.provideFeature(feature)
     interface.alsoProvides(context, ISparcPreparedConfigurationContext)
     return context
def _configure(self=None,
               set_up_packages=(),
               features=(),
               context=None,
               execute=True):
    if set_up_packages:
        if context is None:
            context = config.ConfigurationMachine()
            xmlconfig.registerCommonDirectives(context)
        for feature in features:
            context.provideFeature(feature)

        for i in set_up_packages:
            __traceback_info__ = (i, self, set_up_packages)
            if isinstance(i, tuple):
                filename = i[0]
                package = i[1]
            else:
                filename = 'configure.zcml'
                package = i

            if isinstance(package, six.string_types):
                package = dottedname.resolve(package)
            context = xmlconfig.file(filename,
                                     package=package,
                                     context=context,
                                     execute=execute)
    return context
示例#3
0
 def setUp(self):
     setHooks()
     context = config.ConfigurationMachine()
     xmlconfig.registerCommonDirectives(context)
     for feature in self.features:
         context.provideFeature(feature)
     self.context = self._load_zcml(context)
     provideHandler(events.append, (None, ))
示例#4
0
def evaluateCondition(expression):
    """Evaluate import condition.

    ``expression`` is a string of the form "verb arguments".

    Currently the supported verbs are 'have', 'not-have',
    'installed' and 'not-installed'.

    The 'have' verb takes one argument: the name of a feature.
    """
    try:
        import Zope2.App.zcml
        context = Zope2.App.zcml._context or config.ConfigurationMachine()
    except ImportError:
        context = config.ConfigurationMachine()

    handler = xmlconfig.ConfigurationHandler(context)
    return handler.evaluateCondition(expression)
示例#5
0
def zcml_strings(dir, domain="zope", site_zcml=None):
    """Retrieve all ZCML messages from `dir` that are in the `domain`.
    """
    from zope.configuration import xmlconfig, config

    # Load server-independent site config
    context = config.ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)
    context.provideFeature("devmode")
    context = xmlconfig.file(site_zcml, context=context, execute=False)

    return context.i18n_strings.get(domain, {})
示例#6
0
def file(name, package=None, context=None, execute=True):
    """Execute a zcml file
    """

    if context is None:
        context = config.ConfigurationMachine()
        registerCommonDirectives(context)
        context.package = package

    include(context, name, package)
    if execute:
        context.execute_actions()

    return context
示例#7
0
 def test_registry_actions_can_be_pickled_and_unpickled(self):
     import repoze.lemonade.tests.fixtureapp as package
     from zope.configuration import xmlconfig
     from zope.configuration import config
     context = config.ConfigurationMachine()
     xmlconfig.registerCommonDirectives(context)
     context.package = package
     xmlconfig.include(context, 'configure.zcml', package)
     context.execute_actions(clear=False)
     actions = context.actions
     import cPickle
     dumped = cPickle.dumps(actions, -1)
     new = cPickle.loads(dumped)
     self.assertEqual(len(actions), len(new))
示例#8
0
def string(s, context=None, name="<string>", execute=True):
    """Execute a zcml string
    """
    from StringIO import StringIO

    if context is None:
        context = config.ConfigurationMachine()
        registerCommonDirectives(context)

    f = StringIO(s)
    f.name = name
    processxmlfile(f, context)

    if execute:
        context.execute_actions()

    return context
示例#9
0
def zcmlconfigure(settings):
    """ configuration for ZCML. The path to site.zcml must be
        written in the ini-file and defined in the section
        'zcml' as 'path'.
    """

    parser = configparser.ConfigParser()
    parser.read(settings.file)
    zcmlpath = parser.get('zcml', 'path')

    # Hook up custom component architecture calls
    zope.component.hooks.setHooks()

    # Load server-independent site config
    context = zconfig.ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)
    context = xmlconfig.file(zcmlpath, context=context, execute=True)

    return context
示例#10
0
def configure(options):
    from zope.error.error import globalErrorReportingUtility
    globalErrorReportingUtility.copy_to_zlog = True

    from zope.security.management import newInteraction, endInteraction
    endInteraction()
    newInteraction(SystemConfigurationParticipation())
    zope.app.component.hooks.setHooks()

    from zope.configuration import xmlconfig, config
    context = config.ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)
    for feature in options.features:
        context.provideFeature(feature)
    with warnings.catch_warnings():
        # zope.app.security globalmodules.zcml declares security directives for
        # some modules deprecated in newer versions of Python.
        warnings.filterwarnings('ignore',
                                message='^the formatter module is deprecated')
        context = xmlconfig.string(options.site_definition, context=context)

    endInteraction()
示例#11
0
def zcml(source):
    context = config.ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)

    # Test directives
    config.defineSimpleDirective(context,
                                 "print",
                                 IPrint,
                                 print_,
                                 namespace="*")
    config.defineSimpleDirective(context,
                                 "lolcat",
                                 ILolCat,
                                 lolcat,
                                 namespace="*")

    source = '''\
<configure package="z3c.unconfigure.tests.fixtures">
%s
</configure>''' % source

    xmlconfig.string(source, context)
示例#12
0
def zcml_strings(path, domain="zope", site_zcml=None):
    """Retrieve all ZCML messages from `dir` that are in the `domain`.

    Note, the pot maker runs in a loop for each package and the maker collects
    only the given messages from such a package by the given path. This allows
    us to collect messages from eggs and external packages. This also prevents
    to collect the same message more then one time since we use the same zcml
    configuration for each package path.
    """
    from zope.configuration import xmlconfig, config

    # The context will return the domain as an 8-bit character string.
    if not isinstance(domain, bytes):
        domain = domain.encode('ascii')

    # Load server-independent site config
    context = config.ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)
    context.provideFeature("devmode")
    context = xmlconfig.file(site_zcml, context=context, execute=False)

    catalog = context.i18n_strings.get(domain, {})
    res = {}
    duplicated = []
    append = duplicated.append
    for msg, locations  in catalog.items():
        for filename, lineno in locations:
            # only collect locations based on the given path
            if filename.startswith(path):
                id = '%s-%s-%s' % (msg, filename, lineno)
                # skip duplicated entries
                if id not in duplicated:
                    append(id)
                    l = res.get(msg, [])
                    l.append((filename, lineno))
                    res[msg] = l
    return res
示例#13
0
def _clearContext():
    global _context
    _context = config.ConfigurationMachine()
    registerCommonDirectives(_context)
示例#14
0
def zcml(source):
    context = config.ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)
    xmlconfig.string(source, context)