Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bdd5354

Browse files
committed
Issue #13680: add lowecase compression type to write header; patch by Oleg Plakhotnyuk
1 parent da785fd commit bdd5354

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

Lib/aifc.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -716,18 +716,12 @@ def _lin2adpcm(self, data):
716716

717717
def _ensure_header_written(self, datasize):
718718
if not self._nframeswritten:
719-
if self._comptype in (b'ULAW', b'ALAW'):
719+
if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
720720
if not self._sampwidth:
721721
self._sampwidth = 2
722722
if self._sampwidth != 2:
723723
raise Error('sample width must be 2 when compressing '
724-
'with ulaw/ULAW or alaw/ALAW')
725-
if self._comptype == b'G722':
726-
if not self._sampwidth:
727-
self._sampwidth = 2
728-
if self._sampwidth != 2:
729-
raise Error('sample width must be 2 when compressing '
730-
'with G7.22 (ADPCM)')
724+
'with ulaw/ULAW, alaw/ALAW or G7.22 (ADPCM)')
731725
if not self._nchannels:
732726
raise Error('# channels not specified')
733727
if not self._sampwidth:
@@ -743,8 +737,6 @@ def _init_compression(self):
743737
self._convert = self._lin2ulaw
744738
elif self._comptype in (b'alaw', b'ALAW'):
745739
self._convert = self._lin2alaw
746-
else:
747-
raise Error('unsupported compression type')
748740

749741
def _write_header(self, initlength):
750742
if self._aifc and self._comptype != b'NONE':

Lib/test/test_aifc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from test.support import findfile, run_unittest, TESTFN
22
import unittest
33
import os
4+
import io
45

56
import aifc
67

@@ -109,6 +110,16 @@ def __getattr__(self, attr): return getattr(self.file, attr)
109110
f.close()
110111
self.assertEqual(testfile.closed, True)
111112

113+
def test_write_header_comptype_sampwidth(self):
114+
for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
115+
fout = self.fout = aifc.open(io.BytesIO(), 'wb')
116+
fout.setnchannels(1)
117+
fout.setframerate(1)
118+
fout.setcomptype(comptype, b'')
119+
fout.close()
120+
self.assertEqual(fout.getsampwidth(), 2)
121+
fout.initfp(None)
122+
112123

113124
def test_main():
114125
run_unittest(AIFCTest)

0 commit comments

Comments
 (0)