Skip to content

Commit

Permalink
Replace usage of cgi.parse_header with email.message.Message
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Sep 2, 2022
1 parent 43b1006 commit cd65655
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Version 0.10
- Add ``NOTICE.txt`` to ``license_files``, #58
- Use default SSL context when downloading classifiers from PyPI, #57
- Remove ``setup.py``, #52
- Explicitly limit oldest supported Python version.
- Explicitly limit oldest supported Python version
- Replace usage of ``cgi.parse_header`` with ``email.message.Message``

Version 0.9
===========
Expand Down
8 changes: 4 additions & 4 deletions src/validate_pyproject/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ def pep517_backend_reference(value: str) -> bool:


def _download_classifiers() -> str:
import cgi
import ssl
from email.message import Message
from urllib.request import urlopen

url = "https://pypi.org/pypi?:action=list_classifiers"
context = ssl.create_default_context()
with urlopen(url, context=context) as response:
content_type = response.getheader("content-type", "text/plain")
encoding = cgi.parse_header(content_type)[1].get("charset", "utf-8")
return response.read().decode(encoding)
headers = Message()
headers["content_type"] = response.getheader("content-type", "text/plain")
return response.read().decode(headers.get_param("charset", "utf-8"))


class _TroveClassifier:
Expand Down

0 comments on commit cd65655

Please sign in to comment.