diff --git a/plugins/ChangeLogPlugin/ChangeLog.py b/plugins/ChangeLogPlugin/ChangeLog.py index e93d5c4395..723c83a021 100644 --- a/plugins/ChangeLogPlugin/ChangeLog.py +++ b/plugins/ChangeLogPlugin/ChangeLog.py @@ -55,7 +55,7 @@ class ChangeLog(Extension, QObject,): def loadChangeLogs(self): self._change_logs = collections.OrderedDict() - with open(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.txt"), "r",-1, "utf-8") as f: + with open(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.txt"), "r", encoding = "utf-8") as f: open_version = None open_header = "" # Initialise to an empty header in case there is no "*" in the first line of the changelog for line in f: diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py index 4b50a600ba..9fbae7b473 100644 --- a/plugins/GCodeProfileReader/GCodeProfileReader.py +++ b/plugins/GCodeProfileReader/GCodeProfileReader.py @@ -57,7 +57,7 @@ class GCodeProfileReader(ProfileReader): # TODO: Consider moving settings to the start? serialized = "" # Will be filled with the serialized profile. try: - with open(file_name, "r") as f: + with open(file_name, "r", encoding = "utf-8") as f: for line in f: if line.startswith(prefix): # Remove the prefix and the newline from the line and add it to the rest. diff --git a/plugins/LegacyProfileReader/LegacyProfileReader.py b/plugins/LegacyProfileReader/LegacyProfileReader.py index 3c2b9bfa76..40a843e6c4 100644 --- a/plugins/LegacyProfileReader/LegacyProfileReader.py +++ b/plugins/LegacyProfileReader/LegacyProfileReader.py @@ -100,7 +100,7 @@ class LegacyProfileReader(ProfileReader): return None try: - with open(os.path.join(PluginRegistry.getInstance().getPluginPath("LegacyProfileReader"), "DictionaryOfDoom.json"), "r", -1, "utf-8") as f: + with open(os.path.join(PluginRegistry.getInstance().getPluginPath("LegacyProfileReader"), "DictionaryOfDoom.json"), "r", encoding = "utf-8") as f: dict_of_doom = json.load(f) # Parse the Dictionary of Doom. except IOError as e: Logger.log("e", "Could not open DictionaryOfDoom.json for reading: %s", str(e)) diff --git a/plugins/USBPrinting/avr_isp/intelHex.py b/plugins/USBPrinting/avr_isp/intelHex.py index a51c798d8e..671f1788f7 100644 --- a/plugins/USBPrinting/avr_isp/intelHex.py +++ b/plugins/USBPrinting/avr_isp/intelHex.py @@ -13,7 +13,7 @@ def readHex(filename): """ data = [] extra_addr = 0 - f = io.open(filename, "r") + f = io.open(filename, "r", encoding = "utf-8") for line in f: line = line.strip() if len(line) < 1: diff --git a/plugins/VersionUpgrade/VersionUpgrade22to24/VersionUpgrade.py b/plugins/VersionUpgrade/VersionUpgrade22to24/VersionUpgrade.py index 7505911049..730a62e591 100644 --- a/plugins/VersionUpgrade/VersionUpgrade22to24/VersionUpgrade.py +++ b/plugins/VersionUpgrade/VersionUpgrade22to24/VersionUpgrade.py @@ -94,7 +94,7 @@ class VersionUpgrade22to24(VersionUpgrade): if variant_path.endswith("_variant.inst.cfg"): variant_path = variant_path[:-len("_variant.inst.cfg")] + "_settings.inst.cfg" - with open(os.path.join(machine_instances_dir, os.path.basename(variant_path)), "w") as fp: + with open(os.path.join(machine_instances_dir, os.path.basename(variant_path)), "w", encoding = "utf-8") as fp: variant_config.write(fp) return config_name @@ -105,9 +105,9 @@ class VersionUpgrade22to24(VersionUpgrade): result = [] for entry in os.scandir(variants_dir): - if entry.name.endswith('.inst.cfg') and entry.is_file(): + if entry.name.endswith(".inst.cfg") and entry.is_file(): config = configparser.ConfigParser(interpolation = None) - with open(entry.path, "r") as fhandle: + with open(entry.path, "r", encoding = "utf-8") as fhandle: config.read_file(fhandle) if config.has_section("general") and config.has_option("general", "name"): result.append( { "path": entry.path, "name": config.get("general", "name") } ) diff --git a/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py b/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py index e1c14be2e1..54b561c847 100644 --- a/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py +++ b/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py @@ -249,11 +249,11 @@ class VersionUpgrade25to26(VersionUpgrade): definition_changes_dir = Resources.getPath(CuraApplication.ResourceTypes.DefinitionChangesContainer) user_settings_dir = Resources.getPath(CuraApplication.ResourceTypes.UserInstanceContainer) - with open(os.path.join(definition_changes_dir, definition_changes_filename), "w") as f: + with open(os.path.join(definition_changes_dir, definition_changes_filename), "w", encoding = "utf-8") as f: f.write(definition_changes_output.getvalue()) - with open(os.path.join(user_settings_dir, user_settings_filename), "w") as f: + with open(os.path.join(user_settings_dir, user_settings_filename), "w", encoding = "utf-8") as f: f.write(user_settings_output.getvalue()) - with open(os.path.join(extruder_stack_dir, extruder_filename), "w") as f: + with open(os.path.join(extruder_stack_dir, extruder_filename), "w", encoding = "utf-8") as f: f.write(extruder_output.getvalue()) ## Creates a definition changes container which doesn't contain anything for the Custom FDM Printers. diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index 4985c2fd87..9d456c833d 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -1018,7 +1018,7 @@ class XmlMaterialProfile(InstanceContainer): @classmethod def getProductIdMap(cls) -> Dict[str, List[str]]: product_to_id_file = os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "product_to_id.json") - with open(product_to_id_file) as f: + with open(product_to_id_file, encoding = "utf-8") as f: product_to_id_map = json.load(f) product_to_id_map = {key: [value] for key, value in product_to_id_map.items()} return product_to_id_map diff --git a/tests/TestProfileRequirements.py b/tests/TestProfileRequirements.py index edeec909f2..f75ca9da8d 100644 --- a/tests/TestProfileRequirements.py +++ b/tests/TestProfileRequirements.py @@ -19,7 +19,7 @@ import pytest def test_ultimaker3extended_variants(um3_file, um3e_file): directory = os.path.join(os.path.dirname(__file__), "..", "resources", "variants") #TODO: Hardcoded path relative to this test file. um3 = configparser.ConfigParser() - um3.read_file(open(os.path.join(directory, um3_file))) + um3.read_file(open(os.path.join(directory, um3_file), encoding = "utf-8")) um3e = configparser.ConfigParser() - um3e.read_file(open(os.path.join(directory, um3e_file))) + um3e.read_file(open(os.path.join(directory, um3e_file), encoding = "utf-8")) assert um3["values"] == um3e["values"]