Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexcles authored and Ms2ger committed Oct 4, 2018
1 parent bd7e883 commit ce24036
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tools/wptserve/tests/functional/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion tools/wptserve/tests/functional/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion tools/wptserve/tests/functional/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" "))
5 changes: 3 additions & 2 deletions tools/wptserve/wptserve/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tools/wptserve/wptserve/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit ce24036

Please sign in to comment.