summaryrefslogtreecommitdiff
path: root/Lib/imputil.py
diff options
context:
space:
mode:
authorGreg Stein <gstein@lyra.org>2001-04-07 16:05:24 +0000
committerGreg Stein <gstein@lyra.org>2001-04-07 16:05:24 +0000
commit76977bbcafd4dd5ac50eed1e8794a338d0fb5841 (patch)
treeb02dad7af19defa1ad294900a4d3be5d5686bffc /Lib/imputil.py
parent43935128a4791ab533212550f84b59f5b59649d4 (diff)
downloadcpython-git-76977bbcafd4dd5ac50eed1e8794a338d0fb5841.tar.gz
Add an uninstall method to the ImportManager.
This is the accepted portion of patch #402498.
Diffstat (limited to 'Lib/imputil.py')
-rw-r--r--Lib/imputil.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/imputil.py b/Lib/imputil.py
index 2f87d69be9..b245ec5035 100644
--- a/Lib/imputil.py
+++ b/Lib/imputil.py
@@ -28,12 +28,20 @@ class ImportManager:
if isinstance(namespace, _ModuleType):
namespace = vars(namespace)
- ### Note that we have no notion of "uninstall" or "chaining"
+ # Note: we have no notion of "chaining"
+ # Record the previous import hook, then install our own.
+ self.previous_importer = namespace['__import__']
+ self.namespace = namespace
namespace['__import__'] = self._import_hook
+
### fix this
#namespace['reload'] = self._reload_hook
+ def uninstall(self):
+ "Restore the previous import mechanism."
+ self.namespace['__import__'] = self.previous_importer
+
def add_suffix(self, suffix, importFunc):
assert callable(importFunc)
self.fs_imp.add_suffix(suffix, importFunc)