mirror of https://github.com/python/cpython
merge with 3.2
This commit is contained in:
commit
35e0275e59
12
Lib/aifc.py
12
Lib/aifc.py
|
@ -716,18 +716,12 @@ class Aifc_write:
|
||||||
|
|
||||||
def _ensure_header_written(self, datasize):
|
def _ensure_header_written(self, datasize):
|
||||||
if not self._nframeswritten:
|
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:
|
if not self._sampwidth:
|
||||||
self._sampwidth = 2
|
self._sampwidth = 2
|
||||||
if self._sampwidth != 2:
|
if self._sampwidth != 2:
|
||||||
raise Error('sample width must be 2 when compressing '
|
raise Error('sample width must be 2 when compressing '
|
||||||
'with ulaw/ULAW or alaw/ALAW')
|
'with ulaw/ULAW, alaw/ALAW or G7.22 (ADPCM)')
|
||||||
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)')
|
|
||||||
if not self._nchannels:
|
if not self._nchannels:
|
||||||
raise Error('# channels not specified')
|
raise Error('# channels not specified')
|
||||||
if not self._sampwidth:
|
if not self._sampwidth:
|
||||||
|
@ -743,8 +737,6 @@ class Aifc_write:
|
||||||
self._convert = self._lin2ulaw
|
self._convert = self._lin2ulaw
|
||||||
elif self._comptype in (b'alaw', b'ALAW'):
|
elif self._comptype in (b'alaw', b'ALAW'):
|
||||||
self._convert = self._lin2alaw
|
self._convert = self._lin2alaw
|
||||||
else:
|
|
||||||
raise Error('unsupported compression type')
|
|
||||||
|
|
||||||
def _write_header(self, initlength):
|
def _write_header(self, initlength):
|
||||||
if self._aifc and self._comptype != b'NONE':
|
if self._aifc and self._comptype != b'NONE':
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from test.support import findfile, run_unittest, TESTFN
|
from test.support import findfile, run_unittest, TESTFN
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
import io
|
||||||
|
|
||||||
import aifc
|
import aifc
|
||||||
|
|
||||||
|
@ -109,6 +110,16 @@ class AIFCTest(unittest.TestCase):
|
||||||
f.close()
|
f.close()
|
||||||
self.assertEqual(testfile.closed, True)
|
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():
|
def test_main():
|
||||||
run_unittest(AIFCTest)
|
run_unittest(AIFCTest)
|
||||||
|
|
Loading…
Reference in New Issue