1
2
3
4 """Miscellaneous functions to mask Python version differences."""
5
6 import sys
7 import os
8 import math
9 import binascii
10
11 if sys.version_info >= (3,0):
12
14
15
16
17
18
20
23
24
25
26
27
29 try:
30 b = bytearray(binascii.a2b_hex(bytearray(s, "ascii")))
31 except Exception as e:
32 raise SyntaxError("base16 error: %s" % e)
33 return b
34
36 try:
37 b = bytearray(binascii.a2b_base64(bytearray(s, "ascii")))
38 except Exception as e:
39 raise SyntaxError("base64 error: %s" % e)
40 return b
41
43 return binascii.b2a_hex(b).decode("ascii")
44
47
49 return base64.b32encode(b).decode("ascii")
50
51
53 return b.decode(encoding)
54
56 return sys.stdin.buffer.read()
57
58 else:
59
60
61 if sys.version_info < (2,7):
63 else:
65
66
67
69
71 try:
72 b = bytearray(binascii.a2b_hex(s))
73 except Exception as e:
74 raise SyntaxError("base16 error: %s" % e)
75 return b
76
78 try:
79 b = bytearray(binascii.a2b_base64(s))
80 except Exception as e:
81 raise SyntaxError("base64 error: %s" % e)
82 return b
83
86
89
91 return base64.b32encode(str(b))
92
93 import traceback
97