diff options
author | Guido van Rossum <guido@python.org> | 1996-07-30 16:26:42 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-07-30 16:26:42 (GMT) |
commit | 81749b0754f0799cb84beedd8b411544a2934c5f (patch) | |
tree | de535663c67c0c7dea26b018ccccbd77267e8db4 /Lib/imghdr.py | |
parent | 56a733856e4e06952c7d6cae1a7d85d7a870f922 (diff) | |
download | cpython-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.py | 20 |
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 |