mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Added optional second arg to what(), giving the data read from the file
(then f may be None).
This commit is contained in:
parent
56a733856e
commit
81749b0754
1 changed files with 13 additions and 7 deletions
|
@ -5,13 +5,19 @@
|
|||
# Recognize sound headers #
|
||||
#-------------------------#
|
||||
|
||||
def what(filename):
|
||||
f = open(filename, 'r')
|
||||
h = f.read(32)
|
||||
for tf in tests:
|
||||
res = tf(h, f)
|
||||
if res:
|
||||
return res
|
||||
def what(filename, h=None):
|
||||
if not h:
|
||||
f = open(filename, 'r')
|
||||
h = f.read(32)
|
||||
else:
|
||||
f = None
|
||||
try:
|
||||
for tf in tests:
|
||||
res = tf(h, f)
|
||||
if res:
|
||||
return res
|
||||
finally:
|
||||
if f: f.close()
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue