[Bf-blender-cvs] [9607e549858] master: Fix T74959: Need to be explicit about UTF8 encoding in py.

Bastien Montagne noreply at git.blender.org
Fri Mar 20 20:53:01 CET 2020


Commit: 9607e54985838006ca5695ed88bdaf81dda29b4c
Author: Bastien Montagne
Date:   Fri Mar 20 20:49:48 2020 +0100
Branches: master
https://developer.blender.org/rB9607e54985838006ca5695ed88bdaf81dda29b4c

Fix T74959: Need to be explicit about UTF8 encoding in py.

Because some OSs are still using old 8bits specific encodings... Angry
eye @windows...

===================================================================

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

===================================================================

diff --git a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
index 61c3a8dd52c..cee8f89abd3 100644
--- a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
+++ b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
@@ -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'))
diff --git a/release/scripts/modules/bl_i18n_utils/settings.py b/release/scripts/modules/bl_i18n_utils/settings.py
index e96c94d4f4e..4da9d515ffd 100644
--- a/release/scripts/modules/bl_i18n_utils/settings.py
+++ b/release/scripts/modules/bl_i18n_utils/settings.py
@@ -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:
diff --git a/release/scripts/modules/bl_i18n_utils/utils.py b/release/scripts/modules/bl_i18n_utils/utils.py
index 7c22a86d687..493afc53267 100644
--- a/release/scripts/modules/bl_i18n_utils/utils.py
+++ b/release/scripts/modules/bl_i18n_utils/utils.py
@@ -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()
 
diff --git a/release/scripts/modules/bl_i18n_utils/utils_languages_menu.py b/release/scripts/modules/bl_i18n_utils/utils_languages_menu.py
index 4f499476ad9..7c98faebe9d 100755
--- a/release/scripts/modules/bl_i18n_utils/utils_languages_menu.py
+++ b/release/scripts/modules/bl_i18n_utils/utils_languages_menu.py
@@ -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))



More information about the Bf-blender-cvs mailing list