From 184891314a7da6ade70c6c8b0b2f7220b9e7298e Mon Sep 17 00:00:00 2001 From: Ben Coleman Date: Fri, 4 Feb 2022 10:10:25 -0500 Subject: [PATCH] add encoding indicators when opening files --- mirrulations-client/src/mirrclient/client.py | 4 ++-- mirrulations-work-generator/tests/test_results_processor.py | 3 ++- mirrulations-work-server/src/mirrserver/work_server.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mirrulations-client/src/mirrclient/client.py b/mirrulations-client/src/mirrclient/client.py index d7df3d0..beb1d54 100644 --- a/mirrulations-client/src/mirrclient/client.py +++ b/mirrulations-client/src/mirrclient/client.py @@ -112,14 +112,14 @@ def check_status_code(response): def read_client_id(filename): try: - with open(filename, 'r') as file: + with open(filename, 'r', encoding='utf-8') as file: return int(file.readline()) except FileNotFoundError: return -1 def write_client_id(filename, client_id): - with open(filename, 'w') as file: + with open(filename, 'w', encoding='utf-8') as file: file.write(str(client_id)) diff --git a/mirrulations-work-generator/tests/test_results_processor.py b/mirrulations-work-generator/tests/test_results_processor.py index 8554741..4e89378 100644 --- a/mirrulations-work-generator/tests/test_results_processor.py +++ b/mirrulations-work-generator/tests/test_results_processor.py @@ -12,7 +12,8 @@ def test_process_results(): dir_path = os.path.dirname(os.path.realpath(__file__)) processor = ResultsProcessor(JobQueue(database), MockDataStorage()) - with open(f'{dir_path}/data/dockets_listing.json') as listings: + with open(f'{dir_path}/data/dockets_listing.json', + encoding='utf-8') as listings: data = listings.read() processor.process_results(json.loads(data)) diff --git a/mirrulations-work-server/src/mirrserver/work_server.py b/mirrulations-work-server/src/mirrserver/work_server.py index 2c89e9f..9327f34 100644 --- a/mirrulations-work-server/src/mirrserver/work_server.py +++ b/mirrulations-work-server/src/mirrserver/work_server.py @@ -69,7 +69,7 @@ def write_results(directory, path, data): os.makedirs(f'/data/{directory}') except FileExistsError: print(f'Directory already exists in root: /data/{directory}') - with open(f'/data/{path}', 'w+') as file: + with open(f'/data/{path}', 'w+', encoding='utf-8') as file: file.write(json.dumps(data))