[gtk/gtk-3-24: 1/2] build: always use utf-8 when reading/writing text files



commit 5107735c9f889173aa8fb018176181d579e42aa2
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Fri Jun 21 15:01:17 2019 +0200

    build: always use utf-8 when reading/writing text files
    
    open() in text mode should never be used without an encoding because it defaults
    to the locale encoding which is rarely what is wanted.
    
    This fixes the Windows build in some cases (depending on the locale/paths used)

 demos/gtk-demo/geninclude.py  | 4 ++--
 gdk/gen-gdk-gresources-xml.py | 2 +-
 gtk/gen-gtk-gresources-xml.py | 2 +-
 gtk/gen-rc.py                 | 6 +++---
 gtk/gentypefuncs.py           | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
---
diff --git a/demos/gtk-demo/geninclude.py b/demos/gtk-demo/geninclude.py
index 57038a43b8..92bfaecc99 100755
--- a/demos/gtk-demo/geninclude.py
+++ b/demos/gtk-demo/geninclude.py
@@ -33,7 +33,7 @@ demos = []
 for demo_file in in_files:
     filename =  demo_file[demo_file.rfind('/')+1:]
     demo_name = filename.replace(".c", "")
-    with open(demo_file, 'r') as f:
+    with open(demo_file, 'r', encoding='utf-8') as f:
         title = f.readline().replace("/*", "").strip()
 
 
@@ -103,6 +103,6 @@ for demo in demos:
 
 file_output += "  { NULL }\n};\n"
 
-ofile = open(out_file, "w")
+ofile = open(out_file, "w", encoding="utf-8")
 ofile.write(file_output)
 ofile.close()
diff --git a/gdk/gen-gdk-gresources-xml.py b/gdk/gen-gdk-gresources-xml.py
index 694a9159aa..cbbdf64a0f 100644
--- a/gdk/gen-gdk-gresources-xml.py
+++ b/gdk/gen-gdk-gresources-xml.py
@@ -26,7 +26,7 @@ xml += '''
 
 if len(sys.argv) > 2:
   outfile = sys.argv[2]
-  f = open(outfile, 'w')
+  f = open(outfile, 'w', encoding='utf-8')
   f.write(xml)
   f.close()
 else:
diff --git a/gtk/gen-gtk-gresources-xml.py b/gtk/gen-gtk-gresources-xml.py
index 720d588a4e..6c610005f3 100644
--- a/gtk/gen-gtk-gresources-xml.py
+++ b/gtk/gen-gtk-gresources-xml.py
@@ -82,7 +82,7 @@ xml += '''
 
 if len(sys.argv) > 2:
   outfile = sys.argv[2]
-  f = open(outfile, 'w')
+  f = open(outfile, 'w', encoding='utf-8')
   f.write(xml)
   f.close()
 else:
diff --git a/gtk/gen-rc.py b/gtk/gen-rc.py
index 2c24fa5f6e..4bbac33553 100644
--- a/gtk/gen-rc.py
+++ b/gtk/gen-rc.py
@@ -8,14 +8,14 @@ out_file = sys.argv[1]
 in_file = sys.argv[2]
 old_msvc = sys.argv[3]
 
-with open(out_file, 'w') as o:
+with open(out_file, 'w', encoding='utf-8') as o:
     if old_msvc is not None and old_msvc == "1":
         o.write("#define ISOLATION_AWARE_ENABLED 1\n")
     o.write('#include <winuser.h>\n')
 
-    with open(in_file, 'r') as f:
+    with open(in_file, 'r', encoding='utf-8') as f:
         for line in f:
             o.write(line)
 
     o.write('\n')
-    o.write('ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST libgtk3.manifest')
\ No newline at end of file
+    o.write('ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST libgtk3.manifest')
diff --git a/gtk/gentypefuncs.py b/gtk/gentypefuncs.py
index b17b7233a1..16498b9cb0 100644
--- a/gtk/gentypefuncs.py
+++ b/gtk/gentypefuncs.py
@@ -50,6 +50,6 @@ for f in funcs:
 
 if debug: print (len(funcs), 'functions')
 
-ofile = open(out_file, "w")
+ofile = open_file(out_file, "w")
 ofile.write(file_output)
 ofile.close()


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