summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/imghdr.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/imghdr.py b/Lib/imghdr.py
index 62518b5..10cc085 100644
--- a/Lib/imghdr.py
+++ b/Lib/imghdr.py
@@ -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