diff --git a/src/caosadvancedtools/collect_datamodel.py b/src/caosadvancedtools/collect_datamodel.py index f485aec67616d63998f9e89da800359dc8dc0bb0..bb69a03d4475c8af21f69fd5d9ffd3ac4adb1f2f 100644 --- a/src/caosadvancedtools/collect_datamodel.py +++ b/src/caosadvancedtools/collect_datamodel.py @@ -62,9 +62,9 @@ def store(directory, xml=False): rts, ps = get_dm() os.makedirs(directory, exist_ok=True) - with open(os.path.join(directory, "recordtypes.txt"), "w") as fi: + with open(os.path.join(directory, "recordtypes.txt"), "w", encoding="utf-8") as fi: fi.write(",".join([el[1] for el in rts])) - with open(os.path.join(directory, "properties.txt"), "w") as fi: + with open(os.path.join(directory, "properties.txt"), "w", encoding="utf-8") as fi: fi.write(",".join([el[1] for el in ps])) if xml: @@ -75,10 +75,10 @@ def store(directory, xml=False): def load_dm(directory): - with open(os.path.join(directory, "recordtypes.txt"), "r") as fi: + with open(os.path.join(directory, "recordtypes.txt"), "r", encoding="utf-8") as fi: text = fi.read() rts = [el.strip() for el in text.split(",")] - with open(os.path.join(directory, "properties.txt"), "r") as fi: + with open(os.path.join(directory, "properties.txt"), "r", encoding="utf-8") as fi: text = fi.read() ps = [el.strip() for el in text.split(",")] diff --git a/src/caosadvancedtools/crawler.py b/src/caosadvancedtools/crawler.py index e5bdd14271c948e83fc66a3308ff7167db0fe696..9b960d5755bed693f18a381033e94aa3d6503df1 100644 --- a/src/caosadvancedtools/crawler.py +++ b/src/caosadvancedtools/crawler.py @@ -599,7 +599,7 @@ ____________________\n""".format(i+1, len(pending_changes)) + str(el[3])) randname = os.path.basename(os.path.abspath(directory)) filepath = os.path.abspath(os.path.join(directory, filename)) filename = os.path.join(randname, filename) - with open(filepath, "w") as f: + with open(filepath, "w", encoding="utf-8") as f: f.write(form) return filename diff --git a/src/caosadvancedtools/export_related.py b/src/caosadvancedtools/export_related.py index 72484a3075fa34805af54b7b0c36ff82fbcf743e..d25381f9e4f35eabb3a17462d59ac62153d32b37 100755 --- a/src/caosadvancedtools/export_related.py +++ b/src/caosadvancedtools/export_related.py @@ -128,7 +128,7 @@ def export(cont, directory="."): xml = etree.tounicode(cont.to_xml( local_serialization=True), pretty_print=True) - with open(os.path.join(directory, "linkahead_data.xml"), "w") as fi: + with open(os.path.join(directory, "linkahead_data.xml"), "w", encoding="utf-8") as fi: fi.write(xml) diff --git a/src/caosadvancedtools/import_from_xml.py b/src/caosadvancedtools/import_from_xml.py index 23ea79c113a1269165ab9ddc1284182472f82266..4f9bba991affe449508c7b641003d2e44f93df55 100755 --- a/src/caosadvancedtools/import_from_xml.py +++ b/src/caosadvancedtools/import_from_xml.py @@ -39,7 +39,7 @@ from caosadvancedtools.models.data_model import DataModel def create_dummy_file(text="Please ask the administrator for this file."): tmpfile = NamedTemporaryFile(delete=False) tmpfile.close() - with open(tmpfile.name, "w") as tm: + with open(tmpfile.name, "w", encoding="utf-8") as tm: tm.write(text) return tmpfile.name @@ -51,7 +51,7 @@ def import_xml(filename, rerun=False, interactive=True): rerun: boolean; if true, files are not inserted as paths would conflict. """ cont = db.Container() - with open(filename) as fi: + with open(filename, encoding="utf-8") as fi: cont = cont.from_xml(fi.read()) tmpfile = create_dummy_file() diff --git a/src/caosadvancedtools/loadFiles.py b/src/caosadvancedtools/loadFiles.py index c9258afaff88b53f843d684a4d8b18a4baf55688..8e3b466fa20fd20a981ed899b3be5ba3282517fc 100755 --- a/src/caosadvancedtools/loadFiles.py +++ b/src/caosadvancedtools/loadFiles.py @@ -90,9 +90,9 @@ def combine_ignore_files(caosdbignore: str, localignore: str, dirname=None) -> s tmp = NamedTemporaryFile(delete=False, mode="w", dir=dirname, prefix=".caosdbignore") - with open(caosdbignore, "r") as base: + with open(caosdbignore, "r", encoding="utf-8") as base: tmp.write(base.read()) - with open(localignore, "r") as local: + with open(localignore, "r", encoding="utf-8") as local: tmp.write(local.read()) tmp.close() return tmp.name diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 7b91891f3b180e4bc0cd327cbf609cd11d454e52..f6e142db5c1fa9aefaceb033dc4725fcfeee5d4a 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -247,7 +247,7 @@ debug : bool, optional out : data_model.DataModel The created DataModel """ - with open(filename, 'r') as outfile: + with open(filename, 'r', encoding="utf-8") as outfile: ymlmodel = yaml.load(outfile, Loader=SafeLineLoader) return self._create_model_from_dict(ymlmodel, existing_model=existing_model) @@ -731,7 +731,7 @@ class JsonSchemaParser(Parser): # @author Florian Spreckelsen # @date 2022-02-17 # @review Timm Fitschen 2023-05-25 - with open(filename, 'r') as schema_file: + with open(filename, 'r', encoding="utf-8") as schema_file: model_dict = jsonref.load(schema_file) return self._create_model_from_dict(model_dict, top_level_recordtype=top_level_recordtype) diff --git a/src/caosadvancedtools/pandoc_header_tools.py b/src/caosadvancedtools/pandoc_header_tools.py index bf9b25a9e4ad9a5e9190c41cf00fc4bed6808b4c..a6879565dbbe80a7bb22c041ff56f59f04b623ec 100644 --- a/src/caosadvancedtools/pandoc_header_tools.py +++ b/src/caosadvancedtools/pandoc_header_tools.py @@ -103,7 +103,7 @@ it is not at the beginning, it must be preceded by a blank line. if not os.path.exists(filename): raise MetadataFileMissing(filename) - with open(filename) as f: + with open(filename, encoding="utf-8") as f: textlines = f.readlines() state = 0 @@ -168,7 +168,7 @@ def save_header(filename, header_data): if os.path.isdir(filename): filename = os.path.join(filename, "README.md") - with open(filename) as f: + with open(filename, encoding="utf-8") as f: textlines = f.readlines() while textlines[header_data[0]] != "...\n": @@ -181,7 +181,7 @@ def save_header(filename, header_data): default_flow_style=False, allow_unicode=True)) - with open(filename, "w") as f: + with open(filename, "w", encoding="utf-8") as f: f.writelines(textlines) @@ -199,7 +199,7 @@ def add_header(filename, header_dict=None): filename = os.path.join(filename, "README.md") if os.path.exists(filename): - with open(filename) as f: + with open(filename, encoding="utf-8") as f: textlines = f.readlines() else: textlines = "" @@ -211,7 +211,7 @@ def add_header(filename, header_dict=None): default_flow_style=False, allow_unicode=True) + "...\n" - with open(filename, "w") as f: + with open(filename, "w", encoding="utf-8") as f: f.write(localheader) f.writelines(textlines) diff --git a/src/caosadvancedtools/table_export.py b/src/caosadvancedtools/table_export.py index 00e644e436bde7e84043175bdeb050f07b969a3d..9b821394f633c29e58c05df2ee2d08f84e693f50 100644 --- a/src/caosadvancedtools/table_export.py +++ b/src/caosadvancedtools/table_export.py @@ -123,7 +123,7 @@ class BaseTableExporter(object): self.export_dict = export_dict else: try: - with open(export_dict) as tmp: + with open(export_dict, encoding="utf-8") as tmp: self.export_dict = json.load(tmp) except BaseException: raise ValueError(