diff options
-rw-r--r-- | mimeparse.py | 7 | ||||
-rw-r--r-- | testdata.json | 1 |
2 files changed, 3 insertions, 5 deletions
diff --git a/mimeparse.py b/mimeparse.py index f1677f9..2884b1d 100644 --- a/mimeparse.py +++ b/mimeparse.py @@ -18,6 +18,7 @@ Contents: - best_match(): Choose the mime-type with the highest quality ('q') from a list of candidates. """ +import cgi from functools import reduce __version__ = '1.5.2' @@ -41,11 +42,7 @@ def parse_mime_type(mime_type): ('application', 'xhtml', {'q', '0.5'}) """ - parts = mime_type.split(';') - params = dict([tuple([s.strip() for s in param.split('=', 1)]) - for param in parts[1:] - ]) - full_type = parts[0].strip() + full_type, params = cgi.parse_header(mime_type) # Java URLConnection class sends an Accept header that includes a # single '*'. Turn it into a legal wildcard. if full_type == '*': diff --git a/testdata.json b/testdata.json index bb89e6f..409ab72 100644 --- a/testdata.json +++ b/testdata.json @@ -41,6 +41,7 @@ "parse_mime_type": [ ["application/xhtml;q=0.5", ["application", "xhtml", {"q": "0.5"}]], ["application/xhtml;q=0.5;ver=1.2", ["application", "xhtml", {"q": "0.5", "ver": "1.2"}]], + ["application/xhtml;q=0.5;foo=\"bar quux\"", ["application", "xhtml", {"q": "0.5", "foo": "bar quux"}]], ["text", null], ["text/something/invalid", null] ] |