summaryrefslogtreecommitdiffstats
path: root/Lib/imghdr.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-07-30 16:26:42 (GMT)
committerGuido van Rossum <guido@python.org>1996-07-30 16:26:42 (GMT)
commit81749b0754f0799cb84beedd8b411544a2934c5f (patch)
treede535663c67c0c7dea26b018ccccbd77267e8db4 /Lib/imghdr.py
parent56a733856e4e06952c7d6cae1a7d85d7a870f922 (diff)
downloadcpython-81749b0754f0799cb84beedd8b411544a2934c5f.zip
cpython-81749b0754f0799cb84beedd8b411544a2934c5f.tar.gz
cpython-81749b0754f0799cb84beedd8b411544a2934c5f.tar.bz2
Added optional second arg to what(), giving the data read from the file
(then f may be None).
Diffstat (limited to 'Lib/imghdr.py')
-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