From f6b64815dda947090f112bd4f7e0e430a16b48d7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 17 May 2019 22:00:36 -0600 Subject: dtoc: Use byte type instead of str in fdt In Python 3 bytes and str are separate types. Use bytes to ensure that the code functions correctly with Python 3. Signed-off-by: Simon Glass --- tools/patman/tools.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tools/patman/tools.py') diff --git a/tools/patman/tools.py b/tools/patman/tools.py index 976670ef00..bdc1953936 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -317,3 +317,28 @@ def ToChar(byte): 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]) + +def ToBytes(string): + """Convert a str type into a bytes type + + Args: + string: string to convert value + + Returns: + Python 3: A bytes type + Python 2: A string type + """ + if sys.version_info[0] >= 3: + return string.encode('utf-8') + return string -- cgit