mirror of
https://github.com/servo/servo.git
synced 2025-08-16 10:55:34 +01:00
Update web-platform-tests to revision fcb3495f6321b32f607cabcbe0e63a918f48d348
This commit is contained in:
parent
7824b6d0de
commit
808edd90a4
74 changed files with 357 additions and 129 deletions
|
@ -1,3 +1,4 @@
|
|||
from six import PY3
|
||||
from wptserve.utils import isomorphic_encode
|
||||
|
||||
# Outputs the request body, with controls and non-ASCII bytes escaped
|
||||
|
@ -5,13 +6,13 @@ from wptserve.utils import isomorphic_encode
|
|||
# As a convenience, CRLF newlines are left as is.
|
||||
|
||||
def escape_byte(byte):
|
||||
# Iterating over a binary string gives different types in Py2 & Py3.
|
||||
# Py3: bytes -> int
|
||||
# Py2: str -> str (of length 1), so we convert it to int
|
||||
code = byte if type(byte) is int else ord(byte)
|
||||
if 0 <= code <= 0x1F or code >= 0x7F:
|
||||
return b"\\x%02x" % code
|
||||
if code == ord(b"\\"):
|
||||
# We want a single-char binary string, but in Python 3 we may get an int
|
||||
# from iterating over bytes.
|
||||
if PY3:
|
||||
byte = bytes([byte])
|
||||
if b"\0" <= byte <= b"\x1F" or byte >= b"\x7F":
|
||||
return b"\\x%02x" % ord(byte)
|
||||
if byte == b"\\":
|
||||
return b"\\\\"
|
||||
return byte
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue