[Python-checkins] r54394 - in python/trunk: Lib/wave.py Misc/NEWS

georg.brandl python-checkins at python.org
Thu Mar 15 08:41:34 CET 2007


Author: georg.brandl
Date: Thu Mar 15 08:41:30 2007
New Revision: 54394

Modified:
   python/trunk/Lib/wave.py
   python/trunk/Misc/NEWS
Log:
Patch #1681153: the wave module now closes a file object it opened if
initialization failed.


Modified: python/trunk/Lib/wave.py
==============================================================================
--- python/trunk/Lib/wave.py	(original)
+++ python/trunk/Lib/wave.py	Thu Mar 15 08:41:30 2007
@@ -159,7 +159,12 @@
             f = __builtin__.open(f, 'rb')
             self._i_opened_the_file = f
         # else, assume it is an open file object already
-        self.initfp(f)
+        try:
+            self.initfp(f)
+        except:
+            if self._i_opened_the_file:
+                f.close()
+            raise
 
     def __del__(self):
         self.close()
@@ -297,7 +302,12 @@
         if isinstance(f, basestring):
             f = __builtin__.open(f, 'wb')
             self._i_opened_the_file = f
-        self.initfp(f)
+        try:
+            self.initfp(f)
+        except:
+            if self._i_opened_the_file:
+                f.close()
+            raise
 
     def initfp(self, file):
         self._file = file

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Thu Mar 15 08:41:30 2007
@@ -173,6 +173,9 @@
 Library
 -------
 
+- Patch #1681153: the wave module now closes a file object it opened if
+  initialization failed.
+
 - Bug #767111: fix long-standing bug in urllib which caused an
   AttributeError instead of an IOError when the server's response didn't
   contain a valid HTTP status line.


More information about the Python-checkins mailing list