2009-02-16 22:45:03 -04:00
|
|
|
"""Utility code for constructing importers, etc."""
|
2010-04-16 21:19:56 -03:00
|
|
|
|
2013-05-30 18:31:47 -03:00
|
|
|
from ._bootstrap import module_to_load
|
2009-02-16 22:45:03 -04:00
|
|
|
from ._bootstrap import module_for_loader
|
2009-03-10 02:17:37 -03:00
|
|
|
from ._bootstrap import set_loader
|
2009-03-04 12:07:00 -04:00
|
|
|
from ._bootstrap import set_package
|
2012-05-13 14:45:09 -03:00
|
|
|
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)
|