Skip to content
Myr

Replace cgi which will be deprecated in Python 3.11 (#2309)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Replace cgi which will be deprecated in Python 3.11 * Update httpx/_utils.py

authored by Florimond Manca · committed by GitHub · parent 45b7cfa · Browse files · 2 files+11 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−6 removed

  • other:+11 added−6 removed

2 files+11 added−6 removed

modified:httpx/_models.py+2 added-6 removed
1import cgi1import datetime2import email.message3import json as jsonlib4import typing
40 unmodified lines
45 is_known_encoding,46 normalize_header_key,47 normalize_header_value,48 obfuscate_sensitive_headers,49 parse_content_type_charset,50 parse_header_links,51)5253
553 unmodified lines
607 content_type = self.headers.get("Content-Type")608 if content_type is None:609 return None610611 _, params = cgi.parse_header(content_type)612 if "charset" not in params:613 return None611 return parse_content_type_charset(content_type)612615 return params["charset"].strip("'\"")616613 def _get_content_decoder(self) -> ContentDecoder:614 """615 Returns a decoder instance which can be used to decode the raw byte616 content, depending on the Content-Encoding used in the response.
587 unmodified lines
modified:httpx/_utils.py+9 added
1import codecs2import email.message3import logging4import mimetypes5import netrc6import os
202 unmodified lines
209 links.append(link)210 return links211212213def parse_content_type_charset(content_type: str) -> typing.Optional[str]:214 # We used to use `cgi.parse_header()` here, but `cgi` became a dead battery.215 # See: https://peps.python.org/pep-0594/#cgi216 msg = email.message.Message()217 msg["content-type"] = content_type218 return msg.get_content_charset(failobj=None)219220221SENSITIVE_HEADERS = {"authorization", "proxy-authorization"}222223224def obfuscate_sensitive_headers(
307 unmodified lines