mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Add an uninstall method to the ImportManager.
This is the accepted portion of patch #402498.
This commit is contained in:
parent
43935128a4
commit
76977bbcaf
1 changed files with 9 additions and 1 deletions
|
|
@ -28,12 +28,20 @@ class ImportManager:
|
||||||
if isinstance(namespace, _ModuleType):
|
if isinstance(namespace, _ModuleType):
|
||||||
namespace = vars(namespace)
|
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
|
namespace['__import__'] = self._import_hook
|
||||||
|
|
||||||
### fix this
|
### fix this
|
||||||
#namespace['reload'] = self._reload_hook
|
#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):
|
def add_suffix(self, suffix, importFunc):
|
||||||
assert callable(importFunc)
|
assert callable(importFunc)
|
||||||
self.fs_imp.add_suffix(suffix, importFunc)
|
self.fs_imp.add_suffix(suffix, importFunc)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue