From: Guido van Rossum Date: Wed, 8 Oct 1997 15:22:32 +0000 (+0000) Subject: Allow open file as parameter (must be seekable) (Jack) X-Git-Tag: v1.5a4~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45ac47c0b2798cc3a29cf5111694aba5e9347e08;p=python Allow open file as parameter (must be seekable) (Jack) --- diff --git a/Lib/imghdr.py b/Lib/imghdr.py index c320594e97..422471fb44 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -2,13 +2,19 @@ #-------------------------# -# Recognize sound headers # +# Recognize image headers # #-------------------------# -def what(filename, h=None): +def what(file, h=None): if h is None: - f = open(filename, 'r') - h = f.read(32) + if type(file) == type(''): + f = open(file, 'rb') + h = f.read(32) + else: + location = file.tell() + h = file.read(32) + file.seek(location) + f = None else: f = None try: