[Mesa-dev] [PATCH 13/26] python: Explicitly use byte strings
Eric Engestrom
eric.engestrom at intel.com
Thu Jul 5 15:47:41 UTC 2018
On Thursday, 2018-07-05 15:17:44 +0200, Mathieu Bridon wrote:
> In both Python 2 and 3, zlib.Compress.compress() takes a byte string,
> and returns a byte string as well.
>
> In Python 2, the script was working because:
>
> 1. string literalls were byte strings;
> 2. opening a file in unicode mode, reading from it, then passing the
> unicode string to compress() would automatically encode to a byte
> string;
>
> On Python 3, the above two points are not valid any more, so:
>
> 1. zlib.Compress.compress() refuses the passed unicode string;
> 2. compressed_data, defined as an empty unicode string literal, can't be
> concatenated with the byte string returned by compress();
>
> This commit fixes this by explicitly using byte strings where
> appropriate, so that the script works on both Python 2 and 3.
>
> Signed-off-by: Mathieu Bridon <bochecha at daitauha.fr>
Reviewed-by: Eric Engestrom <eric.engestrom at intel.com>
> ---
> src/intel/genxml/gen_zipped_file.py | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/intel/genxml/gen_zipped_file.py b/src/intel/genxml/gen_zipped_file.py
> index af2008bea0..6d8daf4d69 100644
> --- a/src/intel/genxml/gen_zipped_file.py
> +++ b/src/intel/genxml/gen_zipped_file.py
> @@ -42,10 +42,10 @@ def main():
> print("} genxml_files_table[] = {")
>
> xml_offset = 0
> - compressed_data = ''
> + compressed_data = b''
> for i in range(1, len(sys.argv)):
> filename = sys.argv[i]
> - xml = open(filename).read()
> + xml = open(filename, "rb").read()
> xml_length = len(xml)
> root = et.fromstring(xml)
>
> --
> 2.17.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list