From 020aaf6134b042975e3f5fbebde070bb6263199d Mon Sep 17 00:00:00 2001 From: Greg Stein Date: Sat, 7 Apr 2001 16:05:24 +0000 Subject: Add an uninstall method to the ImportManager. This is the accepted portion of patch #402498. --- Lib/imputil.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Lib/imputil.py') 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) -- cgit v1.2.1