Kaydet (Commit) 6dc61b11 authored tarafından Guido van Rossum's avatar Guido van Rossum

Add try-finally to close the file after loading it in

ModuleLoader.load_module!  (Thanks to Daniel Larsson who complained
about this.)
üst 6af4abdb
...@@ -252,6 +252,7 @@ class ModuleLoader(BasicModuleLoader): ...@@ -252,6 +252,7 @@ class ModuleLoader(BasicModuleLoader):
def load_module(self, name, stuff): def load_module(self, name, stuff):
file, filename, (suff, mode, type) = stuff file, filename, (suff, mode, type) = stuff
try:
if type == BUILTIN_MODULE: if type == BUILTIN_MODULE:
return self.hooks.init_builtin(name) return self.hooks.init_builtin(name)
if type == FROZEN_MODULE: if type == FROZEN_MODULE:
...@@ -265,6 +266,8 @@ class ModuleLoader(BasicModuleLoader): ...@@ -265,6 +266,8 @@ class ModuleLoader(BasicModuleLoader):
else: else:
raise ImportError, "Unrecognized module type (%s) for %s" % \ raise ImportError, "Unrecognized module type (%s) for %s" % \
(`type`, name) (`type`, name)
finally:
if file: file.close()
m.__file__ = filename m.__file__ = filename
return m return m
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment