summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-13 14:48:36 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-13 14:48:36 (GMT)
commit6dc61b110fe9f5a30c6f37fab9e28c33fc6040cf (patch)
tree498973c5ce5f0ea1b0f07fb5249a1c93c9a8d371
parent6af4abdba0f9e5bd99fcf51503bd2f44b7dd8056 (diff)
downloadcpython-6dc61b110fe9f5a30c6f37fab9e28c33fc6040cf.zip
cpython-6dc61b110fe9f5a30c6f37fab9e28c33fc6040cf.tar.gz
cpython-6dc61b110fe9f5a30c6f37fab9e28c33fc6040cf.tar.bz2
Add try-finally to close the file after loading it in
ModuleLoader.load_module! (Thanks to Daniel Larsson who complained about this.)
-rw-r--r--Lib/ihooks.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/Lib/ihooks.py b/Lib/ihooks.py
index dfe29cf..8f64957 100644
--- a/Lib/ihooks.py
+++ b/Lib/ihooks.py
@@ -252,19 +252,22 @@ class ModuleLoader(BasicModuleLoader):
def load_module(self, name, stuff):
file, filename, (suff, mode, type) = stuff
- if type == BUILTIN_MODULE:
- return self.hooks.init_builtin(name)
- if type == FROZEN_MODULE:
- return self.hooks.init_frozen(name)
- if type == C_EXTENSION:
- m = self.hooks.load_dynamic(name, filename, file)
- elif type == PY_SOURCE:
- m = self.hooks.load_source(name, filename, file)
- elif type == PY_COMPILED:
- m = self.hooks.load_compiled(name, filename, file)
- else:
- raise ImportError, "Unrecognized module type (%s) for %s" % \
- (`type`, name)
+ try:
+ if type == BUILTIN_MODULE:
+ return self.hooks.init_builtin(name)
+ if type == FROZEN_MODULE:
+ return self.hooks.init_frozen(name)
+ if type == C_EXTENSION:
+ m = self.hooks.load_dynamic(name, filename, file)
+ elif type == PY_SOURCE:
+ m = self.hooks.load_source(name, filename, file)
+ elif type == PY_COMPILED:
+ m = self.hooks.load_compiled(name, filename, file)
+ else:
+ raise ImportError, "Unrecognized module type (%s) for %s" % \
+ (`type`, name)
+ finally:
+ if file: file.close()
m.__file__ = filename
return m