summaryrefslogtreecommitdiff
path: root/tools/patman/tools.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2019-05-15 00:53:47 +0300
committerSimon Glass <sjg@chromium.org>2019-07-11 01:52:58 +0300
commite6d85ff9f239a338748871b93ed11f066609e869 (patch)
tree5add11f4bc83ae9a6c2b9fe57157cb6031ccd16b /tools/patman/tools.py
parent6d1d6418645229d5de2f8c52bf6a9ce6a345c2a1 (diff)
downloadu-boot-e6d85ff9f239a338748871b93ed11f066609e869.tar.xz
binman: Handle repeated bytes for Python 3
The method of multiplying a character by a number works well for creating a repeated string in Python 2. But in Python 3 we need to use bytes() instead, to avoid unicode problems, since 'bytes' is no-longer just an alias of 'str'. Create a function to handle this detail and call it from the relevant places in binman. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/tools.py')
-rw-r--r--tools/patman/tools.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 1df8f2ecd2..0ad0fb9705 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -7,6 +7,7 @@ import command
import glob
import os
import shutil
+import sys
import tempfile
import tout
@@ -239,3 +240,21 @@ def WriteFile(fname, data):
#(fname, len(data), len(data)))
with open(Filename(fname), 'wb') as fd:
fd.write(data)
+
+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
+
+ 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