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

Because some OSs are still using old 8bits specific encodings... Angry
eye @windows...
This commit is contained in:
Bastien Montagne
2020-03-20 20:49:48 +01:00
parent 3d9d132ccd
commit 9607e54985
4 changed files with 8 additions and 8 deletions

View File

@@ -765,7 +765,7 @@ def dump_src_messages(msgs, reports, settings):
} }
data = "" data = ""
with open(path) as f: with open(path, encoding="utf8") as f:
data = f.read() data = f.read()
for srch in pygettexts: for srch in pygettexts:
m = srch(data) m = srch(data)
@@ -798,7 +798,7 @@ def dump_src_messages(msgs, reports, settings):
forbidden = set() forbidden = set()
forced = set() forced = set()
if os.path.isfile(settings.SRC_POTFILES): 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: for l in src:
if l[0] == '-': if l[0] == '-':
forbidden.add(l[1:].rstrip('\n')) forbidden.add(l[1:].rstrip('\n'))

View File

@@ -592,7 +592,7 @@ class I18nSettings:
# Assume it is already real JSon string... # Assume it is already real JSon string...
self.from_json(fname) self.from_json(fname)
return return
with open(fname) as f: with open(fname, encoding="utf8") as f:
self.from_json(f.read()) self.from_json(f.read())
# Else assume fname is already a file(like) object! # Else assume fname is already a file(like) object!
else: else:
@@ -600,7 +600,7 @@ class I18nSettings:
def save(self, fname): def save(self, fname):
if isinstance(fname, str): if isinstance(fname, str):
with open(fname, 'w') as f: with open(fname, 'w', encoding="utf8") as f:
f.write(self.to_json()) f.write(self.to_json())
# Else assume fname is already a file(like) object! # Else assume fname is already a file(like) object!
else: else:

View File

@@ -1158,7 +1158,7 @@ class I18n:
print("WARNING: skipping file {}, too huge!".format(path)) print("WARNING: skipping file {}, too huge!".format(path))
return None, None, None, False return None, None, None, False
txt = "" txt = ""
with open(path) as f: with open(path, encoding="utf8") as f:
txt = f.read() txt = f.read()
_in = 0 _in = 0
_out = len(txt) _out = len(txt)
@@ -1544,7 +1544,7 @@ class I18n:
"", "",
self.settings.PARSER_PY_MARKER_END, 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 "")) f.write((prev or "") + "\n".join(txt) + (nxt or ""))
self.unescape() self.unescape()

View File

@@ -93,7 +93,7 @@ def gen_menu_file(stats, settings):
else: else:
# Non-existing, commented entry! # Non-existing, commented entry!
data_lines.append("# {} #{}:{}:{}".format(FLAG_MESSAGES[flag], uid_num, label, uid)) 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)) 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)) f.write("\n".join(data_lines))