Skip to content

Commit

Permalink
Python 3: Use bytes for status (web-platform-tests#24585)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziransun authored Jul 14, 2020
1 parent 2300345 commit 0d90501
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions cors/resources/304.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def main(request, response):
# what are you doing here? This should be a fresh request.
return error(u"If-None-Match on first request")
else:
status = 200, u"OK"
status = 200, b"OK"
headers.append((b"Access-Control-Allow-Origin", b"*"))
headers.append((b"Content-Type", b"text/plain"))
headers.append((b"Cache-Control", b"private, max-age=3, must-revalidate"))
headers.append((b"ETag", etag))
return status, headers, u"Success"
return status, headers, b"Success"
else: # even requests are the second in a pair, and should have a good INM.
if inm != etag:
# Bad browser.
Expand All @@ -58,5 +58,5 @@ def main(request, response):
headers.append((b"Access-Control-Expose-Headers", b"a"))
elif req_num == 8:
headers.append((b"Access-Control-Allow-Origin", b"other.origin.example:80"))
status = 304, u"Not Modified"
return status, headers, u""
status = 304, b"Not Modified"
return status, headers, b""
6 changes: 3 additions & 3 deletions cors/resources/cache-304.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
def main(request, response):
match = request.headers.get(b"If-None-Match", None)
if match is not None and match == b"mybestscript-v1":
response.status = (304, u"YEP")
return u""
response.status = (304, b"YEP")
return b""
response.headers.set(b"Access-Control-Allow-Origin", b"*")
response.headers.set(b"Cache-Control", b"must-revalidate")
response.headers.set(b"ETag", b"mybestscript-v1")
response.headers.set(b"Content-Type", b"text/javascript")
return u"function hep() { }"
return b"function hep() { }"
2 changes: 1 addition & 1 deletion cors/resources/cors-makeheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ def main(request, response):
body = json.dumps(headers)

if code:
return (code, u"StatusText"), [], body
return (code, b"StatusText"), [], body
else:
return body
2 changes: 1 addition & 1 deletion resource-timing/resources/cors-ahem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def main(request, response):
etag = b"123abc"
if etag == request.headers.get(b"If-None-Match", None):
response.headers.set(b"X-HTTP-STATUS", 304)
response.status = (304, u"Not Modified")
response.status = (304, b"Not Modified")
return u""

response.headers.set(b"Cache-Control", b"public, max-age=86400")
Expand Down
10 changes: 5 additions & 5 deletions resource-timing/resources/fake_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def main(request, response):
response.headers.set(b"Last-Modified", date)
if redirect:
response.headers.set(b"Location", redirect)
response.status = (302, u"Moved")
return u""
response.status = (302, b"Moved")
return b""

if ((match is not None and match == tag) or
(modified is not None and modified == date)):
response.status = (304, u"SUPERCOOL")
return u""
response.status = (304, b"SUPERCOOL")
return b""
else:
response.headers.set(b"Content-Type", b"text/plain")
return u"MAYBE NOT"
return b"MAYBE NOT"
2 changes: 1 addition & 1 deletion signed-exchange/resources/prefetch-test-cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def main(request, response):
stash_id = request.GET.first(b"id")
if request.server.stash.take(stash_id) is not None:
response.status = (404, u"Not Found")
response.status = (404, b"Not Found")
response.headers.set(b"Content-Type", b"text/plain")
return u"not found"
request.server.stash.put(stash_id, True)
Expand Down
4 changes: 3 additions & 1 deletion xhr/resources/inspect-headers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from six import PY3

from wptserve.utils import isomorphic_encode

def get_response(raw_headers, filter_value, filter_name):
result = b""
# Type of raw_headers is <httplib.HTTPMessage> in Python 2 and <http.client.HTTPMessage> in
Expand All @@ -11,7 +13,7 @@ def get_response(raw_headers, filter_value, filter_name):
# in Python 3.
if PY3:
header_list = [
(s + u'\r\n').encode("iso-8859-1") for s in raw_headers.as_string().splitlines() if s
isomorphic_encode(s + u'\r\n') for s in raw_headers.as_string().splitlines() if s
]
else:
header_list = raw_headers.headers
Expand Down

0 comments on commit 0d90501

Please sign in to comment.