From 84d28b4ee5983bcb048323a0e56ea4c5498a0652 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 14 Dec 2013 20:35:04 +0200 Subject: Issue #19623: Fixed writing to unseekable files in the aifc module. --- Lib/aifc.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Lib/aifc.py') diff --git a/Lib/aifc.py b/Lib/aifc.py index 86a5edc8c9..db0924a2b7 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -771,7 +771,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, OSError): + self._form_length_pos = None commlength = self._write_form_length(self._datalength) if self._aifc: self._file.write(b'AIFC') @@ -783,7 +786,8 @@ class Aifc_write: self._file.write(b'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 (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): _write_short(self._file, 8) @@ -794,7 +798,8 @@ class Aifc_write: self._file.write(self._comptype) _write_string(self._file, self._compname) self._file.write(b'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) -- cgit v1.2.1