mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Preserve order of tests
This commit is contained in:
parent
f1248b88d0
commit
c45a2dac8f
@ -91,7 +91,16 @@ def identify(src):
|
|||||||
# ---------------------------------#
|
# ---------------------------------#
|
||||||
|
|
||||||
|
|
||||||
def test_for_jpeg(h):
|
tests = []
|
||||||
|
|
||||||
|
|
||||||
|
def test(f):
|
||||||
|
tests.append(f)
|
||||||
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
@test
|
||||||
|
def jpeg(h):
|
||||||
"""JPEG data in JFIF format (Changed by Kovid to mimic the file utility,
|
"""JPEG data in JFIF format (Changed by Kovid to mimic the file utility,
|
||||||
the original code was failing with some jpegs that included ICC_PROFILE
|
the original code was failing with some jpegs that included ICC_PROFILE
|
||||||
data, for example: http://nationalpostnews.files.wordpress.com/2013/03/budget.jpeg?w=300&h=1571)"""
|
data, for example: http://nationalpostnews.files.wordpress.com/2013/03/budget.jpeg?w=300&h=1571)"""
|
||||||
@ -145,18 +154,21 @@ def jpeg_dimensions(stream):
|
|||||||
return -1, -1
|
return -1, -1
|
||||||
|
|
||||||
|
|
||||||
def test_for_png(h):
|
@test
|
||||||
|
def png(h):
|
||||||
if h[:8] == b"\211PNG\r\n\032\n":
|
if h[:8] == b"\211PNG\r\n\032\n":
|
||||||
return 'png'
|
return 'png'
|
||||||
|
|
||||||
|
|
||||||
def test_for_gif(h):
|
@test
|
||||||
|
def gif(h):
|
||||||
"""GIF ('87 and '89 variants)"""
|
"""GIF ('87 and '89 variants)"""
|
||||||
if h[:6] in (b'GIF87a', b'GIF89a'):
|
if h[:6] in (b'GIF87a', b'GIF89a'):
|
||||||
return 'gif'
|
return 'gif'
|
||||||
|
|
||||||
|
|
||||||
def test_for_tiff(h):
|
@test
|
||||||
|
def tiff(h):
|
||||||
"""TIFF (can be in Motorola or Intel byte order)"""
|
"""TIFF (can be in Motorola or Intel byte order)"""
|
||||||
if h[:2] in (b'MM', b'II'):
|
if h[:2] in (b'MM', b'II'):
|
||||||
if h[2:4] == b'\xbc\x01':
|
if h[2:4] == b'\xbc\x01':
|
||||||
@ -164,69 +176,80 @@ def test_for_tiff(h):
|
|||||||
return 'tiff'
|
return 'tiff'
|
||||||
|
|
||||||
|
|
||||||
def test_for_webp(h):
|
@test
|
||||||
|
def webp(h):
|
||||||
if h[:4] == b'RIFF' and h[8:12] == b'WEBP':
|
if h[:4] == b'RIFF' and h[8:12] == b'WEBP':
|
||||||
return 'webp'
|
return 'webp'
|
||||||
|
|
||||||
|
|
||||||
def test_for_rgb(h):
|
@test
|
||||||
|
def rgb(h):
|
||||||
"""SGI image library"""
|
"""SGI image library"""
|
||||||
if h[:2] == b'\001\332':
|
if h[:2] == b'\001\332':
|
||||||
return 'rgb'
|
return 'rgb'
|
||||||
|
|
||||||
|
|
||||||
def test_for_pbm(h):
|
@test
|
||||||
|
def pbm(h):
|
||||||
"""PBM (portable bitmap)"""
|
"""PBM (portable bitmap)"""
|
||||||
if len(h) >= 3 and \
|
if len(h) >= 3 and \
|
||||||
h[0] == b'P' and h[1] in b'14' and h[2] in b' \t\n\r':
|
h[0] == b'P' and h[1] in b'14' and h[2] in b' \t\n\r':
|
||||||
return 'pbm'
|
return 'pbm'
|
||||||
|
|
||||||
|
|
||||||
def test_for_pgm(h):
|
@test
|
||||||
|
def pgm(h):
|
||||||
"""PGM (portable graymap)"""
|
"""PGM (portable graymap)"""
|
||||||
if len(h) >= 3 and \
|
if len(h) >= 3 and \
|
||||||
h[0] == b'P' and h[1] in b'25' and h[2] in b' \t\n\r':
|
h[0] == b'P' and h[1] in b'25' and h[2] in b' \t\n\r':
|
||||||
return 'pgm'
|
return 'pgm'
|
||||||
|
|
||||||
|
|
||||||
def test_for_ppm(h):
|
@test
|
||||||
|
def ppm(h):
|
||||||
"""PPM (portable pixmap)"""
|
"""PPM (portable pixmap)"""
|
||||||
if len(h) >= 3 and \
|
if len(h) >= 3 and \
|
||||||
h[0] == b'P' and h[1] in b'36' and h[2] in b' \t\n\r':
|
h[0] == b'P' and h[1] in b'36' and h[2] in b' \t\n\r':
|
||||||
return 'ppm'
|
return 'ppm'
|
||||||
|
|
||||||
|
|
||||||
def test_for_rast(h):
|
@test
|
||||||
|
def rast(h):
|
||||||
"""Sun raster file"""
|
"""Sun raster file"""
|
||||||
if h[:4] == b'\x59\xA6\x6A\x95':
|
if h[:4] == b'\x59\xA6\x6A\x95':
|
||||||
return 'rast'
|
return 'rast'
|
||||||
|
|
||||||
|
|
||||||
def test_for_xbm(h):
|
@test
|
||||||
|
def xbm(h):
|
||||||
"""X bitmap (X10 or X11)"""
|
"""X bitmap (X10 or X11)"""
|
||||||
s = b'#define '
|
s = b'#define '
|
||||||
if h[:len(s)] == s:
|
if h[:len(s)] == s:
|
||||||
return 'xbm'
|
return 'xbm'
|
||||||
|
|
||||||
|
|
||||||
def test_for_bmp(h):
|
@test
|
||||||
|
def bmp(h):
|
||||||
if h[:2] == b'BM':
|
if h[:2] == b'BM':
|
||||||
return 'bmp'
|
return 'bmp'
|
||||||
|
|
||||||
|
|
||||||
def test_for_emf(h):
|
@test
|
||||||
|
def emf(h):
|
||||||
if h[:4] == b'\x01\0\0\0' and h[40:44] == b' EMF':
|
if h[:4] == b'\x01\0\0\0' and h[40:44] == b' EMF':
|
||||||
return 'emf'
|
return 'emf'
|
||||||
|
|
||||||
|
|
||||||
def test_for_jpeg2000(h):
|
@test
|
||||||
|
def jpeg2000(h):
|
||||||
if h[:12] == b'\x00\x00\x00\x0cjP \r\n\x87\n':
|
if h[:12] == b'\x00\x00\x00\x0cjP \r\n\x87\n':
|
||||||
return 'jpeg2000'
|
return 'jpeg2000'
|
||||||
|
|
||||||
|
|
||||||
def test_for_svg(h):
|
@test
|
||||||
|
def svg(h):
|
||||||
if h[:4] == b'<svg' or (h[:2] == b'<?' and h[2:5].tobytes().lower() == b'xml' and b'<svg' in h.tobytes()):
|
if h[:4] == b'<svg' or (h[:2] == b'<?' and h[2:5].tobytes().lower() == b'xml' and b'<svg' in h.tobytes()):
|
||||||
return 'svg'
|
return 'svg'
|
||||||
|
|
||||||
|
|
||||||
tests = tuple(v for k, v in globals().iteritems() if callable(v) and k.startswith('test_for_'))
|
tests = tuple(tests)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user