Mercurial > cpython-lru_cache-weakref
diff Lib/importlib/_bootstrap.py @ 74935:81f3bb5efa40
Bring importlib in line w/ changes made in my personal bootstrap branch in the sandbox.
| author | Brett Cannon <brett@python.org> |
|---|---|
| date | Tue, 14 Feb 2012 18:38:11 -0500 |
| parents | 2857c4a3a26d |
| children | 03140936913c |
line wrap: on
line diff
--- a/Lib/importlib/_bootstrap.py Tue Feb 14 23:30:35 2012 +0100 +++ b/Lib/importlib/_bootstrap.py Tue Feb 14 18:38:11 2012 -0500 @@ -10,6 +10,7 @@ # Injected modules are '_warnings', 'imp', 'sys', 'marshal', '_io', # and '_os' (a.k.a. 'posix', 'nt' or 'os2'). # Injected attribute is path_sep. +# Most injection is handled by _setup(). # # When editing this code be aware that code executed at import time CANNOT # reference any injected objects! This includes not only global code but also @@ -999,7 +1000,7 @@ into the global namespace. As sys is needed for sys.modules access and imp is needed to load built-in - modules those two modules must be explicitly passed in. + modules, those two modules must be explicitly passed in. """ global imp, sys @@ -1035,3 +1036,16 @@ raise ImportError('importlib requires posix or nt') setattr(self_module, '_os', os_module) setattr(self_module, 'path_sep', path_sep) + + +def _install(sys_module, imp_module): + """Install importlib as the implementation of import. + + It is assumed that imp and sys have been imported and injected into the + global namespace for the module prior to calling this function. + + """ + _setup(sys_module, imp_module) + orig_import = builtins.__import__ + builtins.__import__ = __import__ + builtins.__original_import__ = orig_import
