From df29ed238f620122b4a39b197dde2ad3ebe7beb1 Mon Sep 17 00:00:00 2001 From: Duck <24493647+ghostduck@users.noreply.github.com> Date: Sat, 5 Jan 2019 19:11:01 +0800 Subject: [PATCH 1/2] Specify encoding to UTF-8 when opening source file --- updateHostsFile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index bc82cda11..af375b9e7 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -527,7 +527,7 @@ def update_sources_data(sources_data, **sources_params): source_data_filename = sources_params["sourcedatafilename"] for source in recursive_glob(sources_params["datapath"], source_data_filename): - update_file = open(source, "r") + update_file = open(source, "r", encoding="utf8") update_data = json.load(update_file) sources_data.append(update_data) update_file.close() @@ -586,7 +586,7 @@ def update_all_sources(source_data_filename, host_filename): all_sources = recursive_glob("*", source_data_filename) for source in all_sources: - update_file = open(source, "r") + update_file = open(source, "r", encoding="utf8") update_data = json.load(update_file) update_file.close() update_url = update_data["url"] @@ -631,7 +631,7 @@ def create_initial_file(): start = "# Start {}\n\n".format(os.path.basename(os.path.dirname(source))) end = "# End {}\n\n".format(os.path.basename(os.path.dirname(source))) - with open(source, "r") as curFile: + with open(source, "r", encoding="utf8") as curFile: write_data(merge_file, start + curFile.read() + end) # spin the sources for extensions to the base file From 5c69826a983a2a1df3d97652ebea66f5f30a9a85 Mon Sep 17 00:00:00 2001 From: Duck <24493647+ghostduck@users.noreply.github.com> Date: Sat, 5 Jan 2019 23:08:46 +0800 Subject: [PATCH 2/2] Change "utf8" to "UTF-8" in params for encoding in updateHostFile.py --- updateHostsFile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index af375b9e7..541b6034a 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -527,7 +527,7 @@ def update_sources_data(sources_data, **sources_params): source_data_filename = sources_params["sourcedatafilename"] for source in recursive_glob(sources_params["datapath"], source_data_filename): - update_file = open(source, "r", encoding="utf8") + update_file = open(source, "r", encoding="UTF-8") update_data = json.load(update_file) sources_data.append(update_data) update_file.close() @@ -586,7 +586,7 @@ def update_all_sources(source_data_filename, host_filename): all_sources = recursive_glob("*", source_data_filename) for source in all_sources: - update_file = open(source, "r", encoding="utf8") + update_file = open(source, "r", encoding="UTF-8") update_data = json.load(update_file) update_file.close() update_url = update_data["url"] @@ -631,7 +631,7 @@ def create_initial_file(): start = "# Start {}\n\n".format(os.path.basename(os.path.dirname(source))) end = "# End {}\n\n".format(os.path.basename(os.path.dirname(source))) - with open(source, "r", encoding="utf8") as curFile: + with open(source, "r", encoding="UTF-8") as curFile: write_data(merge_file, start + curFile.read() + end) # spin the sources for extensions to the base file