Skip to content

Commit eb0d211

Browse files
committed
Add encoding="utf-8" to text-mode open() calls
Without an explicit encoding, open() uses the locale encoding, which may not be UTF-8 on all systems. All files read or written here are UTF-8 (ebuilds, Gentoo profile files). Signed-off-by: Matt Turner <mattst88@gentoo.org> Part-of: #62 Closes: #62
1 parent 4cfa7f0 commit eb0d211

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

pym/gentoolkit/eshowkw/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ def main(argv, indirect=False):
191191
for repo in ports.repositories:
192192
repos[repo.name] = repo.location
193193

194-
with open(os.path.join(ourtree, "profiles", "repo_name")) as f:
194+
with open(
195+
os.path.join(ourtree, "profiles", "repo_name"), encoding="utf-8"
196+
) as f:
195197
repo_name = f.readline().strip()
196198

197199
repos[repo_name] = ourtree

pym/gentoolkit/imlate/imlate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def show_result(conf, pkgs):
9797
elif conf["FILE"] == "stderr":
9898
out = stderr
9999
else:
100-
out = open(conf["FILE"], "w")
100+
out = open(conf["FILE"], "w", encoding="utf-8")
101101

102102
if conf["STABLE"] and conf["KEYWORD"]:
103103
_cand = "%i Stable and %i Keyword(~)" % (

pym/gentoolkit/merge_driver_ekeyword/merge_driver_ekeyword.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def keyword_line_changes(old: str, new: str) -> KeywordChanges:
5858

5959

6060
def keyword_changes(ebuild1: str, ebuild2: str) -> Optional[KeywordChanges]:
61-
with open(ebuild1) as e1, open(ebuild2) as e2:
61+
with open(ebuild1, encoding="utf-8") as e1, open(ebuild2, encoding="utf-8") as e2:
6262
lines1 = e1.readlines()
6363
lines2 = e2.readlines()
6464

0 commit comments

Comments
 (0)