Skip to content

Commit

Permalink
Replace int2byte from six with string literals or bytes(...) (web-pla…
Browse files Browse the repository at this point in the history
…tform-tests#28748)

The following expressions were evaluated as True in a Python 3.8.2 shell
to gain confidence:
```py
from six import int2byte
b"".join(int2byte(byte) for byte in range(255)) == bytes(range(255))
int2byte(0xff) == b"\xff"
int2byte(0x83) + int2byte(0x65) + int2byte(0x83) + int2byte(0x58) + int2byte(0x83) + int2byte(0x67) == bytes([0x83, 0x65, 0x83, 0x58, 0x83, 0x67])
b'<' + int2byte(0xff) + b'/>' == b'<\xff/>'
```
  • Loading branch information
foolip authored Apr 29, 2021
1 parent 765450f commit 9c4b5c0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
4 changes: 1 addition & 3 deletions encoding/resources/single-byte-raw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from six import int2byte

def main(request, response):
response.headers.set(b"Content-Type", b"text/plain;charset=" + request.GET.first(b"label"))
response.content = b"".join(int2byte(byte) for byte in range(255))
response.content = bytes(range(255))
4 changes: 1 addition & 3 deletions xhr/resources/invalid-utf8-html.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from six import int2byte

def main(request, response):
headers = [(b"Content-type", b"text/html;charset=utf-8")]
content = int2byte(0xff)
content = b"\xff"

return headers, content
4 changes: 1 addition & 3 deletions xhr/resources/shift-jis-html.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from six import int2byte

def main(request, response):
headers = [(b"Content-type", b"text/html;charset=shift-jis")]
# Shift-JIS bytes for katakana TE SU TO ('test')
content = int2byte(0x83) + int2byte(0x65) + int2byte(0x83) + int2byte(0x58) + int2byte(0x83) + int2byte(0x67)
content = bytes([0x83, 0x65, 0x83, 0x58, 0x83, 0x67])

return headers, content
4 changes: 1 addition & 3 deletions xhr/resources/win-1252-xml.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from six import int2byte

def main(request, response):
headers = [(b"Content-type", b"application/xml;charset=windows-1252")]
content = b'<' + int2byte(0xff) + b'/>'
content = b'<\xff/>'

return headers, content

0 comments on commit 9c4b5c0

Please sign in to comment.