python: Open file in binary mode
authorMathieu Bridon <bochecha@daitauha.fr>
Tue, 26 Jun 2018 06:52:08 +0000 (08:52 +0200)
committerEric Engestrom <eric.engestrom@intel.com>
Wed, 1 Aug 2018 13:26:19 +0000 (14:26 +0100)
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@daitauha.fr>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
src/intel/genxml/gen_bits_header.py

index e31e9ff..dcd6ccb 100644 (file)
@@ -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):