Commit e23b2d06 authored by Serhiy Storchaka's avatar Serhiy Storchaka

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.
parent 5c01d99c
...@@ -414,6 +414,8 @@ class Au_write: ...@@ -414,6 +414,8 @@ class Au_write:
self._patchheader() self._patchheader()
def close(self): def close(self):
if self._file:
try:
self._ensure_header_written() self._ensure_header_written()
if self._nframeswritten != self._nframes or \ if self._nframeswritten != self._nframes or \
self._datalength != self._datawritten: self._datalength != self._datawritten:
...@@ -421,6 +423,7 @@ class Au_write: ...@@ -421,6 +423,7 @@ class Au_write:
self._file.flush() self._file.flush()
if self._opened and self._file: if self._opened and self._file:
self._file.close() self._file.close()
finally:
self._file = None self._file = None
# #
......
...@@ -436,10 +436,12 @@ class Wave_write: ...@@ -436,10 +436,12 @@ class Wave_write:
def close(self): def close(self):
if self._file: if self._file:
try:
self._ensure_header_written(0) self._ensure_header_written(0)
if self._datalength != self._datawritten: if self._datalength != self._datawritten:
self._patchheader() self._patchheader()
self._file.flush() self._file.flush()
finally:
self._file = None self._file = None
if self._i_opened_the_file: if self._i_opened_the_file:
self._i_opened_the_file.close() self._i_opened_the_file.close()
......
...@@ -76,6 +76,10 @@ Core and Builtins ...@@ -76,6 +76,10 @@ Core and Builtins
Library 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 - Issue #19131: The aifc module now correctly reads and writes sampwidth of
compressed streams. compressed streams.
......
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