From: <zy...@us...> - 2009-04-02 02:33:01
|
Revision: 6148 http://jython.svn.sourceforge.net/jython/?rev=6148&view=rev Author: zyasoft Date: 2009-04-02 02:32:59 +0000 (Thu, 02 Apr 2009) Log Message: ----------- Fixed #1283 by ensuring that all opens in pkgutil use finally to close. Modified Paths: -------------- trunk/jython/Lib/pkgutil.py Modified: trunk/jython/Lib/pkgutil.py =================================================================== --- trunk/jython/Lib/pkgutil.py 2009-04-01 13:54:58 UTC (rev 6147) +++ trunk/jython/Lib/pkgutil.py 2009-04-02 02:32:59 UTC (rev 6148) @@ -241,8 +241,12 @@ return mod def get_data(self, pathname): - return open(pathname, "rb").read() - + f = open(pathname, "rb") + try: + return f.read() + finally: + f.close() + def _reopen(self): if self.file and self.file.closed: mod_type = self.etc[2] @@ -293,8 +297,10 @@ elif mod_type==imp.PY_COMPILED: if os.path.exists(self.filename[:-1]): f = open(self.filename[:-1], 'rU') - self.source = f.read() - f.close() + try: + self.source = f.read() + finally: + f.close() elif mod_type==imp.PKG_DIRECTORY: self.source = self._get_delegate().get_source() return self.source @@ -538,11 +544,13 @@ sys.stderr.write("Can't open %s: %s\n" % (pkgfile, msg)) else: - for line in f: - line = line.rstrip('\n') - if not line or line.startswith('#'): - continue - path.append(line) # Don't check for existence! - f.close() + try: + for line in f: + line = line.rstrip('\n') + if not line or line.startswith('#'): + continue + path.append(line) # Don't check for existence! + finally: + f.close() return path This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |