Commit 499d8213 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.  Second invocation of close() on sunau writer now has no effects.
The aifc module now accepts lower case of names of the 'ulaw' and 'alaw'
codecs.
parent 5b68d649
...@@ -486,7 +486,7 @@ class Aifc_read: ...@@ -486,7 +486,7 @@ class Aifc_read:
try: try:
import cl import cl
except ImportError: except ImportError:
if self._comptype == 'ULAW': if self._comptype in ('ULAW', 'ulaw'):
try: try:
import audioop import audioop
self._convert = self._ulaw2lin self._convert = self._ulaw2lin
...@@ -495,9 +495,9 @@ class Aifc_read: ...@@ -495,9 +495,9 @@ class Aifc_read:
except ImportError: except ImportError:
pass pass
raise Error, 'cannot read compressed AIFF-C files' raise Error, 'cannot read compressed AIFF-C files'
if self._comptype == 'ULAW': if self._comptype in ('ULAW', 'ulaw'):
scheme = cl.G711_ULAW scheme = cl.G711_ULAW
elif self._comptype == 'ALAW': elif self._comptype in ('ALAW', 'alaw'):
scheme = cl.G711_ALAW scheme = cl.G711_ALAW
else: else:
raise Error, 'unsupported compression type' raise Error, 'unsupported compression type'
...@@ -654,7 +654,7 @@ class Aifc_write: ...@@ -654,7 +654,7 @@ class Aifc_write:
def setcomptype(self, comptype, compname): def setcomptype(self, comptype, compname):
if self._nframeswritten: if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write' raise Error, 'cannot change parameters after starting to write'
if comptype not in ('NONE', 'ULAW', 'ALAW', 'G722'): if comptype not in ('NONE', 'ULAW', 'ulaw', 'ALAW', 'alaw', 'G722'):
raise Error, 'unsupported compression type' raise Error, 'unsupported compression type'
self._comptype = comptype self._comptype = comptype
self._compname = compname self._compname = compname
...@@ -674,7 +674,7 @@ class Aifc_write: ...@@ -674,7 +674,7 @@ class Aifc_write:
nchannels, sampwidth, framerate, nframes, comptype, compname = info nchannels, sampwidth, framerate, nframes, comptype, compname = info
if self._nframeswritten: if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write' raise Error, 'cannot change parameters after starting to write'
if comptype not in ('NONE', 'ULAW', 'ALAW', 'G722'): if comptype not in ('NONE', 'ULAW', 'ulaw', 'ALAW', 'alaw', 'G722'):
raise Error, 'unsupported compression type' raise Error, 'unsupported compression type'
self.setnchannels(nchannels) self.setnchannels(nchannels)
self.setsampwidth(sampwidth) self.setsampwidth(sampwidth)
...@@ -803,7 +803,7 @@ class Aifc_write: ...@@ -803,7 +803,7 @@ class Aifc_write:
try: try:
import cl import cl
except ImportError: except ImportError:
if self._comptype == 'ULAW': if self._comptype in ('ULAW', 'ulaw'):
try: try:
import audioop import audioop
self._convert = self._lin2ulaw self._convert = self._lin2ulaw
...@@ -811,9 +811,9 @@ class Aifc_write: ...@@ -811,9 +811,9 @@ class Aifc_write:
except ImportError: except ImportError:
pass pass
raise Error, 'cannot write compressed AIFF-C files' raise Error, 'cannot write compressed AIFF-C files'
if self._comptype == 'ULAW': if self._comptype in ('ULAW', 'ulaw'):
scheme = cl.G711_ULAW scheme = cl.G711_ULAW
elif self._comptype == 'ALAW': elif self._comptype in ('ALAW', 'alaw'):
scheme = cl.G711_ALAW scheme = cl.G711_ALAW
else: else:
raise Error, 'unsupported compression type' raise Error, 'unsupported compression type'
...@@ -866,7 +866,7 @@ class Aifc_write: ...@@ -866,7 +866,7 @@ class Aifc_write:
_write_short(self._file, self._nchannels) _write_short(self._file, self._nchannels)
self._nframes_pos = self._file.tell() self._nframes_pos = self._file.tell()
_write_ulong(self._file, self._nframes) _write_ulong(self._file, self._nframes)
if self._comptype in ('ULAW', 'ALAW', 'G722'): if self._comptype in ('ULAW', 'ulaw', 'ALAW', 'alaw', 'G722'):
_write_short(self._file, 8) _write_short(self._file, 8)
else: else:
_write_short(self._file, self._sampwidth * 8) _write_short(self._file, self._sampwidth * 8)
......
...@@ -406,12 +406,15 @@ class Au_write: ...@@ -406,12 +406,15 @@ class Au_write:
self._patchheader() self._patchheader()
def close(self): def close(self):
self._ensure_header_written() if self._file:
if self._nframeswritten != self._nframes or \ try:
self._datalength != self._datawritten: self._ensure_header_written()
self._patchheader() if self._nframeswritten != self._nframes or \
self._file.flush() self._datalength != self._datawritten:
self._file = None self._patchheader()
self._file.flush()
finally:
self._file = None
# #
# private methods # private methods
......
...@@ -436,11 +436,13 @@ class Wave_write: ...@@ -436,11 +436,13 @@ class Wave_write:
def close(self): def close(self):
if self._file: if self._file:
self._ensure_header_written(0) try:
if self._datalength != self._datawritten: self._ensure_header_written(0)
self._patchheader() if self._datalength != self._datawritten:
self._file.flush() self._patchheader()
self._file = None self._file.flush()
finally:
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()
self._i_opened_the_file = None self._i_opened_the_file = None
......
...@@ -32,6 +32,12 @@ Core and Builtins ...@@ -32,6 +32,12 @@ 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. Second invocation of close() on sunau writer now has no effects.
The aifc module now accepts lower case of names of the 'ulaw' and 'alaw'
codecs.
- 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