Fix T74959: Need to be explicit about UTF8 encoding in py.
authorBastien Montagne <montagne29@wanadoo.fr>
Fri, 20 Mar 2020 19:49:48 +0000 (20:49 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 20 Mar 2020 19:52:52 +0000 (20:52 +0100)
Because some OSs are still using old 8bits specific encodings... Angry
eye @windows...

release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
release/scripts/modules/bl_i18n_utils/settings.py
release/scripts/modules/bl_i18n_utils/utils.py
release/scripts/modules/bl_i18n_utils/utils_languages_menu.py

index 61c3a8dd52cb01c75f14bfc10fdf36441bd72d57..cee8f89abd3936c466eb6a6544b9dea9b24a5641 100644 (file)
@@ -765,7 +765,7 @@ def dump_src_messages(msgs, reports, settings):
             }
 
         data = ""
-        with open(path) as f:
+        with open(path, encoding="utf8") as f:
             data = f.read()
         for srch in pygettexts:
             m = srch(data)
@@ -798,7 +798,7 @@ def dump_src_messages(msgs, reports, settings):
     forbidden = set()
     forced = set()
     if os.path.isfile(settings.SRC_POTFILES):
-        with open(settings.SRC_POTFILES) as src:
+        with open(settings.SRC_POTFILES, encoding="utf8") as src:
             for l in src:
                 if l[0] == '-':
                     forbidden.add(l[1:].rstrip('\n'))
index e96c94d4f4e73e438bd90d1833805113851679eb..4da9d515ffdedddcdf17bd1675124f310746507e 100644 (file)
@@ -592,7 +592,7 @@ class I18nSettings:
                 # Assume it is already real JSon string...
                 self.from_json(fname)
                 return
-            with open(fname) as f:
+            with open(fname, encoding="utf8") as f:
                 self.from_json(f.read())
         # Else assume fname is already a file(like) object!
         else:
@@ -600,7 +600,7 @@ class I18nSettings:
 
     def save(self, fname):
         if isinstance(fname, str):
-            with open(fname, 'w') as f:
+            with open(fname, 'w', encoding="utf8") as f:
                 f.write(self.to_json())
         # Else assume fname is already a file(like) object!
         else:
index 7c22a86d6871efc90abc5835be8e3e2f5a861961..493afc53267c766ffb8de13d73aea7180bdbe12e 100644 (file)
@@ -1158,7 +1158,7 @@ class I18n:
             print("WARNING: skipping file {}, too huge!".format(path))
             return None, None, None, False
         txt = ""
-        with open(path) as f:
+        with open(path, encoding="utf8") as f:
             txt = f.read()
         _in = 0
         _out = len(txt)
@@ -1544,7 +1544,7 @@ class I18n:
                 "",
                 self.settings.PARSER_PY_MARKER_END,
             ]
-        with open(dst, 'w') as f:
+        with open(dst, 'w', encoding="utf8") as f:
             f.write((prev or "") + "\n".join(txt) + (nxt or ""))
         self.unescape()
 
index 4f499476ad9a295a441f20db1d16d02109716943..7c98faebe9df80d99326cf452e31a3ba148cd03a 100755 (executable)
@@ -93,7 +93,7 @@ def gen_menu_file(stats, settings):
             else:
                 # Non-existing, commented entry!
                 data_lines.append("# {} #{}:{}:{}".format(FLAG_MESSAGES[flag], uid_num, label, uid))
-    with open(os.path.join(settings.TRUNK_MO_DIR, settings.LANGUAGES_FILE), 'w') as f:
+    with open(os.path.join(settings.TRUNK_MO_DIR, settings.LANGUAGES_FILE), 'w', encoding="utf8") as f:
         f.write("\n".join(data_lines))
-    with open(os.path.join(settings.GIT_I18N_ROOT, settings.LANGUAGES_FILE), 'w') as f:
+    with open(os.path.join(settings.GIT_I18N_ROOT, settings.LANGUAGES_FILE), 'w', encoding="utf8") as f:
         f.write("\n".join(data_lines))