summaryrefslogtreecommitdiff
path: root/Lib/importlib/util.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-05-13 13:45:09 -0400
committerBrett Cannon <brett@python.org>2012-05-13 13:45:09 -0400
commitb4f7654dd002623617cf74a490998cef364d4066 (patch)
tree2f97cd25d88dc782b53b781076b382be63e19fd4 /Lib/importlib/util.py
parent729156efcc732f1d2a002644f586388eb8e95504 (diff)
downloadcpython-b4f7654dd002623617cf74a490998cef364d4066.tar.gz
Add importlib.util.resolve_name().
Diffstat (limited to 'Lib/importlib/util.py')
-rw-r--r--Lib/importlib/util.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py
index 7b44fa1344..1316437102 100644
--- a/Lib/importlib/util.py
+++ b/Lib/importlib/util.py
@@ -3,3 +3,19 @@
from ._bootstrap import module_for_loader
from ._bootstrap import set_loader
from ._bootstrap import set_package
+from ._bootstrap import _resolve_name
+
+
+def resolve_name(name, package):
+ """Resolve a relative module name to an absolute one."""
+ if not name.startswith('.'):
+ return name
+ elif not package:
+ raise ValueError('{!r} is not a relative name '
+ '(no leading dot)'.format(name))
+ level = 0
+ for character in name:
+ if character != '.':
+ break
+ level += 1
+ return _resolve_name(name[level:], package, level)