• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / Zope / 3956162881

pending completion
3956162881

push

github

Michael Howitz
Update to deprecation warning free releases.

4401 of 7036 branches covered (62.55%)

Branch coverage included in aggregate %.

27161 of 31488 relevant lines covered (86.26%)

0.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.34
/src/Zope2/Startup/options.py
1
##############################################################################
2
#
3
# Copyright (c) 2003 Zope Foundation and Contributors.
4
# All Rights Reserved.
5
#
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14

15
import os
1✔
16
import xml.sax
1✔
17

18
from ZConfig.loader import ConfigLoader
1✔
19
from ZConfig.loader import SchemaLoader
1✔
20
from ZConfig.schema import SchemaParser
1✔
21

22

23
class ConditionalSchemaParser(SchemaParser):
1✔
24
    """
25
    A SchemaParser with support for conditionally executing import
26
    directives based on a Python import condition. This is similar to
27
    ZCML's condition="installed foo" support, shortened to condition="foo".
28
    """
29

30
    def start_import(self, attrs):
1✔
31
        load_import = True
1✔
32
        condition = attrs.get('condition', '').strip()
1✔
33
        if condition:
1✔
34
            try:
1✔
35
                __import__(condition)
1✔
36
            except ImportError:
37
                load_import = False
38

39
        if load_import:
1✔
40
            SchemaParser.start_import(self, attrs)
1✔
41

42

43
class ZopeWSGIOptions:
1✔
44
    """ZopeWSGIOptions parses a ZConfig schema and config file.
45
    """
46
    configfile = None
1✔
47
    confighandlers = None
1✔
48
    configroot = None
1✔
49
    schema = None
1✔
50
    schemadir = os.path.dirname(os.path.abspath(__file__))
1✔
51
    schemafile = 'wsgischema.xml'
1✔
52

53
    def __init__(self, configfile=None):
1✔
54
        self.configfile = configfile
1✔
55

56
    def load_schema(self):
1✔
57
        if self.schema is None:
1!
58
            # Load schema
59
            if self.schemadir is None:
1!
60
                self.schemadir = os.path.dirname(__file__)
×
61
            self.schemafile = os.path.join(self.schemadir, self.schemafile)
1✔
62
            self._conditional_load()
1✔
63

64
    def _conditional_load(self):
1✔
65
        loader = SchemaLoader()
1✔
66
        # loadURL
67
        url = loader.normalizeURL(self.schemafile)
1✔
68
        resource = loader.openResource(url)
1✔
69
        try:
1✔
70
            # load / parseResource without caching
71
            parser = ConditionalSchemaParser(loader, resource.url)
1✔
72
            xml.sax.parse(resource.file, parser)
1✔
73
            self.schema = parser._schema
1✔
74
        finally:
75
            resource.close()
1✔
76

77
    def load_configfile(self):
1✔
78
        loader = ConfigLoader(self.schema)
1✔
79
        self.configroot, self.confighandlers = loader.loadURL(
1✔
80
            self.configfile)
81

82
    def __call__(self):
1✔
83
        self.load_schema()
1✔
84
        self.load_configfile()
1✔
85
        return self
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc