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