From 61de6fa1d65d4219c6798ab025e1beeca1247068 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 23 Jul 2016 11:55:27 -0700 Subject: fix test_view_urlencoded --- netlib/http/url.py | 1 + 1 file changed, 1 insertion(+) (limited to 'netlib/http/url.py') diff --git a/netlib/http/url.py b/netlib/http/url.py index 2fc6e7ee..1c8c007a 100644 --- a/netlib/http/url.py +++ b/netlib/http/url.py @@ -82,6 +82,7 @@ def unparse(scheme, host, port, path=""): def encode(s): + # type: (six.text_type, bytes) -> str """ Takes a list of (key, value) tuples and returns a urlencoded string. """ -- cgit v1.2.3 From a682074e9ed5e94683389f67cc192e6547d6310e Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 24 Jul 2016 19:06:49 -0700 Subject: improve query/path_components getter/setter --- netlib/http/url.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'netlib/http/url.py') diff --git a/netlib/http/url.py b/netlib/http/url.py index 1c8c007a..076854b9 100644 --- a/netlib/http/url.py +++ b/netlib/http/url.py @@ -82,19 +82,51 @@ def unparse(scheme, host, port, path=""): def encode(s): - # type: (six.text_type, bytes) -> str + # 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): -- cgit v1.2.3