(original) (raw)

changeset: 74224:a9cdc3ff2b8e branch: 3.2 parent: 74222:f4a9c7cf98dd user: Sandro Tosi sandro.tosi@gmail.com date: Sun Jan 01 18:04:37 2012 +0100 files: Lib/aifc.py Lib/test/test_aifc.py description: Issue #13680: add lowecase compression type to write header; patch by Oleg Plakhotnyuk diff -r f4a9c7cf98dd -r a9cdc3ff2b8e Lib/aifc.py --- a/Lib/aifc.py Sun Jan 01 12:55:20 2012 +0100 +++ b/Lib/aifc.py Sun Jan 01 18:04:37 2012 +0100 @@ -716,18 +716,12 @@ def _ensure_header_written(self, datasize): if not self._nframeswritten: - if self._comptype in (b'ULAW', b'ALAW'): + if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): if not self._sampwidth: self._sampwidth = 2 if self._sampwidth != 2: raise Error('sample width must be 2 when compressing ' - 'with ulaw/ULAW or alaw/ALAW') - if self._comptype == b'G722': - if not self._sampwidth: - self._sampwidth = 2 - if self._sampwidth != 2: - raise Error('sample width must be 2 when compressing ' - 'with G7.22 (ADPCM)') + 'with ulaw/ULAW, alaw/ALAW or G7.22 (ADPCM)') if not self._nchannels: raise Error('# channels not specified') if not self._sampwidth: @@ -743,8 +737,6 @@ self._convert = self._lin2ulaw elif self._comptype in (b'alaw', b'ALAW'): self._convert = self._lin2alaw - else: - raise Error('unsupported compression type') def _write_header(self, initlength): if self._aifc and self._comptype != b'NONE': diff -r f4a9c7cf98dd -r a9cdc3ff2b8e Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py Sun Jan 01 12:55:20 2012 +0100 +++ b/Lib/test/test_aifc.py Sun Jan 01 18:04:37 2012 +0100 @@ -1,6 +1,7 @@ from test.support import findfile, run_unittest, TESTFN import unittest import os +import io import aifc @@ -109,6 +110,16 @@ f.close() self.assertEqual(testfile.closed, True) + def test_write_header_comptype_sampwidth(self): + for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): + fout = self.fout = aifc.open(io.BytesIO(), 'wb') + fout.setnchannels(1) + fout.setframerate(1) + fout.setcomptype(comptype, b'') + fout.close() + self.assertEqual(fout.getsampwidth(), 2) + fout.initfp(None) + def test_main(): run_unittest(AIFCTest) /sandro.tosi@gmail.com