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

Replace deprecated cgi usage with email.message #35

Merged
merged 2 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions cssutils/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Testcases for cssutils.util"""


import cgi
from email.message import Message
import re
import urllib.request
import urllib.error
Expand Down Expand Up @@ -384,9 +384,11 @@ class Response:
def __init__(self, url, contenttype, content, exception=None, args=None):
self.url = url

mt, params = cgi.parse_header(contenttype)
self.mimetype = mt
self.charset = params.get('charset', None)
m = Message()
m['content-type'] = contenttype

self.mimetype = m.get_content_type()
self.charset = m.get_param('charset', None)

self.text = content

Expand Down
9 changes: 6 additions & 3 deletions encutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
'EncodingInfo',
]

from email.message import Message
import html.parser
import io
import cgi
import re
import sys
import urllib.request
Expand Down Expand Up @@ -315,8 +315,11 @@ def getMetaInfo(text, log=None):
pass

if p.content_type:
media_type, params = cgi.parse_header(p.content_type)
encoding = params.get('charset') # defaults to None
m = Message()
m['content-type'] = p.content_type

media_type = m.get_content_type()
encoding = m.get_param('charset') # defaults to None
if encoding:
encoding = encoding.lower()
if log:
Expand Down