]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #18919: If the close() method of a writer in the sunau or wave module
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 12 Oct 2013 18:36:10 +0000 (21:36 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 12 Oct 2013 18:36:10 +0000 (21:36 +0300)
failed, second invocation of close() and destructor no more raise an
exception.

Lib/sunau.py
Lib/wave.py
Misc/NEWS

index 5212370588ef4181e0fa11a3863b82993c240177..15f7b0354b22645fbada5cf3856532e92b2c7781 100644 (file)
@@ -414,14 +414,17 @@ class Au_write:
             self._patchheader()
 
     def close(self):
-        self._ensure_header_written()
-        if self._nframeswritten != self._nframes or \
-                  self._datalength != self._datawritten:
-            self._patchheader()
-        self._file.flush()
-        if self._opened and self._file:
-            self._file.close()
-        self._file = None
+        if self._file:
+            try:
+                self._ensure_header_written()
+                if self._nframeswritten != self._nframes or \
+                        self._datalength != self._datawritten:
+                    self._patchheader()
+                self._file.flush()
+                if self._opened and self._file:
+                    self._file.close()
+            finally:
+                self._file = None
 
     #
     # private methods
index 54f030267a835fc9dfbb4aebea3ce9bdf3666d9c..2c386a5dff9c4094ba893de85081609c56fcce1f 100644 (file)
@@ -436,11 +436,13 @@ class Wave_write:
 
     def close(self):
         if self._file:
-            self._ensure_header_written(0)
-            if self._datalength != self._datawritten:
-                self._patchheader()
-            self._file.flush()
-            self._file = None
+            try:
+                self._ensure_header_written(0)
+                if self._datalength != self._datawritten:
+                    self._patchheader()
+                self._file.flush()
+            finally:
+                self._file = None
         if self._i_opened_the_file:
             self._i_opened_the_file.close()
             self._i_opened_the_file = None
index 08ebbbd987d08e1394ca9b52333eacb44109dfb5..c1c9eaa1d36c800d2090d3b63207f49ece380b00 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -76,6 +76,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #18919: If the close() method of a writer in the sunau or wave module
+  failed, second invocation of close() and destructor no more raise an
+  exception.
+
 - Issue #19131: The aifc module now correctly reads and writes sampwidth of
   compressed streams.