From 81749b0754f0799cb84beedd8b411544a2934c5f Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 30 Jul 1996 16:26:42 +0000 Subject: Added optional second arg to what(), giving the data read from the file (then f may be None). --- Lib/imghdr.py | 20 +++++++++++++------- 1 file 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 -- cgit v0.12