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

zopefoundation / zope.dottedname / 16248941268

09 Aug 2024 04:26PM UTC coverage: 100.0%. Remained the same
16248941268

push

github

web-flow
Update Python version support. (#14)

8 of 8 branches covered (100.0%)

Branch coverage included in aggregate %.

4 of 4 new or added lines in 1 file covered. (100.0%)

63 of 63 relevant lines covered (100.0%)

1.0 hits per line

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

100.0
/src/zope/dottedname/resolve.py
1
##############################################################################
2
#
3
# Copyright (c) 2004 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
"""Dotted name support
15
"""
16

17

18
def resolve(name, module=None):
1✔
19
    """Resolve ``name`` to a Python object via imports / attribute lookups.
20

21
    If ``module`` is None, ``name`` must be "absolute" (no leading dots).
22

23
    If ``module`` is not None, and ``name`` is "relative" (has leading dots),
24
    the object will be found by navigating relative to ``module``.
25

26
    Returns the object, if found.  If not, propagates the error.
27
    """
28
    name = name.split('.')
1✔
29
    if not name[0]:
1✔
30
        if module is None:
1✔
31
            raise ValueError("relative name without base module")
1✔
32
        module = module.split('.')
1✔
33
        name.pop(0)
1✔
34
        while not name[0]:
1✔
35
            module.pop()
1✔
36
            name.pop(0)
1✔
37
        name = module + name
1✔
38

39
    used = name.pop(0)
1✔
40
    found = __import__(used)
1✔
41
    for n in name:
1✔
42
        used += '.' + n
1✔
43
        try:
1✔
44
            found = getattr(found, n)
1✔
45
        except AttributeError:
1✔
46
            __import__(used)
1✔
47
            found = getattr(found, n)
1✔
48

49
    return found
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