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

[deprecate-cgi] get charset without using cgi #5

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

jeffhung
Copy link
Contributor

Instead of the deprecated cgi.parse_header(), use email.message.EmailMessage to parse Content-Type header and extract charset.

The Problem

See PEP 594, the cgi module
is deprecated since version 3.11 and will be removed in version 3.13.

Thus creating the following lint error:

$ make lint
poetry run pylint requests_har
************* Module requests_har.har
requests_har/har.py:9:0: W4901: Deprecated module 'cgi' (deprecated-module)

------------------------------------------------------------------
Your code has been rated at 9.94/10 (previous run: 9.94/10, +0.00)

make: *** [lint] Error 4

And test warning:

$ make test
poetry run pytest
======================================================= test session starts ========================================================
platform darwin -- Python 3.11.6, pytest-7.4.4, pluggy-1.5.0
rootdir: /Users/jeff_hung/wc/NoteBrainer/requests_har
plugins: pylama-8.4.1
collected 1 item

tests/test_har.py .                                                                                                          [100%]

========================================================= warnings summary =========================================================
requests_har/har.py:9
  /Users/jeff_hung/wc/NoteBrainer/requests_har/requests_har/har.py:9: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
    from cgi import parse_header

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 1 passed, 1 warning in 0.16s ===================================================

The mitigation, as suggested in cgi.parse_header() document,
is to use email.message.EmailMessage instead.

See also:

After Fix

$ make lint
poetry run pylint requests_har

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

$ make test
poetry run pytest
======================================================= test session starts ========================================================
platform darwin -- Python 3.11.6, pytest-7.4.4, pluggy-1.5.0
rootdir: /Users/jeff_hung/wc/NoteBrainer/requests_har
plugins: pylama-8.4.1
collected 1 item

tests/test_har.py .                                                                                                          [100%]

======================================================== 1 passed in 0.15s =========================================================

Instead of the deprecated `cgi.parse_header()`, use
`email.message.EmailMessage` to parse `Content-Type` header and extract
charset.
@jeffhung
Copy link
Contributor Author

This PR fixes #4.

@sbordeyne sbordeyne merged commit fbd68e0 into sbordeyne:master Jul 11, 2024
@FelixSchwarz
Copy link

Thank you for fixing this - how about a new release? Python 3.13 is out for a bit now :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants