Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 0b417c7

Browse files
committed
Stop using the cgi module, it is deprecated
Rewrite code that calls cgi.parse_header() because the cgi module is deprecated, and will be removed in Python 3.11 Use email.message.EmailMessage for parsing MIME types instead.
1 parent 10b6efb commit 0b417c7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pantomime/parse.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from cgi import parse_header
1+
from email.message import EmailMessage
22
from typing import Any, Dict, Optional, Tuple
33
from normality import stringify
44
from normality.encoding import tidy_encoding
@@ -62,7 +62,10 @@ def parse(
6262
mime_type = stringify(mime_type)
6363
params = None
6464
if mime_type is not None:
65-
mime_type, params = parse_header(mime_type)
65+
msg = EmailMessage()
66+
msg['content-type'] = mime_type
67+
mime_type = msg.get_content_type() if mime_type.count("/") == 1 else None
68+
params = msg['content-type'].params
6669

6770
family, subtype = cls.split(mime_type)
6871
if family is None:

0 commit comments

Comments
 (0)