summaryrefslogtreecommitdiff
path: root/Lib/imghdr.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-08 15:22:32 +0000
committerGuido van Rossum <guido@python.org>1997-10-08 15:22:32 +0000
commit0e96cf0cdc35dff5c6f04b75d335347ab73346e8 (patch)
tree77692ebbbcd55211385b8db94649a69c51ce1737 /Lib/imghdr.py
parentea04a391d63afe757376d2fcd495f3ec48f965b4 (diff)
downloadcpython-0e96cf0cdc35dff5c6f04b75d335347ab73346e8.tar.gz
Allow open file as parameter (must be seekable) (Jack)
Diffstat (limited to 'Lib/imghdr.py')
-rw-r--r--Lib/imghdr.py14
1 files changed, 10 insertions, 4 deletions
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: