4
4
__license__ = 'MIT License'
5
5
__credits__ = ''
6
6
7
- from typing import Dict , Generator , Iterable , Tuple
7
+ from typing import Dict , Generator , Iterable , Tuple , Union
8
8
9
9
10
10
class MimeTypeParseException (ValueError ):
@@ -90,7 +90,7 @@ def parse_media_range(range: str) -> Tuple[str, str, Dict[str, str]]:
90
90
necessary.
91
91
"""
92
92
(type , subtype , params ) = parse_mime_type (range )
93
- params .setdefault ('q' , params .pop ('Q' , None )) # q is case insensitive
93
+ params .setdefault ('q' , params .pop ('Q' , '1.0' )) # q is case insensitive
94
94
try :
95
95
if not params ['q' ] or not 0 <= float (params ['q' ]) <= 1 :
96
96
params ['q' ] = '1'
@@ -112,8 +112,8 @@ def quality_and_fitness_parsed(
112
112
match, or (-1, 0) if no match was found. Just as for quality_parsed(),
113
113
'parsed_ranges' must be a list of parsed media ranges.
114
114
"""
115
- best_fitness = - 1
116
- best_fit_q = 0
115
+ best_fitness = - 1.
116
+ best_fit_q : Union [ float , str ] = 0.
117
117
(target_type , target_subtype , target_params ) = \
118
118
parse_media_range (mime_type )
119
119
@@ -128,10 +128,10 @@ def quality_and_fitness_parsed(
128
128
if type_match and subtype_match :
129
129
130
130
# 100 points if the type matches w/o a wildcard
131
- fitness = type == target_type and 100 or 0
131
+ fitness = type == target_type and 100. or 0.
132
132
133
133
# 10 points if the subtype matches w/o a wildcard
134
- fitness += subtype == target_subtype and 10 or 0
134
+ fitness += subtype == target_subtype and 10. or 0.
135
135
136
136
# 1 bonus point for each matching param besides "q"
137
137
param_matches = sum ([
0 commit comments