Skip to content

Commit

Permalink
Merge pull request #35 from Vekhir/replace-deprecated-cgi
Browse files Browse the repository at this point in the history
Replace deprecated cgi usage with email.message
  • Loading branch information
jaraco committed Jun 9, 2023
2 parents ebbf820 + 94d3b3f commit c43e72b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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

0 comments on commit c43e72b

Please sign in to comment.