[Mesa-dev] [PATCH] python: Help Python 2 print the line

Jose Fonseca jfonseca at vmware.com
Fri Aug 17 13:30:40 UTC 2018


On 17/08/18 14:22, Mathieu Bridon wrote:
> ---
> Jose, can you test whether this patch fixes your build issues?
> 
> I don't have access to a Windows machine, and I can't reproduce your
> problem on Linux.
> 
>   src/util/xmlpool/gen_xmlpool.py | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py
> index 327709c7f8d..12177dc50f5 100644
> --- a/src/util/xmlpool/gen_xmlpool.py
> +++ b/src/util/xmlpool/gen_xmlpool.py
> @@ -218,6 +218,11 @@ for line in template:
>           assert len(descMatches) == 0
>           descMatches = [matchDESC_BEGIN]
>       else:
> +        # In Python 2, stdout expects encoded byte strings, or else it will
> +        # encode them with the ascii 'codec'
> +        if sys.version_info.major == 2:
> +            line = line.encode('utf-8')
> +
>           print(line, end='')
>   
>   template.close()
> 

It fixes the UnicodeEncodeError.  I need to do more testing to see if it 
fixes all errors.


I think we should fix the print(end ..) statemet.   In fact, it might be 
easier to have an helper function (e.g., write() )  which does the 
sys.version check , utf8 encoding, and print, and use it everywhere 
print is used now.


Jose


More information about the mesa-dev mailing list