Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by dbairaktaris1 · committed by dbairaktaris1 · parent 80a7904 · Browse files · 3 files+19 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+19 added−10 removed

  • tests:+8 added−4 removed
  • other:+11 added−6 removed

3 files+19 added−10 removed

modified:requests/utils.py+10 added-6 removed
454 unmodified lines
455 """456457 tokens = header.split(';')458 content_type, params = tokens[0].strip(), tokens[1:]459 params_dict = {} 459 params_dict = {}460 items_to_strip = "\"' "461462 for param in params:462 if param and not param.isspace():463 param = param.strip()463 param = param.strip()464 if param:465 key, value = param, True465 if '=' in param:466 param_tokens = [x.strip('\'" ') for x in param.split('=', 1)]467 key, value = param_tokens[0], param_tokens[1]466 index_of_equals = param.find("=")467 if index_of_equals != -1:468 before_equals = slice(0, index_of_equals)469 after_equals = slice(index_of_equals + 1, len(param))470 key = param[before_equals].strip(items_to_strip)471 value = param[after_equals].strip(items_to_strip)472 params_dict[key] = value473 return content_type, params_dict474475
499 unmodified lines
modified:tests/test_utils.py+8 added-4 removed
472 unmodified lines
473@pytest.mark.parametrize(474 'value, expected', (475 (476 'application/xml',477 ('application/xml', dict())477 ('application/xml', {})478 ),479 (480 'application/json ; charset=utf-8',481 ('application/json', {'charset': 'utf-8'})482 ),483 (484 'text/plain',485 ('text/plain', dict())485 ('text/plain', {})486 ),487 (488 'multipart/form-data; boundary = something ; \'boundary2=something_else\' ; no_equals ',489 ('multipart/form-data', {'boundary': 'something', 'boundary2': 'something_else', 'no_equals': True})490 ),491 (492 'multipart/form-data; boundary = something ; \"boundary2=something_else\" ; no_equals ',493 ('multipart/form-data', {'boundary': 'something', 'boundary2': 'something_else', 'no_equals': True})494 ),495 (492 'application/json ;; ; ',493 ('application/json', dict())496 'application/json ; ; ',497 ('application/json', {})498 )499 ))500def test__parse_content_type_header(value, expected):501 assert _parse_content_type_header(value) == expected
247 unmodified lines
modified:AUTHORS.rst+1 added
179 unmodified lines
180- Matt Liu <liumatt@gmail.com> (`@mlcrazy <https://github.com/mlcrazy>`_)181- Taylor Hoff <primdevs@protonmail.com> (`@PrimordialHelios <https://github.com/PrimordialHelios>`_)182- Arthur Vigil (`@ahvigil <https://github.com/ahvigil>`_)183- Nehal J Wani (`@nehaljwani <https://github.com/nehaljwani>`_)184- Demetrios Bairaktaris (`@DemetriosBairaktaris <https://github.com/demetriosbairaktaris>`_)