summaryrefslogtreecommitdiffstats
path: root/Lib/ihooks.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-09-10 17:37:44 (GMT)
committerGuido van Rossum <guido@python.org>1996-09-10 17:37:44 (GMT)
commit2ea05098eb6e69288b6d78e31115d490b1362ef7 (patch)
treeb7689e20985ae563c1686fef93e04d5ca27895c8 /Lib/ihooks.py
parentbe0a8a6042482fa09519379b3c3ea062c0344d71 (diff)
downloadcpython-2ea05098eb6e69288b6d78e31115d490b1362ef7.zip
cpython-2ea05098eb6e69288b6d78e31115d490b1362ef7.tar.gz
cpython-2ea05098eb6e69288b6d78e31115d490b1362ef7.tar.bz2
close module file after loading
Diffstat (limited to 'Lib/ihooks.py')
-rw-r--r--Lib/ihooks.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/Lib/ihooks.py b/Lib/ihooks.py
index bdc48e1..3a7e4bf 100644
--- a/Lib/ihooks.py
+++ b/Lib/ihooks.py
@@ -133,16 +133,19 @@ class BasicModuleLoader(_Verbose):
def load_module(self, name, stuff):
file, filename, (suff, mode, type) = stuff
- if type == BUILTIN_MODULE:
- return imp.init_builtin(name)
- if type == FROZEN_MODULE:
- return imp.init_frozen(name)
- if type == C_EXTENSION:
- return imp.load_dynamic(name, filename, file)
- if type == PY_SOURCE:
- return imp.load_source(name, filename, file)
- if type == PY_COMPILED:
- return imp.load_compiled(name, filename, file)
+ try:
+ if type == BUILTIN_MODULE:
+ return imp.init_builtin(name)
+ if type == FROZEN_MODULE:
+ return imp.init_frozen(name)
+ if type == C_EXTENSION:
+ return imp.load_dynamic(name, filename, file)
+ if type == PY_SOURCE:
+ return imp.load_source(name, filename, file)
+ if type == PY_COMPILED:
+ return imp.load_compiled(name, filename, file)
+ finally:
+ if file: file.close()
raise ImportError, "Unrecognized module type (%s) for %s" % \
(`type`, name)