diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-08-16 16:29:02 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-08-16 16:29:02 (GMT) |
commit | 4acb1899c6fe341c4c259c80fe6ba21be34051d2 (patch) | |
tree | f80755c271be525b4eb6eb0beeb6e354d88b012e /Lib | |
parent | eb90b788f44fae967e969e967e2bd2276f3c6597 (diff) | |
download | cpython-4acb1899c6fe341c4c259c80fe6ba21be34051d2.zip cpython-4acb1899c6fe341c4c259c80fe6ba21be34051d2.tar.gz cpython-4acb1899c6fe341c4c259c80fe6ba21be34051d2.tar.bz2 |
#3424 rearrange the order of tests in imghdr to place more common types first
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/imghdr.py | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/Lib/imghdr.py b/Lib/imghdr.py index 233ea33..1683024 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -34,12 +34,25 @@ def what(file, h=None): tests = [] -def test_rgb(h, f): - """SGI image library""" - if h[:2] == '\001\332': - return 'rgb' +def test_jpeg(h, f): + """JPEG data in JFIF format""" + if h[6:10] == 'JFIF': + 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): """GIF ('87 and '89 variants)""" @@ -48,6 +61,20 @@ def test_gif(h, f): 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): """PBM (portable bitmap)""" if len(h) >= 3 and \ @@ -72,13 +99,6 @@ def test_ppm(h, f): 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): """Sun raster file""" if h[:4] == '\x59\xA6\x6A\x95': @@ -94,32 +114,12 @@ def test_xbm(h, f): 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): if h[:2] == 'BM': return '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 # #--------------------# |