summaryrefslogtreecommitdiffstats
path: root/Lib/imghdr.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/imghdr.py')
-rw-r--r--Lib/imghdr.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/Lib/imghdr.py b/Lib/imghdr.py
index f34f234..d0f66e5 100644
--- a/Lib/imghdr.py
+++ b/Lib/imghdr.py
@@ -36,14 +36,14 @@ tests = []
def test_rgb(h, f):
"""SGI image library"""
- if h[:2] == '\001\332':
+ if h[:2] == b'\001\332':
return 'rgb'
tests.append(test_rgb)
def test_gif(h, f):
"""GIF ('87 and '89 variants)"""
- if h[:6] in ('GIF87a', 'GIF89a'):
+ if h[:6] in (b'GIF87a', b'GIF89a'):
return 'gif'
tests.append(test_gif)
@@ -51,7 +51,7 @@ tests.append(test_gif)
def test_pbm(h, f):
"""PBM (portable bitmap)"""
if len(h) >= 3 and \
- h[0] == 'P' and h[1] in '14' and h[2] in ' \t\n\r':
+ h[0] == ord('P') and h[1] in b'14' and h[2] in b' \t\n\r':
return 'pbm'
tests.append(test_pbm)
@@ -59,7 +59,7 @@ tests.append(test_pbm)
def test_pgm(h, f):
"""PGM (portable graymap)"""
if len(h) >= 3 and \
- h[0] == 'P' and h[1] in '25' and h[2] in ' \t\n\r':
+ h[0] == ord('P') and h[1] in b'25' and h[2] in b' \t\n\r':
return 'pgm'
tests.append(test_pgm)
@@ -67,28 +67,28 @@ tests.append(test_pgm)
def test_ppm(h, f):
"""PPM (portable pixmap)"""
if len(h) >= 3 and \
- h[0] == 'P' and h[1] in '36' and h[2] in ' \t\n\r':
+ h[0] == ord('P') and h[1] in b'36' and h[2] in b' \t\n\r':
return 'ppm'
tests.append(test_ppm)
def test_tiff(h, f):
"""TIFF (can be in Motorola or Intel byte order)"""
- if h[:2] in ('MM', 'II'):
+ if h[:2] in (b'MM', b'II'):
return 'tiff'
tests.append(test_tiff)
def test_rast(h, f):
"""Sun raster file"""
- if h[:4] == '\x59\xA6\x6A\x95':
+ if h[:4] == b'\x59\xA6\x6A\x95':
return 'rast'
tests.append(test_rast)
def test_xbm(h, f):
"""X bitmap (X10 or X11)"""
- s = '#define '
+ s = b'#define '
if h[:len(s)] == s:
return 'xbm'
@@ -96,26 +96,26 @@ tests.append(test_xbm)
def test_jpeg(h, f):
"""JPEG data in JFIF format"""
- if h[6:10] == 'JFIF':
+ if h[6:10] == b'JFIF':
return 'jpeg'
tests.append(test_jpeg)
def test_exif(h, f):
"""JPEG data in Exif format"""
- if h[6:10] == 'Exif':
+ if h[6:10] == b'Exif':
return 'jpeg'
tests.append(test_exif)
def test_bmp(h, f):
- if h[:2] == 'BM':
+ if h[:2] == b'BM':
return 'bmp'
tests.append(test_bmp)
def test_png(h, f):
- if h[:8] == "\211PNG\r\n\032\n":
+ if h[:8] == b'\211PNG\r\n\032\n':
return 'png'
tests.append(test_png)
@@ -159,3 +159,6 @@ def testall(list, recursive, toplevel):
print(what(filename))
except IOError:
print('*** not found ***')
+
+if __name__ == '__main__':
+ test()