37
# Handle long integer conversions nicely in both Python 2 and Python 3
38
integer_types = (int, long) if sys.version < '3' else (int,)
40
# Ensure that 's' format for struct receives correct data type depending
41
# on Python version (needed due to different way to encode into bytes)
43
(lambda value: value if type(value) is str else bytes(value)) \
44
if sys.version < '3' else \
45
(lambda value: bytes(value, 'ascii') if type(value) is str else value)
37
'B': ((int, long), 0x00, 0xff),
38
'H': ((int, long), 0x0000, 0xffff),
39
'L': ((int, long), 0x00000000, 0xffffffff),
40
'Q': ((int, long), 0x0000000000000000, 0xffffffffffffffff),
41
'b': ((int, long), -0x80, 0x7f),
42
'h': ((int, long), -0x8000, 0x7fff),
43
'l': ((int, long), -0x80000000, 0x7fffffff) ,
44
'q': ((int, long), -0x8000000000000000, 0x7fffffffffffffff),
48
'B': (integer_types, 0x00, 0xff),
49
'H': (integer_types, 0x0000, 0xffff),
50
'L': (integer_types, 0x00000000, 0xffffffff),
51
'Q': (integer_types, 0x0000000000000000, 0xffffffffffffffff),
52
'b': (integer_types, -0x80, 0x7f),
53
'h': (integer_types, -0x8000, 0x7fff),
54
'l': (integer_types, -0x80000000, 0x7fffffff) ,
55
'q': (integer_types, -0x8000000000000000, 0x7fffffffffffffff),
47
58
def check_range(varname, fmt, value):