From c16ea58ea097bf2c8f68d67fdf4b71b81a6903bc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Dec 2022 18:44:30 -0500 Subject: [PATCH 1/6] Rely on email.message to parse a header. --- twine/commands/check.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/twine/commands/check.py b/twine/commands/check.py index 5942f221..19aeee32 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import argparse -import cgi +import email.message import io import logging import re @@ -63,6 +63,13 @@ def __str__(self) -> str: return self.getvalue().strip() +# from Python 3.11 docs +def parse_content_type(value): + msg = email.message.EmailMessage() + msg['content-type'] = value + return msg.get_content_type(), msg['content-type'].params + + def _check_file( filename: str, render_warning_stream: _WarningStream ) -> Tuple[List[str], bool]: @@ -82,7 +89,7 @@ def _check_file( ) description_content_type = "text/x-rst" - content_type, params = cgi.parse_header(description_content_type) + content_type, params = parse_content_type(description_content_type) renderer = _RENDERERS.get(content_type, _RENDERERS[None]) if description is None or description.rstrip() == "UNKNOWN": From d38a22665fc24ad8f8f18ffe3037f95ff4617f93 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Dec 2022 18:55:52 -0500 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(d?= =?UTF-8?q?elint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twine/commands/check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/twine/commands/check.py b/twine/commands/check.py index 19aeee32..1ebeada6 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -66,8 +66,8 @@ def __str__(self) -> str: # from Python 3.11 docs def parse_content_type(value): msg = email.message.EmailMessage() - msg['content-type'] = value - return msg.get_content_type(), msg['content-type'].params + msg["content-type"] = value + return msg.get_content_type(), msg["content-type"].params def _check_file( From 93b44dc085b3bccb73a00e72468fe93b4a1d7792 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Dec 2022 18:58:09 -0500 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=A7=8E=E2=80=8D=E2=99=80=EF=B8=8F=20G?= =?UTF-8?q?enuflect=20to=20the=20types.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twine/commands/check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twine/commands/check.py b/twine/commands/check.py index 1ebeada6..3212bf52 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -64,7 +64,7 @@ def __str__(self) -> str: # from Python 3.11 docs -def parse_content_type(value): +def parse_content_type(value: str) -> Tuple[str, dict[str, str]]: msg = email.message.EmailMessage() msg["content-type"] = value return msg.get_content_type(), msg["content-type"].params From 6ce2f3608bc610f368ac5bb1b42fb137896ff5ce Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 24 Dec 2022 14:33:16 -0500 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=A7=8E=E2=80=8D=E2=99=80=EF=B8=8F=20G?= =?UTF-8?q?enuflect=20to=20the=20types.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twine/commands/check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/twine/commands/check.py b/twine/commands/check.py index 3212bf52..64faeca2 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -17,7 +17,7 @@ import io import logging import re -from typing import List, Optional, Tuple, cast +from typing import Dict, List, Optional, Tuple, cast import readme_renderer.rst from rich import print @@ -64,7 +64,7 @@ def __str__(self) -> str: # from Python 3.11 docs -def parse_content_type(value: str) -> Tuple[str, dict[str, str]]: +def parse_content_type(value: str) -> Tuple[str, Dict[str, str]]: msg = email.message.EmailMessage() msg["content-type"] = value return msg.get_content_type(), msg["content-type"].params From e45f5faa16be66ed36d742e8467d94e728e01cee Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Tue, 3 Jan 2023 07:04:22 -0500 Subject: [PATCH 5/6] Indicate private utility method --- twine/commands/check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/twine/commands/check.py b/twine/commands/check.py index 64faeca2..ad78903b 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -64,7 +64,7 @@ def __str__(self) -> str: # from Python 3.11 docs -def parse_content_type(value: str) -> Tuple[str, Dict[str, str]]: +def _parse_content_type(value: str) -> Tuple[str, Dict[str, str]]: msg = email.message.EmailMessage() msg["content-type"] = value return msg.get_content_type(), msg["content-type"].params @@ -89,7 +89,7 @@ def _check_file( ) description_content_type = "text/x-rst" - content_type, params = parse_content_type(description_content_type) + content_type, params = _parse_content_type(description_content_type) renderer = _RENDERERS.get(content_type, _RENDERERS[None]) if description is None or description.rstrip() == "UNKNOWN": From 44149b7577ff9a83cc4542551c8c6b22c7b64468 Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Wed, 4 Jan 2023 06:07:40 -0500 Subject: [PATCH 6/6] Replace comment with docstring --- twine/commands/check.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/twine/commands/check.py b/twine/commands/check.py index ad78903b..90b2e375 100644 --- a/twine/commands/check.py +++ b/twine/commands/check.py @@ -63,8 +63,11 @@ def __str__(self) -> str: return self.getvalue().strip() -# from Python 3.11 docs def _parse_content_type(value: str) -> Tuple[str, Dict[str, str]]: + """Implement logic of deprecated cgi.parse_header(). + + From https://docs.python.org/3.11/library/cgi.html#cgi.parse_header. + """ msg = email.message.EmailMessage() msg["content-type"] = value return msg.get_content_type(), msg["content-type"].params