]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add an uninstall method to the ImportManager.
authorGreg Stein <gstein@lyra.org>
Sat, 7 Apr 2001 16:05:24 +0000 (16:05 +0000)
committerGreg Stein <gstein@lyra.org>
Sat, 7 Apr 2001 16:05:24 +0000 (16:05 +0000)
This is the accepted portion of patch #402498.

Lib/imputil.py

index 2f87d69be97e9224bf2755cf1c62c0bc15cfaf91..b245ec503509d448a6d9abb292c5f4a4362ec75b 100644 (file)
@@ -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)