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

Skip to content

Commit b507d2e

Browse files
committed
Merged revisions 72100-72101 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r72100 | r.david.murray | 2009-04-29 09:17:37 -0400 (Wed, 29 Apr 2009) | 7 lines Fix issue 2245. aifc now skips any chunk type it doesn't actually process instead of throwing errors for anything not in an explicit skip list. This is per this spec: http://www.cnpbagwell.com/aiff-c.txt. Spec reference and test sound file provided by Santiago Peresón, fix based on patch by Hiroaki Kawai. ........ r72101 | r.david.murray | 2009-04-29 09:51:44 -0400 (Wed, 29 Apr 2009) | 2 lines Now that we've got a test_aifc, add a few tests. ........
1 parent aa17a7f commit b507d2e

6 files changed

Lines changed: 63 additions & 9 deletions

File tree

Lib/aifc.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ class Error(Exception):
144144

145145
_AIFC_version = 0xA2805140 # Version 1 of AIFF-C
146146

147-
_skiplist = b'COMT', b'INST', b'MIDI', b'AESD', \
148-
b'APPL', b'NAME', b'AUTH', b'(c) ', b'ANNO'
149-
150147
def _read_long(file):
151148
try:
152149
return struct.unpack('>l', file.read(4))[0]
@@ -313,11 +310,6 @@ def initfp(self, file):
313310
self._version = _read_ulong(chunk)
314311
elif chunkname == b'MARK':
315312
self._readmark(chunk)
316-
elif chunkname in _skiplist:
317-
pass
318-
else:
319-
raise Error('unrecognized chunk type ' +
320-
chunkname.decode('latin1'))
321313
chunk.skip()
322314
if not self._comm_chunk_read or not self._ssnd_chunk:
323315
raise Error('COMM chunk and/or SSND chunk missing')

Lib/test/Sine-1000Hz-300ms.aif

60.3 KB
Binary file not shown.

Lib/test/test_aifc.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from test.support import findfile, run_unittest
2+
import unittest
3+
4+
import aifc
5+
6+
7+
class AIFCTest(unittest.TestCase):
8+
9+
def setUp(self):
10+
self.sndfilepath = findfile('Sine-1000Hz-300ms.aif')
11+
12+
def test_skipunknown(self):
13+
#Issue 2245
14+
#This file contains chunk types aifc doesn't recognize.
15+
f = aifc.open(self.sndfilepath)
16+
f.close()
17+
18+
def test_params(self):
19+
f = aifc.open(self.sndfilepath)
20+
self.assertEqual(f.getnchannels(), 2)
21+
self.assertEqual(f.getsampwidth(), 2)
22+
self.assertEqual(f.getframerate(), 48000)
23+
self.assertEqual(f.getnframes(), 14400)
24+
# XXX: are the next two correct? The docs say/imply they are supposed
25+
# to be strings.
26+
self.assertEqual(f.getcomptype(), b'NONE')
27+
self.assertEqual(f.getcompname(), b'not compressed')
28+
self.assertEqual(
29+
f.getparams(),
30+
(2, 2, 48000, 14400, b'NONE', b'not compressed'),
31+
)
32+
f.close()
33+
34+
def test_read(self):
35+
f = aifc.open(self.sndfilepath)
36+
self.assertEqual(f.tell(), 0)
37+
self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
38+
f.rewind()
39+
pos0 = f.tell()
40+
self.assertEqual(pos0, 0)
41+
self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
42+
pos2 = f.tell()
43+
self.assertEqual(pos2, 2)
44+
self.assertEqual(f.readframes(2), b'\x17t\x17t"\xad"\xad')
45+
f.setpos(pos2)
46+
self.assertEqual(f.readframes(2), b'\x17t\x17t"\xad"\xad')
47+
f.setpos(pos0)
48+
self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
49+
f.close()
50+
51+
#XXX Need more tests!
52+
53+
54+
def test_main():
55+
run_unittest(AIFCTest)
56+
57+
58+
if __name__ == "__main__":
59+
unittest.main()

Lib/test/test_sundry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class TestUntestedModules(unittest.TestCase):
99
def test_at_least_import_untested_modules(self):
1010
with warnings.catch_warnings():
1111
warnings.simplefilter("ignore")
12-
import aifc
1312
import bdb
1413
import cgitb
1514
import code

Misc/ACKS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ Tamito Kajiyama
372372
Peter van Kampen
373373
Jacob Kaplan-Moss
374374
Lou Kates
375+
Hiroaki Kawai
375376
Sebastien Keim
376377
Robert Kern
377378
Randall Kern
@@ -545,6 +546,7 @@ Randy Pausch
545546
Samuele Pedroni
546547
Marcel van der Peijl
547548
Steven Pemberton
549+
Santiago Peres�n
548550
Mark Perrego
549551
Trevor Perrin
550552
Tim Peters

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ Core and Builtins
473473
Library
474474
-------
475475

476+
- Issue #2245: aifc now skips chunk types it doesn't recognize, per spec.
477+
476478
- Issue #5874: distutils.tests.test_config_cmd is not locale-sensitive
477479
anymore.
478480

0 commit comments

Comments
 (0)