Changes in tools/xstruct.py [67435b1:cc1a727] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/xstruct.py

    r67435b1 rcc1a727  
    3232
    3333import struct
    34 import sys
    3534import types
    3635
    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 
    4736ranges = {
    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),
    5645}
    5746
     
    8574                                        args.append(item)
    8675                        else:
    87                                 if (fmt == "s"):
    88                                         value = ensure_string(value)
    8976                                check_range(variable, fmt, value)
    9077                                args.append(value)             
Note: See TracChangeset for help on using the changeset viewer.