Skip to content

Commit

Permalink
Stop using the cgi module, deprecated in Python 3.11 per PEP 594 (#6708
Browse files Browse the repository at this point in the history
…) (#6734)

* Stop using the cgi module, deprecated in Python 3.11 per PEP 594

https://peps.python.org/pep-0594/#cgi

* Simplify creating params dict

Co-authored-by: Sam Bull <[email protected]>

* Create 6708.misc

Co-authored-by: Sam Bull <[email protected]>
(cherry picked from commit a045480)
  • Loading branch information
scop authored May 6, 2022
1 parent e6e878b commit 4ab3584
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/6708.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace deprecated cgi module usage with email.parser.
7 changes: 5 additions & 2 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import base64
import binascii
import cgi
import datetime
import enum
import functools
Expand All @@ -18,6 +17,7 @@
import weakref
from collections import namedtuple
from contextlib import suppress
from email.parser import HeaderParser
from email.utils import parsedate
from math import ceil
from pathlib import Path
Expand Down Expand Up @@ -768,7 +768,10 @@ def _parse_content_type(self, raw: Optional[str]) -> None:
self._content_type = "application/octet-stream"
self._content_dict = {}
else:
self._content_type, self._content_dict = cgi.parse_header(raw)
msg = HeaderParser().parsestr("Content-Type: " + raw)
self._content_type = msg.get_content_type()
params = msg.get_params()
self._content_dict = dict(params[1:]) # First element is content type again

@property
def content_type(self) -> str:
Expand Down

0 comments on commit 4ab3584

Please sign in to comment.