[Python-checkins] CVS: python/dist/src/Lib imputil.py,1.18,1.19
Greg Stein
gstein@users.sourceforge.net
Sat, 07 Apr 2001 09:05:26 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv21285
Modified Files:
imputil.py
Log Message:
Add an uninstall method to the ImportManager.
This is the accepted portion of patch #402498.
Index: imputil.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/imputil.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** imputil.py 2001/02/12 09:17:06 1.18
--- imputil.py 2001/04/07 16:05:24 1.19
***************
*** 29,37 ****
namespace = vars(namespace)
! ### Note that we have no notion of "uninstall" or "chaining"
namespace['__import__'] = self._import_hook
### fix this
#namespace['reload'] = self._reload_hook
def add_suffix(self, suffix, importFunc):
--- 29,45 ----
namespace = vars(namespace)
! # 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):