diff options
author | Tom Rini <trini@konsulko.com> | 2020-12-14 18:57:57 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-12-14 18:57:57 -0500 |
commit | 8351a29d2df18c92d8e365cfa848218c3859f3d2 (patch) | |
tree | 5d29001be9accfb8029df9d9ed78fba196ee07b9 /tools/patman/tools.py | |
parent | ddaa94978583d07ec515e7226e397221d8cc44c8 (diff) | |
parent | b7bbd553de0d9752f919dfc616f560f6f2504c14 (diff) |
Merge tag 'dm-pull-14dec20' of git://git.denx.de/u-boot-dm into next
Driver model tidy-up for livetree
Driver model big rename for consistency
Python 3 clean-ups for patman
Update sandbox serial driver to use membuff
Diffstat (limited to 'tools/patman/tools.py')
-rw-r--r-- | tools/patman/tools.py | 85 |
1 files changed, 3 insertions, 82 deletions
diff --git a/tools/patman/tools.py b/tools/patman/tools.py index bbb157da87..00c7013924 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -414,8 +414,6 @@ def WriteFile(fname, data, binary=True): def GetBytes(byte, size): """Get a string of bytes of a given size - This handles the unfortunate different between Python 2 and Python 2. - Args: byte: Numeric byte value to use size: Size of bytes/string to return @@ -423,81 +421,7 @@ def GetBytes(byte, size): Returns: A bytes type with 'byte' repeated 'size' times """ - if sys.version_info[0] >= 3: - data = bytes([byte]) * size - else: - data = chr(byte) * size - return data - -def ToUnicode(val): - """Make sure a value is a unicode string - - This allows some amount of compatibility between Python 2 and Python3. For - the former, it returns a unicode object. - - Args: - val: string or unicode object - - Returns: - unicode version of val - """ - if sys.version_info[0] >= 3: - return val - return val if isinstance(val, unicode) else val.decode('utf-8') - -def FromUnicode(val): - """Make sure a value is a non-unicode string - - This allows some amount of compatibility between Python 2 and Python3. For - the former, it converts a unicode object to a string. - - Args: - val: string or unicode object - - Returns: - non-unicode version of val - """ - if sys.version_info[0] >= 3: - return val - return val if isinstance(val, str) else val.encode('utf-8') - -def ToByte(ch): - """Convert a character to an ASCII value - - This is useful because in Python 2 bytes is an alias for str, but in - Python 3 they are separate types. This function converts the argument to - an ASCII value in either case. - - Args: - ch: A string (Python 2) or byte (Python 3) value - - Returns: - integer ASCII value for ch - """ - return ord(ch) if type(ch) == str else ch - -def ToChar(byte): - """Convert a byte to a character - - This is useful because in Python 2 bytes is an alias for str, but in - Python 3 they are separate types. This function converts an ASCII value to - a value with the appropriate type in either case. - - Args: - byte: A byte or str value - """ - return chr(byte) if type(byte) != str else byte - -def ToChars(byte_list): - """Convert a list of bytes to a str/bytes type - - Args: - byte_list: List of ASCII values representing the string - - Returns: - string made by concatenating all the ASCII values - """ - return ''.join([chr(byte) for byte in byte_list]) + return bytes([byte]) * size def ToBytes(string): """Convert a str type into a bytes type @@ -506,12 +430,9 @@ def ToBytes(string): string: string to convert Returns: - Python 3: A bytes type - Python 2: A string type + A bytes type """ - if sys.version_info[0] >= 3: - return string.encode('utf-8') - return string + return string.encode('utf-8') def ToString(bval): """Convert a bytes type into a str type |