add missing encoding argument to open calls

This commit is contained in:
Damien Elmes 2021-10-02 23:20:27 +10:00
parent 9a103b3716
commit 553ce808e5
4 changed files with 7 additions and 7 deletions

View File

@ -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:

View File

@ -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.")

View File

@ -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)}<br>"
msg += f"{col.tr.media_generated_file(val=texpath)}<br>"
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()

View File

@ -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: