diff options
author | Stefan Wójcik <wojcikstefan@gmail.com> | 2016-05-01 22:54:52 -0700 |
---|---|---|
committer | Stefan Wójcik <wojcikstefan@gmail.com> | 2016-05-01 22:54:52 -0700 |
commit | c1e94e242ed3a499df7bc463aee239218629931e (patch) | |
tree | a16cace66acf4400d4731f11af3a88ec5331585d /mimeparse.py | |
parent | 21385419371c212449fee83bd8b1cbe0824f845d (diff) | |
parent | 109b38802db3a1128b064142a6a9fd72df74d08d (diff) | |
download | python-mimeparse-c1e94e242ed3a499df7bc463aee239218629931e.tar.gz |
Merge pull request #19 from scop/use-cgi
Use cgi.parse_header for main type parsing
Diffstat (limited to 'mimeparse.py')
-rw-r--r-- | mimeparse.py | 7 |
1 files changed, 2 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 == '*': |