comparison mercurial/demandimport.py @ 5929:e160f2312815

demandimport: handling new relative imports Mercurial does not work on python2.6 because __import__ takes an additional argument called level. This patch merely calls the built-in __import__ when level is passed.
author Ali Gholami Rudi <aligrudi@users.sourceforge.net>
date Wed, 16 Jan 2008 19:14:54 +0330
parents 7dd5cf9d1e09
children 25fc4c620e54
comparison
equal deleted inserted replaced
5928:3340aa5a64f7 5929:e160f2312815
75 return getattr(self._module, attr) 75 return getattr(self._module, attr)
76 def __setattr__(self, attr, val): 76 def __setattr__(self, attr, val):
77 self._load() 77 self._load()
78 setattr(self._module, attr, val) 78 setattr(self._module, attr, val)
79 79
80 def _demandimport(name, globals=None, locals=None, fromlist=None): 80 def _demandimport(name, globals=None, locals=None, fromlist=None, level=None):
81 if not locals or name in ignore or fromlist == ('*',): 81 if not locals or name in ignore or fromlist == ('*',):
82 # these cases we can't really delay 82 # these cases we can't really delay
83 return _origimport(name, globals, locals, fromlist) 83 return _origimport(name, globals, locals, fromlist)
84 elif not fromlist: 84 elif not fromlist:
85 # import a [as b] 85 # import a [as b]
93 if isinstance(locals[base], _demandmod): 93 if isinstance(locals[base], _demandmod):
94 locals[base]._extend(rest) 94 locals[base]._extend(rest)
95 return locals[base] 95 return locals[base]
96 return _demandmod(name, globals, locals) 96 return _demandmod(name, globals, locals)
97 else: 97 else:
98 if level is not None:
99 # from . import b,c,d or from .a import b,c,d
100 return _origimport(name, globals, locals, fromlist, level)
98 # from a import b,c,d 101 # from a import b,c,d
99 mod = _origimport(name, globals, locals) 102 mod = _origimport(name, globals, locals)
100 # recurse down the module chain 103 # recurse down the module chain
101 for comp in name.split('.')[1:]: 104 for comp in name.split('.')[1:]:
102 if not hasattr(mod, comp): 105 if not hasattr(mod, comp):