|
|
@ -91,11 +91,9 @@ except ImportError:
|
|
|
|
compat_subprocess_get_DEVNULL = lambda: open(os.path.devnull, 'w')
|
|
|
|
compat_subprocess_get_DEVNULL = lambda: open(os.path.devnull, 'w')
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from urllib.parse import parse_qs as compat_parse_qs
|
|
|
|
from urllib.parse import unquote as compat_urllib_parse_unquote
|
|
|
|
except ImportError: # Python 2
|
|
|
|
except ImportError:
|
|
|
|
# HACK: The following is the correct parse_qs implementation from cpython 3's stdlib.
|
|
|
|
def compat_urllib_parse_unquote(string, encoding='utf-8', errors='replace'):
|
|
|
|
# Python 2's version is apparently totally broken
|
|
|
|
|
|
|
|
def _unquote(string, encoding='utf-8', errors='replace'):
|
|
|
|
|
|
|
|
if string == '':
|
|
|
|
if string == '':
|
|
|
|
return string
|
|
|
|
return string
|
|
|
|
res = string.split('%')
|
|
|
|
res = string.split('%')
|
|
|
@ -130,6 +128,13 @@ except ImportError: # Python 2
|
|
|
|
string += pct_sequence.decode(encoding, errors)
|
|
|
|
string += pct_sequence.decode(encoding, errors)
|
|
|
|
return string
|
|
|
|
return string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from urllib.parse import parse_qs as compat_parse_qs
|
|
|
|
|
|
|
|
except ImportError: # Python 2
|
|
|
|
|
|
|
|
# HACK: The following is the correct parse_qs implementation from cpython 3's stdlib.
|
|
|
|
|
|
|
|
# Python 2's version is apparently totally broken
|
|
|
|
|
|
|
|
|
|
|
|
def _parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
|
|
|
|
def _parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
|
|
|
|
encoding='utf-8', errors='replace'):
|
|
|
|
encoding='utf-8', errors='replace'):
|
|
|
|
qs, _coerce_result = qs, unicode
|
|
|
|
qs, _coerce_result = qs, unicode
|
|
|
@ -149,10 +154,12 @@ except ImportError: # Python 2
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
if len(nv[1]) or keep_blank_values:
|
|
|
|
if len(nv[1]) or keep_blank_values:
|
|
|
|
name = nv[0].replace('+', ' ')
|
|
|
|
name = nv[0].replace('+', ' ')
|
|
|
|
name = _unquote(name, encoding=encoding, errors=errors)
|
|
|
|
name = compat_urllib_parse_unquote(
|
|
|
|
|
|
|
|
name, encoding=encoding, errors=errors)
|
|
|
|
name = _coerce_result(name)
|
|
|
|
name = _coerce_result(name)
|
|
|
|
value = nv[1].replace('+', ' ')
|
|
|
|
value = nv[1].replace('+', ' ')
|
|
|
|
value = _unquote(value, encoding=encoding, errors=errors)
|
|
|
|
value = compat_urllib_parse_unquote(
|
|
|
|
|
|
|
|
value, encoding=encoding, errors=errors)
|
|
|
|
value = _coerce_result(value)
|
|
|
|
value = _coerce_result(value)
|
|
|
|
r.append((name, value))
|
|
|
|
r.append((name, value))
|
|
|
|
return r
|
|
|
|
return r
|
|
|
|