]> granicus.if.org Git - python/commitdiff
Merged revisions 72100-72101 via svnmerge from
authorR. David Murray <rdmurray@bitdance.com>
Wed, 29 Apr 2009 14:54:29 +0000 (14:54 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Wed, 29 Apr 2009 14:54:29 +0000 (14:54 +0000)
svn+ssh://pythondev@svn.python.org/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.
........

Lib/aifc.py
Lib/test/Sine-1000Hz-300ms.aif [new file with mode: 0644]
Lib/test/test_aifc.py [new file with mode: 0644]
Lib/test/test_sundry.py
Misc/ACKS
Misc/NEWS

index f663dd67d2e7a1f149ab99753097757aff50dc93..8e4f864495d42f90e529f9b6ffcd8a2c0276adb2 100644 (file)
@@ -144,9 +144,6 @@ class Error(Exception):
 
 _AIFC_version = 0xA2805140L     # Version 1 of AIFF-C
 
-_skiplist = 'COMT', 'INST', 'MIDI', 'AESD', \
-      'APPL', 'NAME', 'AUTH', '(c) ', 'ANNO'
-
 def _read_long(file):
     try:
         return struct.unpack('>l', file.read(4))[0]
@@ -314,10 +311,6 @@ class Aifc_read:
                 self._version = _read_ulong(chunk)
             elif chunkname == 'MARK':
                 self._readmark(chunk)
-            elif chunkname in _skiplist:
-                pass
-            else:
-                raise Error, 'unrecognized chunk type '+chunk.chunkname
             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 (file)
index 0000000..bf08f5c
Binary files /dev/null and b/Lib/test/Sine-1000Hz-300ms.aif differ
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py
new file mode 100644 (file)
index 0000000..7e5b2e9
--- /dev/null
@@ -0,0 +1,54 @@
+from test.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)
+        self.assertEqual(f.getcomptype(), 'NONE')
+        self.assertEqual(f.getcompname(), 'not compressed')
+        self.assertEqual(f.getparams(), (2, 2, 48000, 14400, 'NONE', 'not compressed'))
+        f.close()
+
+    def test_read(self):
+        f = aifc.open(self.sndfilepath)
+        self.assertEqual(f.tell(), 0)
+        self.assertEqual(f.readframes(2), '\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
+        f.rewind()
+        pos0 = f.tell()
+        self.assertEqual(pos0, 0)
+        self.assertEqual(f.readframes(2), '\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
+        pos2 = f.tell()
+        self.assertEqual(pos2, 2)
+        self.assertEqual(f.readframes(2), '\x17t\x17t"\xad"\xad')
+        f.setpos(pos2)
+        self.assertEqual(f.readframes(2), '\x17t\x17t"\xad"\xad')
+        f.setpos(pos0)
+        self.assertEqual(f.readframes(2), '\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()
index e7499ae4b26f79d981ac54b47869bbeaac5fcd0a..3b91d656c2196f841027b6d8e3748adc8eacef06 100644 (file)
@@ -10,7 +10,6 @@ class TestUntestedModules(unittest.TestCase):
     def test_at_least_import_untested_modules(self):
         with warnings.catch_warnings():
             import CGIHTTPServer
-            import aifc
             import audiodev
             import bdb
             import cgitb
index 79b74671245301961123c36210ef957e85ee0fb7..4f25c56bf1e3042b6dd74a1b64b1f6333473c180 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -362,6 +362,7 @@ Tamito Kajiyama
 Peter van Kampen
 Jacob Kaplan-Moss
 Lou Kates
+Hiroaki Kawai
 Sebastien Keim
 Robert Kern
 Randall Kern
@@ -527,6 +528,7 @@ Randy Pausch
 Samuele Pedroni
 Marcel van der Peijl
 Steven Pemberton
+Santiago Peresón
 Mark Perrego
 Trevor Perrin
 Tim Peters
index 96fcc3cbff85a211b3ed2dff5e16b8f9d19f5946..132cea8fef4cfad11bce202016bd4313a0c06a17 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #2245: aifc now skips chunk types it doesn't recognize, per spec.
+
 - Issue #4305: ctypes should now build again on mipsel-linux-gnu
 
 - Issue #5853: calling a function of the mimetypes module from several threads