From 204779b7732a403e819df9a12b8f605c0c666e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=3D=3FUTF-8=3Fq=3FVille=3D20Skytt=3DC3=3DA4=3F=3D?= Date: Mon, 16 May 2022 08:48:31 +0200 Subject: [PATCH] Stop using the cgi module, deprecated in Python 3.11 per PEP 594 (#6708) * 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 * Create 6708.misc Co-authored-by: Sam Bull --- aiohttp/helpers.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index 536d219..f30f76b 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -3,7 +3,6 @@ import asyncio import base64 import binascii -import cgi import datetime import functools import inspect @@ -17,6 +16,7 @@ import warnings 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 @@ -756,7 +756,10 @@ class HeadersMixin: 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: -- 2.33.1