Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 dataclasses
import datetime
import enum
Expand All @@ -19,6 +18,7 @@
import weakref
from collections import namedtuple
from contextlib import suppress
from email.parser import HeaderParser
from email.utils import parsedate
from http.cookies import SimpleCookie
from math import ceil
Expand Down Expand Up @@ -748,7 +748,10 @@ def _parse_content_type(self, raw: 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()
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
params = msg.get_params()
self._content_dict = dict(params[1:]) # First element is content type again

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