From 815c1ec088596c6a542f11755ffa22d080131808 Mon Sep 17 00:00:00 2001 From: kramo Date: Sat, 14 Oct 2023 20:32:22 +0200 Subject: [PATCH] =?UTF-8?q?Explicit=20is=20better=20than=20implicit=20?= =?UTF-8?q?=F0=9F=90=8D=F0=9F=A4=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cartridges/main.py | 6 ++++-- cartridges/store/managers/file_manager.py | 2 +- cartridges/utils/migrate_files_v1_to_v2.py | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cartridges/main.py b/cartridges/main.py index 84efcc5..f3fa928 100644 --- a/cartridges/main.py +++ b/cartridges/main.py @@ -172,7 +172,9 @@ class CartridgesApplication(Adw.Application): try: game_id = args[index + 1] data = json.load( - (path := shared.games_dir / (game_id + ".json")).open("r") + (path := shared.games_dir / (game_id + ".json")).open( + "r", encoding="utf-8" + ) ) executable = ( shlex.join(data["executable"]) @@ -184,7 +186,7 @@ class CartridgesApplication(Adw.Application): run_executable(executable) data["last_played"] = int(time()) - json.dump(data, path.open("w")) + json.dump(data, path.open("w", encoding="utf-8")) except (IndexError, KeyError, OSError, json.decoder.JSONDecodeError): return 1 diff --git a/cartridges/store/managers/file_manager.py b/cartridges/store/managers/file_manager.py index b1f437a..8215038 100644 --- a/cartridges/store/managers/file_manager.py +++ b/cartridges/store/managers/file_manager.py @@ -53,7 +53,7 @@ class FileManager(AsyncManager): json.dump( {attr: getattr(game, attr) for attr in attrs if attr}, - (shared.games_dir / f"{game.game_id}.json").open("w"), + (shared.games_dir / f"{game.game_id}.json").open("w", encoding="utf-8"), indent=4, sort_keys=True, ) diff --git a/cartridges/utils/migrate_files_v1_to_v2.py b/cartridges/utils/migrate_files_v1_to_v2.py index 526d48b..50fa2cb 100644 --- a/cartridges/utils/migrate_files_v1_to_v2.py +++ b/cartridges/utils/migrate_files_v1_to_v2.py @@ -76,7 +76,7 @@ def migrate_files_v1_to_v2() -> None: imported_execs = set() for game_path in shared.games_dir.glob("imported_*.json"): try: - game_data = json.load(game_path.open("r")) + game_data = json.load(game_path.open("r", encoding="utf-8")) except (OSError, json.JSONDecodeError): continue number = int(game_data["game_id"].replace("imported_", "")) @@ -86,7 +86,7 @@ def migrate_files_v1_to_v2() -> None: # Migrate imported game files for game_path in old_imported_game_paths: try: - game_data = json.load(game_path.open("r")) + game_data = json.load(game_path.open("r", encoding="utf-8")) except (OSError, json.JSONDecodeError): continue @@ -104,7 +104,7 @@ def migrate_files_v1_to_v2() -> None: ) json.dump( game_data, - destination_game_path.open("w"), + destination_game_path.open("w", encoding="utf-8"), indent=4, sort_keys=True, )