diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-07-25 15:16:16 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-07-25 15:16:16 -0700 |
commit | 79ebcb046e8669f80357a6c3046ec76c6adf49be (patch) | |
tree | 441981a16f1be1e620584e4a47f41767ce5585b2 /netlib/http/url.py | |
parent | 3254595584e1d711e7ae292ad34753a52f7a0fc1 (diff) | |
parent | 56796aeda25dda66621ce78af227ff46049ef811 (diff) | |
download | mitmproxy-79ebcb046e8669f80357a6c3046ec76c6adf49be.tar.gz mitmproxy-79ebcb046e8669f80357a6c3046ec76c6adf49be.tar.bz2 mitmproxy-79ebcb046e8669f80357a6c3046ec76c6adf49be.zip |
Merge remote-tracking branch 'origin/master' into flow_editing_v2
Diffstat (limited to 'netlib/http/url.py')
-rw-r--r-- | netlib/http/url.py | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/netlib/http/url.py b/netlib/http/url.py index 2fc6e7ee..076854b9 100644 --- a/netlib/http/url.py +++ b/netlib/http/url.py @@ -82,18 +82,51 @@ def unparse(scheme, host, port, path=""): def encode(s): + # type: Sequence[Tuple[str,str]] -> str """ Takes a list of (key, value) tuples and returns a urlencoded string. """ - s = [tuple(i) for i in s] - return urllib.parse.urlencode(s, False) + if six.PY2: + return urllib.parse.urlencode(s, False) + else: + return urllib.parse.urlencode(s, False, errors="surrogateescape") def decode(s): """ - Takes a urlencoded string and returns a list of (key, value) tuples. + Takes a urlencoded string and returns a list of surrogate-escaped (key, value) tuples. + """ + if six.PY2: + return urllib.parse.parse_qsl(s, keep_blank_values=True) + else: + return urllib.parse.parse_qsl(s, keep_blank_values=True, errors='surrogateescape') + + +def quote(b, safe="/"): + """ + Returns: + An ascii-encodable str. + """ + # type: (str) -> str + if six.PY2: + return urllib.parse.quote(b, safe=safe) + else: + return urllib.parse.quote(b, safe=safe, errors="surrogateescape") + + +def unquote(s): """ - return urllib.parse.parse_qsl(s, keep_blank_values=True) + Args: + s: A surrogate-escaped str + Returns: + A surrogate-escaped str + """ + # type: (str) -> str + + if six.PY2: + return urllib.parse.unquote(s) + else: + return urllib.parse.unquote(s, errors="surrogateescape") def hostport(scheme, host, port): |