[Mesa-dev] [PATCH 20/26] python: Open file in binary mode

Dylan Baker dylan at pnwbakers.com
Thu Jul 5 16:36:30 UTC 2018


Reviewed-by: Dylan Baker <dylan at pnwbakers.com>

Quoting Mathieu Bridon (2018-07-05 06:17:51)
> 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>
> ---
>  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):
> -- 
> 2.17.1
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180705/ba64c266/attachment.sig>


More information about the mesa-dev mailing list