mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Convert sunaudio.py to bytes. (It has no unit test of its own!)
Fix test_ossaudiodev by closing the dsp properly (it can't be opened multiple times on my box).
This commit is contained in:
parent
003b09883e
commit
23cfc9845c
2 changed files with 11 additions and 6 deletions
|
|
@ -1,14 +1,14 @@
|
||||||
"""Interpret sun audio headers."""
|
"""Interpret sun audio headers."""
|
||||||
|
|
||||||
MAGIC = '.snd'
|
MAGIC = b'.snd'
|
||||||
|
|
||||||
class error(Exception):
|
class error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_long_be(s):
|
def get_long_be(s):
|
||||||
"""Convert a 4-char value to integer."""
|
"""Convert a 4-byte value to integer."""
|
||||||
return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3])
|
return (s[0]<<24) | (s[1]<<16) | (s[2]<<8) | s[3]
|
||||||
|
|
||||||
|
|
||||||
def gethdr(fp):
|
def gethdr(fp):
|
||||||
|
|
@ -26,15 +26,19 @@ def gethdr(fp):
|
||||||
if excess > 0:
|
if excess > 0:
|
||||||
info = fp.read(excess)
|
info = fp.read(excess)
|
||||||
else:
|
else:
|
||||||
info = ''
|
info = b''
|
||||||
return (data_size, encoding, sample_rate, channels, info)
|
return (data_size, encoding, sample_rate, channels, info)
|
||||||
|
|
||||||
|
|
||||||
def printhdr(file):
|
def printhdr(file):
|
||||||
"""Read and print the sound header of a named file."""
|
"""Read and print the sound header of a named file."""
|
||||||
hdr = gethdr(open(file, 'r'))
|
f = open(file, 'rb')
|
||||||
|
try:
|
||||||
|
hdr = gethdr(f)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
data_size, encoding, sample_rate, channels, info = hdr
|
data_size, encoding, sample_rate, channels, info = hdr
|
||||||
while info[-1:] == '\0':
|
while info.endswith(b'\0'):
|
||||||
info = info[:-1]
|
info = info[:-1]
|
||||||
print('File name: ', file)
|
print('File name: ', file)
|
||||||
print('Data size: ', data_size)
|
print('Data size: ', data_size)
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,7 @@ def test_main():
|
||||||
errno.ENODEV, errno.EBUSY):
|
errno.ENODEV, errno.EBUSY):
|
||||||
raise TestSkipped(msg)
|
raise TestSkipped(msg)
|
||||||
raise
|
raise
|
||||||
|
dsp.close()
|
||||||
test_support.run_unittest(__name__)
|
test_support.run_unittest(__name__)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue