diff options
author | Guido van Rossum <guido@python.org> | 2007-08-21 22:49:52 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-21 22:49:52 (GMT) |
commit | 23cfc9845c9b0fdeb4759bd120cf6a465bf0af9e (patch) | |
tree | c667e0c8bd44497830063df70cdd06e2e9d0598f /Lib | |
parent | 003b09883ee3a710e85a68183861168c059ef773 (diff) | |
download | cpython-23cfc9845c9b0fdeb4759bd120cf6a465bf0af9e.zip cpython-23cfc9845c9b0fdeb4759bd120cf6a465bf0af9e.tar.gz cpython-23cfc9845c9b0fdeb4759bd120cf6a465bf0af9e.tar.bz2 |
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).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/sunaudio.py | 16 | ||||
-rw-r--r-- | Lib/test/test_ossaudiodev.py | 1 |
2 files changed, 11 insertions, 6 deletions
diff --git a/Lib/sunaudio.py b/Lib/sunaudio.py index 05bd867..ab4a8fa 100644 --- a/Lib/sunaudio.py +++ b/Lib/sunaudio.py @@ -1,14 +1,14 @@ """Interpret sun audio headers.""" -MAGIC = '.snd' +MAGIC = b'.snd' class error(Exception): pass def get_long_be(s): - """Convert a 4-char value to integer.""" - return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3]) + """Convert a 4-byte value to integer.""" + return (s[0]<<24) | (s[1]<<16) | (s[2]<<8) | s[3] def gethdr(fp): @@ -26,15 +26,19 @@ def gethdr(fp): if excess > 0: info = fp.read(excess) else: - info = '' + info = b'' return (data_size, encoding, sample_rate, channels, info) def printhdr(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 - while info[-1:] == '\0': + while info.endswith(b'\0'): info = info[:-1] print('File name: ', file) print('Data size: ', data_size) diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py index eb15e88..0cdc93c 100644 --- a/Lib/test/test_ossaudiodev.py +++ b/Lib/test/test_ossaudiodev.py @@ -170,6 +170,7 @@ def test_main(): errno.ENODEV, errno.EBUSY): raise TestSkipped(msg) raise + dsp.close() test_support.run_unittest(__name__) if __name__ == "__main__": |