diff options
| author | Simon Glass <sjg@chromium.org> | 2019-05-17 22:00:36 -0600 | 
|---|---|---|
| committer | Simon Glass <sjg@chromium.org> | 2019-07-10 16:52:58 -0600 | 
| commit | f6b64815dda947090f112bd4f7e0e430a16b48d7 (patch) | |
| tree | b5c766842c96dfec029dcef48251e0462c6f913f /tools/patman/tools.py | |
| parent | 2b6ed5e92e3b29fbfa3a966433d4bbc2ec1e9c58 (diff) | |
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.py | 25 | 
1 files changed, 25 insertions, 0 deletions
| diff --git a/tools/patman/tools.py b/tools/patman/tools.py index 976670ef006..bdc1953936c 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 | 
