Mesa (master): python: Open file in binary mode

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 1 13:57:23 UTC 2018


Module: Mesa
Branch: master
Commit: c24d82696867da13360f23abecf130e839da8b0f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c24d82696867da13360f23abecf130e839da8b0f

Author: Mathieu Bridon <bochecha at daitauha.fr>
Date:   Tue Jun 26 08:52:08 2018 +0200

python: Open file in binary mode

The XML parser wants byte strings, not unicode strings.

In both Python 2 and 3, opening a file without specifying the mode will
open it for reading in text mode ('r').

On Python 2, the read() method of the file object will return byte
strings, while on Python 3 it will return unicode strings.

Explicitly specifying the binary mode ('rb') makes the behaviour
identical in both Python 2 and 3, returning what the XML parser
expects.

Signed-off-by: Mathieu Bridon <bochecha at daitauha.fr>
Reviewed-by: Eric Engestrom <eric.engestrom at intel.com>
Reviewed-by: Dylan Baker <dylan at pnwbakers.com>

---

 src/intel/genxml/gen_bits_header.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/intel/genxml/gen_bits_header.py b/src/intel/genxml/gen_bits_header.py
index e31e9ff103..dcd6ccb7d9 100644
--- a/src/intel/genxml/gen_bits_header.py
+++ b/src/intel/genxml/gen_bits_header.py
@@ -282,7 +282,7 @@ class XmlParser(object):
         self.container = None
 
     def parse(self, filename):
-        with open(filename) as f:
+        with open(filename, 'rb') as f:
             self.parser.ParseFile(f)
 
     def start_element(self, name, attrs):




More information about the mesa-commit mailing list