summaryrefslogtreecommitdiff
path: root/tools/patman/tools.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2019-05-18 07:00:36 +0300
committerSimon Glass <sjg@chromium.org>2019-07-11 01:52:58 +0300
commitf6b64815dda947090f112bd4f7e0e430a16b48d7 (patch)
treeb5c766842c96dfec029dcef48251e0462c6f913f /tools/patman/tools.py
parent2b6ed5e92e3b29fbfa3a966433d4bbc2ec1e9c58 (diff)
downloadu-boot-f6b64815dda947090f112bd4f7e0e430a16b48d7.tar.xz
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 <sjg@chromium.org>
Diffstat (limited to 'tools/patman/tools.py')
-rw-r--r--tools/patman/tools.py25
1 files changed, 25 insertions, 0 deletions
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