def __init__(self, raw, errors='replace'):
"""Takes a string of type application/x-www-form-urlencoded.
"""
# urllib needs bytestrings in py2 and unicode strings in py3
raw_str = raw.encode('ascii') if PY2 else raw
self.decoded = _decode(unquote_plus(raw_str), errors=errors)
self.raw = raw
common_kw = dict(keep_blank_values=True, strict_parsing=False)
if PY2:
# in python 2 parse_qs does its own unquote_plus'ing ...
as_dict = parse_qs(raw_str, **common_kw)
# ... but doesn't decode to unicode.
for k, vals in list(as_dict.items()):
as_dict[_decode(k, errors=errors)] = [
_decode(v, errors=errors) for v in vals
]
else:
# in python 3 parse_qs does the decoding
as_dict = parse_qs(raw_str, errors=errors, **common_kw)
Mapping.__init__(self, as_dict)
评论列表
文章目录