]> granicus.if.org Git - python/commitdiff
Added optional second arg to what(), giving the data read from the file
authorGuido van Rossum <guido@python.org>
Tue, 30 Jul 1996 16:26:42 +0000 (16:26 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 30 Jul 1996 16:26:42 +0000 (16:26 +0000)
(then f may be None).

Lib/imghdr.py

index 62518b5f36c9b9400d75364483c1da9dd0650996..10cc08596ecfc5a4fcccc20f6d987c5487ac7e48 100644 (file)
@@ -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