mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
implement changes after code review
This commit is contained in:
+5
-12
@@ -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.
|
||||
|
||||
|
||||
@@ -472,14 +472,6 @@ def test_parse_dict_header(value, expected):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'value, expected', (
|
||||
(
|
||||
None,
|
||||
None
|
||||
),
|
||||
(
|
||||
'',
|
||||
None
|
||||
),
|
||||
(
|
||||
'application/xml',
|
||||
('application/xml', dict())
|
||||
|
||||
Reference in New Issue
Block a user