Skip to content
Myr

tuples too

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

authored by Kenneth Reitz · committed by Kenneth Reitz · parent b97b443 · Browse files · 1 file+25 added−8 removed
This commit

State

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

Diff stats

1 file+25 added−8 removed

  • other:+25 added−8 removed

1 file+25 added−8 removed

modified:requests/utils.py+25 added-8 removed
13 unmodified lines
14import re15import zlib161718def header_expand(header_dict):18def header_expand(headers):19 """Returns an HTTP Header value string from a dictionary.2021 Example expansion::2223 # Accept: text/x-dvi; q=.8; mxb=100000; mxt=5.0, text/x-c23 {'text/x-dvi': {'q': '.8', 'mxb': '100000', 'mxt': '5.0'}, 'text/x-c': {}}24 # Accept: text/x-dvi; q=.8; mxb=100000; mxt=5.0, text/x-c2526 (('text/x-dvi', {'q': '.8', 'mxb': '100000', 'mxt': '5.0'}), ('text/x-c', {}))27 # Accept: text/x-dvi; q=.8; mxb=100000; mxt=5.0, text/x-c28 """2930 collector = []3132 if isinstance(headers, dict):3334 # Assume header-tuple35 headers = headers.items()3637 # print headers3829 for i, (value, params) in enumerate(header_dict.items()):39 for i, (value, params) in enumerate(headers):4041 _params = []4232 for p_k, p_v in params.items():43 for (p_k, p_v) in params.items():4434 _params.append('{k}={v}'.format(k=p_k, v=p_v))45 _params.append('%s=%s' % (p_k, p_v))4647 collector.append(value)48 collector.append('; ')4950 if len(params):37 collector.append(value)38 collector.append('; ')5152 collector.append('; '.join(_params))5341 if not len(header_dict) == i+1:54 if not len(headers) == i+1:55 collector.append(', ')565758 if collector[-1] in (', ', '; '):59 del collector[-1]6061 return ''.join(collector)626364
151 unmodified lines