Changeset 67435b1 in mainline


Ignore:
Timestamp:
2012-05-22T10:31:25Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a58bc8b, df3f85f
Parents:
c4b0317
Message:

Make tools work with Python 3 again

Location:
tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tools/mkfat.py

    rc4b0317 r67435b1  
    189189        "Filter FAT legal characters"
    190190       
    191         filtered_name = ''
     191        filtered_name = b''
    192192        filtered = False
    193193       
     
    205205       
    206206        ascii_name, lfn = fat_lchars(name)
    207         ascii_parts = ascii_name.split('.')
     207        # Splitting works only on strings, not on bytes
     208        ascii_parts = ascii_name.decode('utf8').split('.')
    208209       
    209210        short_name = ''
     
    444445        extra_bytes = int(sys.argv[1])
    445446       
    446         path = os.path.abspath(sys.argv[2].decode())
     447        path = os.path.abspath(sys.argv[2])
    447448        if (not os.path.isdir(path)):
    448449                print("<PATH> must be a directory")
  • tools/xstruct.py

    rc4b0317 r67435b1  
    3535import types
    3636
     37# Handle long integer conversions nicely in both Python 2 and Python 3
    3738integer_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)
     42ensure_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)
    3846
    3947ranges = {
     
    7785                                        args.append(item)
    7886                        else:
     87                                if (fmt == "s"):
     88                                        value = ensure_string(value)
    7989                                check_range(variable, fmt, value)
    8090                                args.append(value)             
Note: See TracChangeset for help on using the changeset viewer.