[gegl] cltostring.py: force using utf8



commit 7f851dc7b0944db78a0b486c6ba7068489751c3f
Author: band-a-prend <torokhov-s-a yandex ru>
Date:   Sun Jan 26 01:35:45 2020 +0300

    cltostring.py: force using utf8
    
    In some cases [1] (maybe due to user locale ussies) the system env codepage
    could differ from utf8. As some of .cl files contains non-ascii symbold
    e.g authora names the cltostring.py script then fails to convert .cl file
    to header file with the error message like:
    
    "UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 783:
    ordinal not in range(128)"
    
    This patch resolves such issues by forcing utf8 codepage while reading .cl.
    The resulting cltostring.py script is compatible both python2.7 and python3.x.
    
    When python2.7 support will be dropped the addition of
    'from __future__ import unicode_literals', 'import io'
    and 'io.' could be removed as not neccessary for python3.x.
    
    [1] https://bugs.gentoo.org/705286

 opencl/cltostring.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/opencl/cltostring.py b/opencl/cltostring.py
index f2831c644..ad1289479 100755
--- a/opencl/cltostring.py
+++ b/opencl/cltostring.py
@@ -1,8 +1,10 @@
 #!/usr/bin/env python
 from __future__ import print_function
+from __future__ import unicode_literals
 
 import os
 import sys
+import io
 
 # Search for lines that look like #include "blah.h" and replace them
 # with the contents of blah.h.
@@ -34,12 +36,12 @@ def escape_string(s):
 
 
 if len(sys.argv) == 2:
-  infile  = open(sys.argv[1], "r")
-  outfile = open(sys.argv[1] + '.h',  "w")
+  infile  = io.open(sys.argv[1], "r", encoding="utf-8")
+  outfile = io.open(sys.argv[1] + '.h',  "w", encoding="utf-8")
 
 elif len(sys.argv) == 3:
-  infile  = open(sys.argv[1], "r")
-  outfile = open(sys.argv[2], "w")
+  infile  = io.open(sys.argv[1], "r", encoding="utf-8")
+  outfile = io.open(sys.argv[2], "w", encoding="utf-8")
 
 else:
   print("Usage: %s input [output]" % sys.argv[0])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]