--- imghdr35.py 2016-11-02 16:54:11.351506360 -0400 +++ imghdr_py3.py 2016-11-02 16:37:20.519517721 -0400 @@ -1,7 +1,5 @@ """Recognize image file formats based on their first few bytes.""" -from os import PathLike - __all__ = ["what"] #-------------------------# @@ -12,7 +10,7 @@ f = None try: if h is None: - if isinstance(file, (str, PathLike)): + if isinstance(file, str): f = open(file, 'rb') h = f.read(32) else: @@ -124,6 +122,23 @@ tests.append(test_exr) +def test_jpeg1(h, f): + """JPEG data in JFIF format""" + if b'JFIF' in h[:23]: + return 'jpeg' + +tests.append(test_jpeg1) + +JPEG_MARK = b'\xff\xd8\xff\xdb\x00C\x00\x08\x06\x06' \ + b'\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c\x0b\x0b\x0c\x19\x12\x13\x0f' + +def test_jpeg2(h, f): + """JPEG with small header""" + if len(h) >= 32 and 67 == h[5] and h[:32] == JPEG_MARK: + return 'jpeg' + +tests.append(test_jpeg2) + #--------------------# # Small test program # #--------------------#