Changes in tools/xstruct.py [67435b1:cc1a727] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/xstruct.py
r67435b1 rcc1a727 32 32 33 33 import struct 34 import sys35 34 import types 36 35 37 # Handle long integer conversions nicely in both Python 2 and Python 338 integer_types = (int, long) if sys.version < '3' else (int,)39 40 # Ensure that 's' format for struct receives correct data type depending41 # on Python version (needed due to different way to encode into bytes)42 ensure_string = \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)46 47 36 ranges = { 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),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), 56 45 } 57 46 … … 85 74 args.append(item) 86 75 else: 87 if (fmt == "s"):88 value = ensure_string(value)89 76 check_range(variable, fmt, value) 90 77 args.append(value)
Note:
See TracChangeset
for help on using the changeset viewer.