Skip to content

Commit cbcf282

Browse files
committed
Go straight to a bytestring
1 parent 74b7541 commit cbcf282

1 file changed

Lines changed: 20 additions & 26 deletions

File tree

Twitter_API/binascii.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,27 @@
44

55
PAD = '='
66

7-
#pylint:disable=bad-whitespace,invalid-name
8-
table_a2b_base64 = [
9-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
10-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
11-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
12-
52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1, # Note PAD->-1 here
13-
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
14-
15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
15-
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
16-
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1,
17-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
18-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
19-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
20-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
21-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
22-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
23-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
24-
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
25-
]
26-
#pylint:enable=bad-whitespace
7+
#pylint:disable=bad-whitespace,invalid-name,bad-continuation
8+
table_a2b_base64 = bytes([
9+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
10+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
11+
255,255,255,255, 255,255,255,255, 255,255,255, 62, 255,255,255, 63,
12+
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255, 255,255,255,255,
13+
255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
14+
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255, 255,255,255,255,
15+
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
16+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255, 255,255,255,255,
17+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
18+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
19+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
20+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
21+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
22+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
23+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
24+
255,255,255,255, 255,255,255,255, 255,255,255,255, 255,255,255,255,
25+
])
26+
#pylint:enable=bad-whitespace,bad-continuation
2727

28-
def _transform(n):
29-
if n == -1:
30-
return '\xff'
31-
return chr(n)
32-
33-
table_a2b_base64 = ''.join(map(_transform, table_a2b_base64))
3428
assert len(table_a2b_base64) == 256
3529

3630
def a2b_base64(ascii_data):

0 commit comments

Comments
 (0)