diff --git a/pylib/anki/buildinfo.py b/pylib/anki/buildinfo.py index d9c5a7a5f..afa52b65b 100644 --- a/pylib/anki/buildinfo.py +++ b/pylib/anki/buildinfo.py @@ -21,7 +21,7 @@ def _build_info_path() -> str: def _get_build_info() -> Dict[str, str]: info = {} - with open(_build_info_path()) as file: + with open(_build_info_path(), encoding="utf8") as file: for line in file.readlines(): elems = line.split() if len(elems) == 2: diff --git a/pylib/anki/importing/supermemo_xml.py b/pylib/anki/importing/supermemo_xml.py index 6327b5f18..7d91e95c5 100644 --- a/pylib/anki/importing/supermemo_xml.py +++ b/pylib/anki/importing/supermemo_xml.py @@ -311,7 +311,7 @@ class SupermemoXmlImporter(NoteImporter): # try to open with native open function (if source is pathname) try: - return open(source) + return open(source, encoding="utf8") except OSError: pass @@ -324,7 +324,7 @@ class SupermemoXmlImporter(NoteImporter): """Load source file and parse with xml.dom.minidom""" self.source = source self.logger("Load started...") - sock = open(self.source) + sock = open(self.source, encoding="utf8") self.xmldoc = minidom.parse(sock).documentElement sock.close() self.logger("Load done.") diff --git a/pylib/anki/latex.py b/pylib/anki/latex.py index e1e31f228..8e9c31966 100644 --- a/pylib/anki/latex.py +++ b/pylib/anki/latex.py @@ -142,7 +142,7 @@ def _save_latex_image( ext = "png" # write into a temp file - log = open(namedtmp("latex_log.txt"), "w") + log = open(namedtmp("latex_log.txt"), "w", encoding="utf8") texpath = namedtmp("tmp.tex") texfile = open(texpath, "w", encoding="utf8") texfile.write(latex) @@ -170,7 +170,7 @@ def _errMsg(col: anki.collection.Collection, type: str, texpath: str) -> Any: msg = f"{col.tr.media_error_executing(val=type)}
" msg += f"{col.tr.media_generated_file(val=texpath)}
" try: - with open(namedtmp("latex_log.txt", rm=False)) as f: + with open(namedtmp("latex_log.txt", rm=False), encoding="utf8") as f: log = f.read() if not log: raise Exception() diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 42a0afac0..bb1190984 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -573,14 +573,14 @@ create table if not exists profiles def video_driver(self) -> VideoDriver: path = self._gldriver_path() try: - with open(path) as file: + with open(path, encoding="utf8") as file: text = file.read().strip() return VideoDriver(text).constrained_to_platform() except (ValueError, OSError): return VideoDriver.default_for_platform() def set_video_driver(self, driver: VideoDriver) -> None: - with open(self._gldriver_path(), "w") as file: + with open(self._gldriver_path(), "w", encoding="utf8") as file: file.write(driver.value) def set_next_video_driver(self) -> None: