[Python-checkins] cpython (3.3): Issue #18919: If the close() method of a writer in the sunau or wave module
serhiy.storchaka
python-checkins at python.org
Sat Oct 12 20:38:53 CEST 2013
http://hg.python.org/cpython/rev/b7eae747385c
changeset: 86245:b7eae747385c
branch: 3.3
parent: 86242:a63af1c8e0b1
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sat Oct 12 21:36:10 2013 +0300
summary:
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.
files:
Lib/sunau.py | 19 +++++++++++--------
Lib/wave.py | 12 +++++++-----
Misc/NEWS | 4 ++++
3 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/Lib/sunau.py b/Lib/sunau.py
--- a/Lib/sunau.py
+++ b/Lib/sunau.py
@@ -414,14 +414,17 @@
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
diff --git a/Lib/wave.py b/Lib/wave.py
--- a/Lib/wave.py
+++ b/Lib/wave.py
@@ -436,11 +436,13 @@
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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -76,6 +76,10 @@
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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list