From b507d2e07d19692df25a07c82f6d96ff1e4b4313 Mon Sep 17 00:00:00 2001 From: "R. David Murray" Date: Wed, 29 Apr 2009 15:34:32 +0000 Subject: [PATCH] Merged revisions 72100-72101 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ........ 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. ........ --- Lib/aifc.py | 8 ----- Lib/test/Sine-1000Hz-300ms.aif | Bin 0 -> 61696 bytes Lib/test/test_aifc.py | 59 +++++++++++++++++++++++++++++++++ Lib/test/test_sundry.py | 1 - Misc/ACKS | 2 ++ Misc/NEWS | 2 ++ 6 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 Lib/test/Sine-1000Hz-300ms.aif create mode 100644 Lib/test/test_aifc.py diff --git a/Lib/aifc.py b/Lib/aifc.py index 26b0ff5b7a3..36312b3c2cb 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -144,9 +144,6 @@ class Error(Exception): _AIFC_version = 0xA2805140 # Version 1 of AIFF-C -_skiplist = b'COMT', b'INST', b'MIDI', b'AESD', \ - b'APPL', b'NAME', b'AUTH', b'(c) ', b'ANNO' - def _read_long(file): try: return struct.unpack('>l', file.read(4))[0] @@ -313,11 +310,6 @@ def initfp(self, file): self._version = _read_ulong(chunk) elif chunkname == b'MARK': self._readmark(chunk) - elif chunkname in _skiplist: - pass - else: - raise Error('unrecognized chunk type ' + - chunkname.decode('latin1')) chunk.skip() if not self._comm_chunk_read or not self._ssnd_chunk: raise Error('COMM chunk and/or SSND chunk missing') diff --git a/Lib/test/Sine-1000Hz-300ms.aif b/Lib/test/Sine-1000Hz-300ms.aif new file mode 100644 index 0000000000000000000000000000000000000000..bf08f5ce859429eeeab213fd29a201b0d851b9c3 GIT binary patch literal 61696 zcmeI&F-t;G6ae5$QxH_-;Ns*IlCzCQp$4VU8$`!`gF`emiG#nv&1lHMO=u9Bnj^xc zA!uj`8XOw)(9%Ds;dAhL-@EtvIOu!tp7YgOXQwHBejOawYKN`U)#tR6)>7K9rtRwH z-PNkSdeu%&&QjXC|7m#_0TB=Z5fA|p5CIVo0TB=Z5fA|p_}>x8vgT1ruj{|ha^q>^ zDc{TYij(4`+$y&!rAn!qtLEx&^|$6_^D>)dv-Y4p=qx&m?x;J8ZM0*59FKm{KgPxQ zm?!3odEahkL#!Vm;0~h2hVSwKRrKNzgT}+KU%-b zKggfRU&+78AIjg#Kg*x1U#P#RAF1D|KdPUqU#q|K1N;C#zz^^P`~W||5AXy006)MF z@B{n+Kfn+01N;C#zz^^P`~W||5AXy006)MF@B{n+Kfn+01N;C#zz^^P`~W||5AXy0 z06)MF@B{n+Kfn+01N;C#zz^^P`~W||5AXy006)MF@B{n+Kfn+01N;C#zz^^P`~W|| z5AXy006)MF@B{n+Kfn+01N;C#zz^^P`~W||5AXy006)MF@B{n+Kfn+01N;C#zz^^P z`~W||5AXy006)MF@B{n+Kfn+01N;C#zz^^P`~W||5AXy006)MF@B{n+Kfn+01N;C# zzz^^P`~W||5AXy006)MF@B{n+Kfn+01N;C#zz^^P`~W||5AXy006)MF@B{n+Kfn+0 z1N;C#zz^^P`~W||5AXy006)MF@B{n+Kfn+01N;C#zz^^P`~W||5AXy006)MF@B{q7 HU;BY?t&pq( literal 0 HcmV?d00001 diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py new file mode 100644 index 00000000000..fd411262207 --- /dev/null +++ b/Lib/test/test_aifc.py @@ -0,0 +1,59 @@ +from test.support import findfile, run_unittest +import unittest + +import aifc + + +class AIFCTest(unittest.TestCase): + + def setUp(self): + self.sndfilepath = findfile('Sine-1000Hz-300ms.aif') + + def test_skipunknown(self): + #Issue 2245 + #This file contains chunk types aifc doesn't recognize. + f = aifc.open(self.sndfilepath) + f.close() + + def test_params(self): + f = aifc.open(self.sndfilepath) + self.assertEqual(f.getnchannels(), 2) + self.assertEqual(f.getsampwidth(), 2) + self.assertEqual(f.getframerate(), 48000) + self.assertEqual(f.getnframes(), 14400) + # XXX: are the next two correct? The docs say/imply they are supposed + # to be strings. + self.assertEqual(f.getcomptype(), b'NONE') + self.assertEqual(f.getcompname(), b'not compressed') + self.assertEqual( + f.getparams(), + (2, 2, 48000, 14400, b'NONE', b'not compressed'), + ) + f.close() + + def test_read(self): + f = aifc.open(self.sndfilepath) + self.assertEqual(f.tell(), 0) + self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4') + f.rewind() + pos0 = f.tell() + self.assertEqual(pos0, 0) + self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4') + pos2 = f.tell() + self.assertEqual(pos2, 2) + self.assertEqual(f.readframes(2), b'\x17t\x17t"\xad"\xad') + f.setpos(pos2) + self.assertEqual(f.readframes(2), b'\x17t\x17t"\xad"\xad') + f.setpos(pos0) + self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4') + f.close() + + #XXX Need more tests! + + +def test_main(): + run_unittest(AIFCTest) + + +if __name__ == "__main__": + unittest.main() diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py index bba54fe5ed1..ee387c74548 100644 --- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -9,7 +9,6 @@ class TestUntestedModules(unittest.TestCase): def test_at_least_import_untested_modules(self): with warnings.catch_warnings(): warnings.simplefilter("ignore") - import aifc import bdb import cgitb import code diff --git a/Misc/ACKS b/Misc/ACKS index a4f848108ff..7eab407d2ed 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -372,6 +372,7 @@ Tamito Kajiyama Peter van Kampen Jacob Kaplan-Moss Lou Kates +Hiroaki Kawai Sebastien Keim Robert Kern Randall Kern @@ -545,6 +546,7 @@ Randy Pausch Samuele Pedroni Marcel van der Peijl Steven Pemberton +Santiago Peresón Mark Perrego Trevor Perrin Tim Peters diff --git a/Misc/NEWS b/Misc/NEWS index 54a3b093f80..bb4c134eac8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -473,6 +473,8 @@ Core and Builtins Library ------- +- Issue #2245: aifc now skips chunk types it doesn't recognize, per spec. + - Issue #5874: distutils.tests.test_config_cmd is not locale-sensitive anymore.