diff options
author | Ville Skyttä <ville.skytta@iki.fi> | 2016-04-28 10:47:19 +0300 |
---|---|---|
committer | Ville Skyttä <ville.skytta@iki.fi> | 2016-05-02 10:26:35 +0300 |
commit | 64a64e32ab8c14e91a6a196cf0a2dd7637d4f3a7 (patch) | |
tree | 24d4cca9ae2404fa053c0083274bee898af78fda | |
parent | 7d3bf001d284ffbd9d555ce213241040c291f79b (diff) | |
download | python-mimeparse-64a64e32ab8c14e91a6a196cf0a2dd7637d4f3a7.tar.gz |
Handle q parameter name case insensitively
https://tools.ietf.org/html/rfc7231#section-5.3.1
-rw-r--r-- | mimeparse.py | 3 | ||||
-rw-r--r-- | testdata.json | 1 |
2 files changed, 3 insertions, 1 deletions
diff --git a/mimeparse.py b/mimeparse.py index 7f4aa3c..91b28b8 100644 --- a/mimeparse.py +++ b/mimeparse.py @@ -72,8 +72,9 @@ def parse_media_range(range): necessary. """ (type, subtype, params) = parse_mime_type(range) + params.setdefault('q', params.pop('Q', None)) # q is case insensitive try: - if not params.get('q') or not 0 <= float(params['q']) <= 1: + if not params['q'] or not 0 <= float(params['q']) <= 1: params['q'] = '1' except ValueError: # from float() params['q'] = '1' diff --git a/testdata.json b/testdata.json index ab7693c..4f0a648 100644 --- a/testdata.json +++ b/testdata.json @@ -9,6 +9,7 @@ ["application/xml ; q=2;b=other",["application", "xml", {"q": "1", "b":"other"}]], ["application/xml ; q=0",["application", "xml", {"q": "0"}]], ["application/xml ; q=foo", ["application", "xml", {"q": "1"}]], + ["application/xml ; Q=0.6", ["application", "xml", {"q": "0.6"}]], [" *; q=.2",["*", "*", {"q": ".2"}]] ], |