/usr/lib/python3/dist-packages/testfixtures/resolve.py is in python3-testfixtures 4.14.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # Copyright (c) 2008-2013 Simplistix Ltd
# See license.txt for license details.
from testfixtures import not_there
def resolve(dotted_name):
names = dotted_name.split('.')
used = names.pop(0)
found = __import__(used)
container = found
method = None
n = None
for n in names:
container = found
used += '.' + n
try:
found = found.__dict__[n]
method = 'a'
except (AttributeError, KeyError):
try:
found = getattr(found, n)
method = 'a' # pragma: no branch
except AttributeError:
try:
__import__(used)
except ImportError:
method = 'i'
try:
found = found[n] # pragma: no branch
except KeyError:
found = not_there # pragma: no branch
except TypeError:
try:
n = int(n)
except ValueError:
method = 'a'
found = not_there
else:
found = found[n] # pragma: no branch
else:
found = getattr(found, n)
method = 'a' # pragma: no branch
return container, method, n, found
|