aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-01-25 18:46:36 +0100
committerDaniel Schadt <kingdread@gmx.de>2023-01-25 18:46:36 +0100
commitda12cffae3f374a8e70841f7ed14b46ee4ed18aa (patch)
tree7babbbbedab9e1e9013bdbb8d334acebe7f559a4
parenta03e5ecaaaba8d89280b19411d15579107ceaf8f (diff)
downloadfietsboek-da12cffae3f374a8e70841f7ed14b46ee4ed18aa.tar.gz
fietsboek-da12cffae3f374a8e70841f7ed14b46ee4ed18aa.tar.bz2
fietsboek-da12cffae3f374a8e70841f7ed14b46ee4ed18aa.zip
make encoding in read_text/write_text explicit
We always use UTF-8, and this way we won't run into funky OS-dependent encoding magic. See also https://peps.python.org/pep-0686/
-rw-r--r--fietsboek/data.py2
-rw-r--r--fietsboek/pages.py2
-rw-r--r--fietsboek/scripts/fietsctl.py2
-rw-r--r--fietsboek/updater/__init__.py2
-rw-r--r--fietsboek/util.py2
5 files changed, 5 insertions, 5 deletions
diff --git a/fietsboek/data.py b/fietsboek/data.py
index 96acaec..1a1b66b 100644
--- a/fietsboek/data.py
+++ b/fietsboek/data.py
@@ -64,7 +64,7 @@ class DataManager:
:return: The maintenance mode state.
"""
try:
- return (self.data_dir / "MAINTENANCE").read_text()
+ return (self.data_dir / "MAINTENANCE").read_text(encoding="utf-8")
except FileNotFoundError:
return None
diff --git a/fietsboek/pages.py b/fietsboek/pages.py
index 8baf02b..5ca8f24 100644
--- a/fietsboek/pages.py
+++ b/fietsboek/pages.py
@@ -149,7 +149,7 @@ class Pages:
:param path: The path of the file to load.
:raises PageException: If the page is malformed.
"""
- source = path.read_text()
+ source = path.read_text(encoding="utf-8")
try:
page = Page.parse(source)
except PageException as exc:
diff --git a/fietsboek/scripts/fietsctl.py b/fietsboek/scripts/fietsctl.py
index a1f14f7..2d6302e 100644
--- a/fietsboek/scripts/fietsctl.py
+++ b/fietsboek/scripts/fietsctl.py
@@ -153,7 +153,7 @@ def cmd_maintenance_mode(env, args):
elif args.disable:
(data_manager.data_dir / "MAINTENANCE").unlink()
else:
- (data_manager.data_dir / "MAINTENANCE").write_text(args.reason)
+ (data_manager.data_dir / "MAINTENANCE").write_text(args.reason, encoding="utf-8")
return EXIT_OKAY
diff --git a/fietsboek/updater/__init__.py b/fietsboek/updater/__init__.py
index 8eca10d..a62b395 100644
--- a/fietsboek/updater/__init__.py
+++ b/fietsboek/updater/__init__.py
@@ -387,7 +387,7 @@ def _load_update_scripts():
"""Loads all available import scripts."""
files = importlib_resources.files(__name__) / "scripts"
return [
- UpdateScript(file.read_text(), _filename_to_modname(file.name))
+ UpdateScript(file.read_text(encoding="utf-8"), _filename_to_modname(file.name))
for file in files.iterdir()
if file.name.startswith("upd_")
]
diff --git a/fietsboek/util.py b/fietsboek/util.py
index 8dd81c0..96ba660 100644
--- a/fietsboek/util.py
+++ b/fietsboek/util.py
@@ -314,7 +314,7 @@ def read_localized_resource(
locale_dir = importlib_resources.files(package) / "locale" / locale
resource_path = locale_dir / path
try:
- return resource_path.read_text()
+ return resource_path.read_text(encoding="utf-8")
except (FileNotFoundError, ModuleNotFoundError, NotADirectoryError):
pass
if raise_on_error: