summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-03-11 06:09:56 +0000
committerZac Medico <zmedico@gentoo.org>2009-03-11 06:09:56 +0000
commitf3c15b765c02202c9a93ae15279a8f4e1c95a31d (patch)
tree10e79d4c51ddd8081bdf0be1a1389077af662249
parent75acf3c20983ff86f37af2b0573b1884780b976b (diff)
downloadportage-f3c15b765c02202c9a93ae15279a8f4e1c95a31d.tar.gz
portage-f3c15b765c02202c9a93ae15279a8f4e1c95a31d.tar.bz2
portage-f3c15b765c02202c9a93ae15279a8f4e1c95a31d.zip
Fix _LazyImportFrom to use the correct module name when registering and
unregistering. (trunk r12679) svn path=/main/branches/2.1.6/; revision=12939
-rw-r--r--pym/portage/proxy/lazyimport.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/pym/portage/proxy/lazyimport.py b/pym/portage/proxy/lazyimport.py
index cf0db77ce..954b29d74 100644
--- a/pym/portage/proxy/lazyimport.py
+++ b/pym/portage/proxy/lazyimport.py
@@ -65,7 +65,11 @@ class _LazyImport(ObjectProxy):
class _LazyImportFrom(_LazyImport):
- __slots__ = ()
+ __slots__ = ('_attr_name',)
+
+ def __init__(self, scope, name, attr_name, alias):
+ object.__setattr__(self, '_attr_name', attr_name)
+ _LazyImport.__init__(self, scope, alias, name)
def _get_target(self):
try:
@@ -73,10 +77,9 @@ class _LazyImportFrom(_LazyImport):
except AttributeError:
pass
name = object.__getattribute__(self, '_name')
- components = name.split('.')
- parent_name = '.'.join(components[:-1])
- __import__(parent_name)
- target = getattr(sys.modules[parent_name], components[-1])
+ attr_name = object.__getattribute__(self, '_attr_name')
+ __import__(name)
+ target = getattr(sys.modules[name], attr_name)
object.__setattr__(self, '_target', target)
object.__getattribute__(self, '_scope')[
object.__getattribute__(self, '_alias')] = target
@@ -138,14 +141,14 @@ def lazyimport(scope, *args):
alias = s.split('@', 1)
if len(alias) == 1:
alias = alias[0]
- orig = alias
+ attr_name = alias
else:
- orig, alias = alias
+ attr_name, alias = alias
if already_imported is not None:
try:
- scope[alias] = getattr(already_imported, orig)
+ scope[alias] = getattr(already_imported, attr_name)
except AttributeError:
- raise ImportError('cannot import name %s' % orig)
+ raise ImportError('cannot import name %s' % attr_name)
else:
- scope[alias] = _LazyImportFrom(scope, alias,
- name + '.' + orig)
+ scope[alias] = \
+ _LazyImportFrom(scope, name, attr_name, alias)