summaryrefslogtreecommitdiff
path: root/mimeparse.py
diff options
context:
space:
mode:
authorD.B. Tsai <dbtsai@dbtsai.com>2012-08-26 16:29:14 -0700
committerD.B. Tsai <dbtsai@dbtsai.com>2012-08-27 20:02:53 -0700
commit29a769f3107e904e4935efe8765328f79adf633a (patch)
tree7dddf867ef4fa54745257d5365cbc2eea3914480 /mimeparse.py
parenta63b32c7a7673ccfd24593ed69e57e43edfefb1b (diff)
downloadpython-mimeparse-29a769f3107e904e4935efe8765328f79adf633a.tar.gz
Fixed that parse_media_range overrides quality values of 0
https://github.com/dbtsai/python-mimeparse/issues/1
Diffstat (limited to 'mimeparse.py')
-rwxr-xr-xmimeparse.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/mimeparse.py b/mimeparse.py
index 9f9a2c1..181e01f 100755
--- a/mimeparse.py
+++ b/mimeparse.py
@@ -66,8 +66,7 @@ def parse_media_range(range):
"""
(type, subtype, params) = parse_mime_type(range)
if not 'q' in params or not params['q'] or \
- not float(params['q']) or float(params['q']) > 1\
- or float(params['q']) < 0:
+ float(params['q']) > 1 or float(params['q']) < 0:
params['q'] = '1'
return (type, subtype, params)
@@ -95,7 +94,7 @@ def fitness_and_quality_parsed(mime_type, parsed_ranges):
target_subtype == '*')
if type_match and subtype_match:
param_matches = reduce(lambda x, y: x + y, [1 for (key, value) in
- list(target_params.items()) if key != 'q' and
+ target_params.items() if key != 'q' and
key in params and value == params[key]], 0)
fitness = (type == target_type) and 100 or 0
fitness += (subtype == target_subtype) and 10 or 0