Skip to content

Commit 1783c9b

Browse files
author
Andreu Botella
authored
Update url/resources/percent-encoding.py to work on Python 3 (#26643)
1 parent 651219c commit 1783c9b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

url/resources/percent-encoding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
def numeric_references(input):
88
output = b""
99
for cp in input:
10-
output += b"&#x" + format(ord(cp), b"X") + b";"
10+
output += b"&#x" + format(ord(cp), u"X").encode(u"utf-8") + b";"
1111
return output
1212

1313
def main(request, response):
1414
# Undo the "magic" space with + replacement as otherwise base64 decoding will fail.
15-
value = request.GET.first(b"value").replace(" ", "+")
15+
value = request.GET.first(b"value").replace(b" ", b"+")
1616
encoding = request.GET.first(b"encoding")
1717

18-
output_value = numeric_references(base64.b64decode(value).decode(b"utf-8"))
18+
output_value = numeric_references(base64.b64decode(value).decode(u"utf-8"))
1919
return (
2020
[(b"Content-Type", b"text/html;charset=" + encoding)],
2121
b"""<!doctype html>

0 commit comments

Comments
 (0)