implement changes after code review

This commit is contained in:
dbairaktaris1
2018-01-03 23:40:08 -06:00
parent 1988d9cf72
commit 071796d83f
2 changed files with 5 additions and 20 deletions
+5 -12
View File
@@ -453,20 +453,12 @@ def _parse_content_type_header(header):
:return: tuple containing content type and dictionary of
parameters
"""
if not header:
return None
# append delimiter on end to ensure at least two elements when split by ';'
header += ';'
# split content type's main value from params
tokens = header.split(';', 1)
content_type_index = 0
params_index = 1
content_type = tokens[content_type_index].strip()
params = tokens[params_index]
params_dict = dict()
tokens = header.split(';')
content_type, params = tokens[0].strip(), tokens[1:]
params_dict = {} # Using dict is actually slower than a dictionary literal. Weird but tru
for param in params.split(';'):
for param in params:
if param and not param.isspace():
param = param.strip()
key, value = param, True
@@ -476,6 +468,7 @@ def _parse_content_type_header(header):
params_dict[key] = value
return content_type, params_dict
def get_encoding_from_headers(headers):
"""Returns encodings from given HTTP Header Dict.
-8
View File
@@ -472,14 +472,6 @@ def test_parse_dict_header(value, expected):
@pytest.mark.parametrize(
'value, expected', (
(
None,
None
),
(
'',
None
),
(
'application/xml',
('application/xml', dict())