diff --git a/tools/wptserve/tests/functional/base.py b/tools/wptserve/tests/functional/base.py index 741ab0bcb74575..f8331f5086d317 100644 --- a/tools/wptserve/tests/functional/base.py +++ b/tools/wptserve/tests/functional/base.py @@ -75,7 +75,7 @@ def request(self, path, query=None, method="GET", headers=None, body=None, auth= req.add_data(body) if auth is not None: - req.add_header("Authorization", b"Basic %s" % base64.b64encode(("%s:%s" % auth).encode("utf-8"))) + req.add_header("Authorization", b"Basic %s" % base64.b64encode((b"%s:%s" % auth))) return urlopen(req) diff --git a/tools/wptserve/tests/functional/test_pipes.py b/tools/wptserve/tests/functional/test_pipes.py index 7739af5e26e17c..fdac4537d64fb5 100644 --- a/tools/wptserve/tests/functional/test_pipes.py +++ b/tools/wptserve/tests/functional/test_pipes.py @@ -115,7 +115,6 @@ def test_sub_uuid(self): def test_sub_var(self): resp = self.request("/sub_var.sub.txt") port = self.server.port - print(port, type(port)) expected = b"localhost %d A %d B localhost C" % (port, port) self.assertEqual(resp.read().rstrip(), expected) diff --git a/tools/wptserve/tests/functional/test_request.py b/tools/wptserve/tests/functional/test_request.py index 3063a0311810b0..276fab1a060334 100644 --- a/tools/wptserve/tests/functional/test_request.py +++ b/tools/wptserve/tests/functional/test_request.py @@ -142,6 +142,12 @@ def handler(request, response): route = ("GET", "/test/test_auth", handler) self.server.router.register(*route) - resp = self.request(route[1], auth=("test", "PASS")) + + resp = self.request(route[1], auth=(b"test", b"PASS")) self.assertEqual(200, resp.getcode()) self.assertEqual([b"test", b"PASS"], resp.read().split(b" ")) + + encoded_text = u"どうも".encode("shift-jis") + resp = self.request(route[1], auth=(encoded_text, encoded_text)) + self.assertEqual(200, resp.getcode()) + self.assertEqual([encoded_text, encoded_text], resp.read().split(b" ")) diff --git a/tools/wptserve/wptserve/pipes.py b/tools/wptserve/wptserve/pipes.py index 737b14d11cff82..102cafb30866cb 100644 --- a/tools/wptserve/wptserve/pipes.py +++ b/tools/wptserve/wptserve/pipes.py @@ -489,8 +489,9 @@ def config_replacement(match): escape_func = {"html": lambda x:escape(x, quote=True), "none": lambda x:x}[escape_type] - #Should possibly support escaping for other contexts e.g. script - #TODO: read the encoding of the response + # Should possibly support escaping for other contexts e.g. script + # TODO: read the encoding of the response + # cgi.escape() only takes text strings in Python 3. if isinstance(value, binary_type): value = value.decode("utf-8") elif isinstance(value, int): diff --git a/tools/wptserve/wptserve/request.py b/tools/wptserve/wptserve/request.py index bcd39dd5b9c9f2..990774cbb9e6a1 100644 --- a/tools/wptserve/wptserve/request.py +++ b/tools/wptserve/wptserve/request.py @@ -377,8 +377,8 @@ class RequestHeaders(dict): """Read-only dictionary-like API for accessing request headers. Unlike BaseHTTPRequestHandler.headers, this class always returns all - headers with the same name (separated by commas). Besides, this class - ensures all keys (i.e. names of headers) and values have binary type. + headers with the same name (separated by commas). And it ensures all keys + (i.e. names of headers) and values have binary type. """ def __init__(self, items): for header in items.keys():