1From 221a1f15a42f3ef76ccafcddf66b7c4ade391bff Mon Sep 17 00:00:00 2001
2From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
3Date: Sat, 11 Feb 2023 12:17:00 -0500
4Subject: [PATCH] drop use of imghdr
5
6imghdr is deprecated and will be removed in python 3.13 (see https://peps.python.org/pep-0594/#imghdr)
7
8The relevant code in imghdr is just:
9
10```
11def test_jpeg(h, f):
12 """JPEG data with JFIF or Exif markers; and raw JPEG"""
13 if h[6:10] in (b'JFIF', b'Exif'):
14 return 'jpeg'
15 elif h[:4] == b'\xff\xd8\xff\xdb':
16 return 'jpeg'
17```
18
19So we transplant it directly
20---
21 pgpy/constants.py | 4 +---
22 1 file changed, 1 insertion(+), 3 deletions(-)
23
24diff --git a/pgpy/constants.py b/pgpy/constants.py
25index 28a4561a..983916d4 100644
26--- a/pgpy/constants.py
27+++ b/pgpy/constants.py
28@@ -2,7 +2,6 @@
29 """
30 import bz2
31 import hashlib
32-import imghdr
33 import os
34 import zlib
35 import warnings
36@@ -429,8 +428,7 @@ class ImageEncoding(IntEnum):
37
38 @classmethod
39 def encodingof(cls, imagebytes):
40- type = imghdr.what(None, h=imagebytes)
41- if type == 'jpeg':
42+ if imagebytes[6:10] in (b'JFIF', b'Exif') or imagebytes[:4] == b'\xff\xd8\xff\xdb':
43 return ImageEncoding.JPEG
44 return ImageEncoding.Unknown # pragma: no cover
45