ยปCore Development>Code coverage>Lib/sunaudio.py

Python code coverage for Lib/sunaudio.py

#countcontent
11"""Interpret sun audio headers."""
21from warnings import warnpy3k
31warnpy3k("the sunaudio module has been removed in Python 3.0; "
41 "use the sunau module instead", stacklevel=2)
51del warnpy3k
6n/a
7n/a
81MAGIC = '.snd'
9n/a
102class error(Exception):
111 pass
12n/a
13n/a
141def get_long_be(s):
15n/a """Convert a 4-char value to integer."""
160 return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3])
17n/a
18n/a
191def gethdr(fp):
20n/a """Read a sound header from an open file."""
210 if fp.read(4) != MAGIC:
220 raise error, 'gethdr: bad magic word'
230 hdr_size = get_long_be(fp.read(4))
240 data_size = get_long_be(fp.read(4))
250 encoding = get_long_be(fp.read(4))
260 sample_rate = get_long_be(fp.read(4))
270 channels = get_long_be(fp.read(4))
280 excess = hdr_size - 24
290 if excess < 0:
300 raise error, 'gethdr: bad hdr_size'
310 if excess > 0:
320 info = fp.read(excess)
33n/a else:
340 info = ''
350 return (data_size, encoding, sample_rate, channels, info)
36n/a
37n/a
381def printhdr(file):
39n/a """Read and print the sound header of a named file."""
400 hdr = gethdr(open(file, 'r'))
410 data_size, encoding, sample_rate, channels, info = hdr
420 while info[-1:] == '\0':
430 info = info[:-1]
440 print 'File name: ', file
450 print 'Data size: ', data_size
460 print 'Encoding: ', encoding
470 print 'Sample rate:', sample_rate
480 print 'Channels: ', channels
490 print 'Info: ', repr(info)