diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2011-10-01 20:49:36 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-27 13:27:51 +0000 |
commit | 921ced43c48c1d170452a7b251b94cc96ec8dd44 (patch) | |
tree | 3c4a89176ea67fe4c7bf7b375488361a823c95fa /mercurial/demandimport.py | |
parent | 9039c805b0a7e36220101323f82735f08a104b37 (diff) | |
download | mercurial-tarball-921ced43c48c1d170452a7b251b94cc96ec8dd44.tar.gz |
Imported from /srv/lorry/lorry-area/mercurial-tarball/mercurial-1.9.3.tar.gz.HEADmercurial-1.9.3master
Diffstat (limited to 'mercurial/demandimport.py')
-rw-r--r-- | mercurial/demandimport.py | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/mercurial/demandimport.py b/mercurial/demandimport.py index e439487..4f5d71e 100644 --- a/mercurial/demandimport.py +++ b/mercurial/demandimport.py @@ -27,17 +27,6 @@ These imports will not be delayed: import __builtin__ _origimport = __import__ -nothing = object() - -try: - _origimport(__builtin__.__name__, {}, {}, None, -1) -except TypeError: # no level argument - def _import(name, globals, locals, fromlist, level): - "call _origimport with no level argument" - return _origimport(name, globals, locals, fromlist) -else: - _import = _origimport - class _demandmod(object): """module demand-loader and proxy""" def __init__(self, name, globals, locals): @@ -61,7 +50,7 @@ class _demandmod(object): h, t = p, None if '.' in p: h, t = p.split('.', 1) - if getattr(mod, h, nothing) is nothing: + if not hasattr(mod, h): setattr(mod, h, _demandmod(p, mod.__dict__, mod.__dict__)) elif t: subload(getattr(mod, h), t) @@ -92,14 +81,20 @@ class _demandmod(object): def _demandimport(name, globals=None, locals=None, fromlist=None, level=-1): if not locals or name in ignore or fromlist == ('*',): # these cases we can't really delay - return _import(name, globals, locals, fromlist, level) + if level == -1: + return _origimport(name, globals, locals, fromlist) + else: + return _origimport(name, globals, locals, fromlist, level) elif not fromlist: # import a [as b] if '.' in name: # a.b base, rest = name.split('.', 1) # email.__init__ loading email.mime if globals and globals.get('__name__', None) == base: - return _import(name, globals, locals, fromlist, level) + if level != -1: + return _origimport(name, globals, locals, fromlist, level) + else: + return _origimport(name, globals, locals, fromlist) # if a is already demand-loaded, add b to its submodule list if base in locals: if isinstance(locals[base], _demandmod): @@ -114,12 +109,12 @@ def _demandimport(name, globals=None, locals=None, fromlist=None, level=-1): mod = _origimport(name, globals, locals) # recurse down the module chain for comp in name.split('.')[1:]: - if getattr(mod, comp, nothing) is nothing: + if not hasattr(mod, comp): setattr(mod, comp, _demandmod(comp, mod.__dict__, mod.__dict__)) mod = getattr(mod, comp) for x in fromlist: # set requested submodules for demand load - if getattr(mod, x, nothing) is nothing: + if not hasattr(mod, x): setattr(mod, x, _demandmod(x, mod.__dict__, locals)) return mod @@ -142,8 +137,6 @@ ignore = [ # raise ImportError if x not defined '__main__', '_ssl', # conditional imports in the stdlib, issue1964 - 'rfc822', - 'mimetools', ] def enable(): @@ -153,3 +146,4 @@ def enable(): def disable(): "disable global demand-loading of modules" __builtin__.__import__ = _origimport + |