Kaydet (Commit) 1a48b9dd authored tarafından R David Murray's avatar R David Murray

#5024: whichhdr now returns the frame count for WAV files.

Patch by Ned Jackson Lovely based on a suggestion by Robert Pyle.
üst 052ddb01
...@@ -137,14 +137,17 @@ tests.append(test_voc) ...@@ -137,14 +137,17 @@ tests.append(test_voc)
def test_wav(h, f): def test_wav(h, f):
import wave
# 'RIFF' <len> 'WAVE' 'fmt ' <len> # 'RIFF' <len> 'WAVE' 'fmt ' <len>
if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ': if not h.startswith(b'RIFF') or h[8:12] != b'WAVE' or h[12:16] != b'fmt ':
return None return None
style = get_short_le(h[20:22]) f.seek(0)
nchannels = get_short_le(h[22:24]) try:
rate = get_long_le(h[24:28]) w = wave.openfp(f, 'r')
sample_bits = get_short_le(h[34:36]) except (EOFError, wave.Error):
return 'wav', rate, nchannels, -1, sample_bits return None
return ('wav', w.getframerate(), w.getnchannels(),
w.getnframes(), 8*w.getsampwidth())
tests.append(test_wav) tests.append(test_wav)
......
...@@ -12,7 +12,7 @@ class TestFormats(unittest.TestCase): ...@@ -12,7 +12,7 @@ class TestFormats(unittest.TestCase):
('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)), ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)),
('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)), ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)),
('sndhdr.voc', ('voc', 0, 1, -1, 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") filename = findfile(filename, subdir="sndhdrdata")
what = sndhdr.what(filename) what = sndhdr.what(filename)
......
...@@ -746,6 +746,7 @@ Hugo Lopes Tavares ...@@ -746,6 +746,7 @@ Hugo Lopes Tavares
Anne Lord Anne Lord
Tom Loredo Tom Loredo
Justin Love Justin Love
Ned Jackson Lovely
Jason Lowe Jason Lowe
Tony Lownds Tony Lownds
Ray Loyzaga Ray Loyzaga
......
...@@ -287,6 +287,9 @@ Core and Builtins ...@@ -287,6 +287,9 @@ Core and Builtins
Library 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 - Issue #17460: Remove the strict argument of HTTPConnection and removing the
DeprecationWarning being issued from 3.2 onwards. DeprecationWarning being issued from 3.2 onwards.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment