Kaydet (Commit) 4acb1899 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

#3424 rearrange the order of tests in imghdr to place more common types first

üst eb90b788
...@@ -34,12 +34,25 @@ def what(file, h=None): ...@@ -34,12 +34,25 @@ def what(file, h=None):
tests = [] tests = []
def test_rgb(h, f): def test_jpeg(h, f):
"""SGI image library""" """JPEG data in JFIF format"""
if h[:2] == '\001\332': if h[6:10] == 'JFIF':
return 'rgb' return 'jpeg'
tests.append(test_rgb) tests.append(test_jpeg)
def test_exif(h, f):
"""JPEG data in Exif format"""
if h[6:10] == 'Exif':
return 'jpeg'
tests.append(test_exif)
def test_png(h, f):
if h[:8] == "\211PNG\r\n\032\n":
return 'png'
tests.append(test_png)
def test_gif(h, f): def test_gif(h, f):
"""GIF ('87 and '89 variants)""" """GIF ('87 and '89 variants)"""
...@@ -48,6 +61,20 @@ def test_gif(h, f): ...@@ -48,6 +61,20 @@ def test_gif(h, f):
tests.append(test_gif) tests.append(test_gif)
def test_tiff(h, f):
"""TIFF (can be in Motorola or Intel byte order)"""
if h[:2] in ('MM', 'II'):
return 'tiff'
tests.append(test_tiff)
def test_rgb(h, f):
"""SGI image library"""
if h[:2] == '\001\332':
return 'rgb'
tests.append(test_rgb)
def test_pbm(h, f): def test_pbm(h, f):
"""PBM (portable bitmap)""" """PBM (portable bitmap)"""
if len(h) >= 3 and \ if len(h) >= 3 and \
...@@ -72,13 +99,6 @@ def test_ppm(h, f): ...@@ -72,13 +99,6 @@ def test_ppm(h, f):
tests.append(test_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'):
return 'tiff'
tests.append(test_tiff)
def test_rast(h, f): def test_rast(h, f):
"""Sun raster file""" """Sun raster file"""
if h[:4] == '\x59\xA6\x6A\x95': if h[:4] == '\x59\xA6\x6A\x95':
...@@ -94,32 +114,12 @@ def test_xbm(h, f): ...@@ -94,32 +114,12 @@ def test_xbm(h, f):
tests.append(test_xbm) tests.append(test_xbm)
def test_jpeg(h, f):
"""JPEG data in JFIF format"""
if h[6:10] == 'JFIF':
return 'jpeg'
tests.append(test_jpeg)
def test_exif(h, f):
"""JPEG data in Exif format"""
if h[6:10] == 'Exif':
return 'jpeg'
tests.append(test_exif)
def test_bmp(h, f): def test_bmp(h, f):
if h[:2] == 'BM': if h[:2] == 'BM':
return 'bmp' return 'bmp'
tests.append(test_bmp) tests.append(test_bmp)
def test_png(h, f):
if h[:8] == "\211PNG\r\n\032\n":
return 'png'
tests.append(test_png)
#--------------------# #--------------------#
# Small test program # # Small test program #
#--------------------# #--------------------#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment