diff options
-rw-r--r-- | Lib/sndhdr.py | 13 | ||||
-rw-r--r-- | Lib/test/test_sndhdr.py | 2 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 13 insertions, 6 deletions
diff --git a/Lib/sndhdr.py b/Lib/sndhdr.py index 0a2fa8d..240e507 100644 --- a/Lib/sndhdr.py +++ b/Lib/sndhdr.py @@ -137,14 +137,17 @@ tests.append(test_voc) def test_wav(h, f): + import wave # 'RIFF' <len> 'WAVE' 'fmt ' <len> if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ': return None - style = get_short_le(h[20:22]) - nchannels = get_short_le(h[22:24]) - rate = get_long_le(h[24:28]) - sample_bits = get_short_le(h[34:36]) - return 'wav', rate, nchannels, -1, sample_bits + f.seek(0) + try: + w = wave.openfp(f, 'r') + except (EOFError, wave.Error): + return None + return ('wav', w.getframerate(), w.getnchannels(), + w.getnframes(), 8*w.getsampwidth()) tests.append(test_wav) diff --git a/Lib/test/test_sndhdr.py b/Lib/test/test_sndhdr.py index 1004688..5e0abe0 100644 --- a/Lib/test/test_sndhdr.py +++ b/Lib/test/test_sndhdr.py @@ -12,7 +12,7 @@ class TestFormats(unittest.TestCase): ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)), ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)), ('sndhdr.voc', ('voc', 0, 1, -1, 8)), - ('sndhdr.wav', ('wav', 44100, 2, -1, 16)), + ('sndhdr.wav', ('wav', 44100, 2, 5, 16)), ): filename = findfile(filename, subdir="sndhdrdata") what = sndhdr.what(filename) @@ -746,6 +746,7 @@ Hugo Lopes Tavares Anne Lord Tom Loredo Justin Love +Ned Jackson Lovely Jason Lowe Tony Lownds Ray Loyzaga @@ -287,6 +287,9 @@ Core and Builtins Library ------- +- Issue #5024: sndhdr.whichhdr now returns the frame count for WAV files + rather than -1. + - Issue #17460: Remove the strict argument of HTTPConnection and removing the DeprecationWarning being issued from 3.2 onwards. |