diff --git a/cssutils/tests/test_util.py b/cssutils/tests/test_util.py index a82e3c58..9606bf1a 100644 --- a/cssutils/tests/test_util.py +++ b/cssutils/tests/test_util.py @@ -1,7 +1,7 @@ """Testcases for cssutils.util""" -import cgi +from email.message import Message import re import urllib.request import urllib.error @@ -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 diff --git a/encutils/__init__.py b/encutils/__init__.py index da6aa042..d44ab3bf 100644 --- a/encutils/__init__.py +++ b/encutils/__init__.py @@ -50,9 +50,9 @@ 'EncodingInfo', ] +from email.message import Message import html.parser import io -import cgi import re import sys import urllib.request @@ -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: