diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-12-14 18:34:33 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-12-14 18:34:33 (GMT) |
commit | d1a61dcc65a85639f273b31fd32267092db9a06e (patch) | |
tree | b1ae63e2903907297d33f0e1127e6d5573176093 /Lib/aifc.py | |
parent | a92cc91ee63ea5c21297e468fbea725c8f7542dd (diff) | |
download | cpython-d1a61dcc65a85639f273b31fd32267092db9a06e.zip cpython-d1a61dcc65a85639f273b31fd32267092db9a06e.tar.gz cpython-d1a61dcc65a85639f273b31fd32267092db9a06e.tar.bz2 |
Issue #19623: Fixed writing to unseekable files in the aifc module.
Fixed writing 'ulaw' (lower case) compressed AIFC files.
Diffstat (limited to 'Lib/aifc.py')
-rw-r--r-- | Lib/aifc.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py index d8b7fab..9ac710f 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -778,7 +778,7 @@ class Aifc_write: def _ensure_header_written(self, datasize): if not self._nframeswritten: - if self._comptype in ('ULAW', 'ALAW'): + if self._comptype in ('ULAW', 'ulaw', 'ALAW', 'alaw'): if not self._sampwidth: self._sampwidth = 2 if self._sampwidth != 2: @@ -844,7 +844,7 @@ class Aifc_write: if self._datalength & 1: self._datalength = self._datalength + 1 if self._aifc: - if self._comptype in ('ULAW', 'ALAW'): + if self._comptype in ('ULAW', 'ulaw', 'ALAW', 'alaw'): self._datalength = self._datalength // 2 if self._datalength & 1: self._datalength = self._datalength + 1 @@ -852,7 +852,10 @@ class Aifc_write: self._datalength = (self._datalength + 3) // 4 if self._datalength & 1: self._datalength = self._datalength + 1 - self._form_length_pos = self._file.tell() + try: + self._form_length_pos = self._file.tell() + except (AttributeError, IOError): + self._form_length_pos = None commlength = self._write_form_length(self._datalength) if self._aifc: self._file.write('AIFC') @@ -864,7 +867,8 @@ class Aifc_write: self._file.write('COMM') _write_ulong(self._file, commlength) _write_short(self._file, self._nchannels) - self._nframes_pos = self._file.tell() + if self._form_length_pos is not None: + self._nframes_pos = self._file.tell() _write_ulong(self._file, self._nframes) if self._comptype in ('ULAW', 'ulaw', 'ALAW', 'alaw', 'G722'): _write_short(self._file, 8) @@ -875,7 +879,8 @@ class Aifc_write: self._file.write(self._comptype) _write_string(self._file, self._compname) self._file.write('SSND') - self._ssnd_length_pos = self._file.tell() + if self._form_length_pos is not None: + self._ssnd_length_pos = self._file.tell() _write_ulong(self._file, self._datalength + 8) _write_ulong(self._file, 0) _write_ulong(self._file, 0) |