Continue to refactor, remove list comprehension, add double quotes test case.

This commit is contained in:
dbairaktaris1
2018-01-04 10:30:50 -06:00
parent 80a790443e
commit cb0914407b
3 changed files with 19 additions and 10 deletions
+1
View File
@@ -181,3 +181,4 @@ Patches and Suggestions
- Taylor Hoff <primdevs@protonmail.com> (`@PrimordialHelios <https://github.com/PrimordialHelios>`_)
- Arthur Vigil (`@ahvigil <https://github.com/ahvigil>`_)
- Nehal J Wani (`@nehaljwani <https://github.com/nehaljwani>`_)
- Demetrios Bairaktaris (`@DemetriosBairaktaris <https://github.com/demetriosbairaktaris>`_)
+10 -6
View File
@@ -456,15 +456,19 @@ def _parse_content_type_header(header):
tokens = header.split(';')
content_type, params = tokens[0].strip(), tokens[1:]
params_dict = {}
params_dict = {}
items_to_strip = "\"' "
for param in params:
if param and not param.isspace():
param = param.strip()
param = param.strip()
if param:
key, value = param, True
if '=' in param:
param_tokens = [x.strip('\'" ') for x in param.split('=', 1)]
key, value = param_tokens[0], param_tokens[1]
index_of_equals = param.find("=")
if index_of_equals != -1:
before_equals = slice(0, index_of_equals)
after_equals = slice(index_of_equals + 1, len(param))
key = param[before_equals].strip(items_to_strip)
value = param[after_equals].strip(items_to_strip)
params_dict[key] = value
return content_type, params_dict
+8 -4
View File
@@ -474,7 +474,7 @@ def test_parse_dict_header(value, expected):
'value, expected', (
(
'application/xml',
('application/xml', dict())
('application/xml', {})
),
(
'application/json ; charset=utf-8',
@@ -482,15 +482,19 @@ def test_parse_dict_header(value, expected):
),
(
'text/plain',
('text/plain', dict())
('text/plain', {})
),
(
'multipart/form-data; boundary = something ; \'boundary2=something_else\' ; no_equals ',
('multipart/form-data', {'boundary': 'something', 'boundary2': 'something_else', 'no_equals': True})
),
(
'application/json ;; ; ',
('application/json', dict())
'multipart/form-data; boundary = something ; \"boundary2=something_else\" ; no_equals ',
('multipart/form-data', {'boundary': 'something', 'boundary2': 'something_else', 'no_equals': True})
),
(
'application/json ; ; ',
('application/json', {})
)
))
def test__parse_content_type_header(value, expected):