def headers_to_str_headers(headers):
'''
Converts dict or tuple-based headers of bytes or str to
tuple-based headers of str, which is the python norm (pep 3333)
'''
ret = []
if isinstance(headers, collections_abc.Mapping):
h = headers.items()
else:
h = headers
if six.PY2: #pragma: no cover
return h
for tup in h:
k, v = tup
if isinstance(k, six.binary_type):
k = k.decode('iso-8859-1')
if isinstance(v, six.binary_type):
v = v.decode('iso-8859-1')
ret.append((k, v))
return ret
评论列表
文章目录