Skip to content

Commit 8c1d881

Browse files
authored
fix: workaround magic false positives (ietf-tools#9207)
* fix: workaround magic false positives * chore: ruff
1 parent ef99ffe commit 8c1d881

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

ietf/utils/mime.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import magic
66
import re
77

8+
89
def get_mime_type(content):
910
# try to fixup encoding
1011
if hasattr(magic, "open"):
@@ -13,15 +14,17 @@ def get_mime_type(content):
1314
filetype = m.buffer(content)
1415
else:
1516
m = magic.Magic()
16-
m.cookie = magic.magic_open(magic.MAGIC_NONE | magic.MAGIC_MIME | magic.MAGIC_MIME_ENCODING)
17+
m.cookie = magic.magic_open(
18+
magic.MAGIC_NONE | magic.MAGIC_MIME | magic.MAGIC_MIME_ENCODING
19+
)
1720
magic.magic_load(m.cookie, None)
1821
filetype = m.from_buffer(content)
1922
# Work around silliness in libmagic on OpenSUSE 15.1
20-
filetype = filetype.replace('text/x-Algol68;', 'text/plain;')
21-
if ';' in filetype and 'charset=' in filetype:
22-
mimetype, charset = re.split('; *charset=', filetype)
23+
filetype = filetype.replace("text/x-Algol68;", "text/plain;")
24+
filetype = filetype.replace("application/vnd.hp-HPGL;", "text/plain;")
25+
if ";" in filetype and "charset=" in filetype:
26+
mimetype, charset = re.split("; *charset=", filetype)
2327
else:
24-
mimetype = re.split(';', filetype)[0]
25-
charset = 'utf-8'
28+
mimetype = re.split(";", filetype)[0]
29+
charset = "utf-8"
2630
return mimetype, charset
27-

0 commit comments

Comments
 (0)