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

zopefoundation / zope.configuration / 16248876899

06 Dec 2024 07:34AM UTC coverage: 99.857%. Remained the same
16248876899

push

github

icemac
Back to development: 6.1

350 of 356 branches covered (98.31%)

Branch coverage included in aggregate %.

3850 of 3850 relevant lines covered (100.0%)

1.0 hits per line

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

98.55
/src/zope/configuration/name.py
1
##############################################################################
2
#
3
# Copyright (c) 2001, 2002 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
Provide configuration object name resolution.
16

17
.. note:: This module is no longer used by `zope.configuration` and
18
   may be deprecated soon. Its functions are not documented.
19
"""
20

21
import os
1✔
22
from types import ModuleType
1✔
23

24

25
__all__ = [
1✔
26
    'resolve',
27
    'getNormalizedName',
28
    'path',
29
]
30

31

32
def resolve(name, package='zopeproducts', _silly=('__doc__',), _globals={}):
1✔
33
    name = name.strip()
1✔
34

35
    if name.startswith('.'):
1✔
36
        name = package + name
1✔
37

38
    if name.endswith('.') or name.endswith('+'):
1✔
39
        name = name[:-1]
1✔
40
        repeat = True
1✔
41
    else:
42
        repeat = False
1✔
43

44
    names = name.split('.')
1✔
45
    last = names[-1]
1✔
46
    mod = '.'.join(names[:-1])
1✔
47

48
    if not mod:
1✔
49
        return __import__(name, _globals, _globals, _silly)
1✔
50

51
    while True:
1✔
52
        m = __import__(mod, _globals, _globals, _silly)
1✔
53
        try:
1✔
54
            a = getattr(m, last)
1✔
55
        except AttributeError:
1✔
56
            if not repeat:
1!
57
                return __import__(name, _globals, _globals, _silly)
1✔
58

59
        else:
60
            if not repeat or (not isinstance(a, ModuleType)):
1✔
61
                return a
1✔
62
        mod += '.' + last
1✔
63

64

65
def getNormalizedName(name, package):
1✔
66
    name = name.strip()
1✔
67
    if name.startswith('.'):
1✔
68
        name = package + name
1✔
69

70
    if name.endswith('.') or name.endswith('+'):
1✔
71
        name = name[:-1]
1✔
72
        repeat = True
1✔
73
    else:
74
        repeat = False
1✔
75
    name = name.split(".")
1✔
76
    while len(name) > 1 and name[-1] == name[-2]:
1✔
77
        name.pop()
1✔
78
        repeat = 1
1✔
79
    name = ".".join(name)
1✔
80
    if repeat:
1✔
81
        name += "+"
1✔
82
    return name
1✔
83

84

85
def path(file='', package='zopeproducts', _silly=('__doc__',), _globals={}):
1✔
86
    # XXX WTF? why not look for abspath before importing?
87
    try:
1✔
88
        package = __import__(package, _globals, _globals, _silly)
1✔
89
    except ImportError:
90
        norm = os.path.normpath(file)
91
        if file and os.path.abspath(norm) == norm:
92
            # The package didn't matter
93
            return norm
94
        raise
95

96
    path = os.path.dirname(package.__file__)
1✔
97

98
    if file:
1✔
99
        path = os.path.join(path, file)
1✔
100

101
    return path
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