From c17544f018b22f393e5be9dfa5ee066b57d57907 Mon Sep 17 00:00:00 2001 From: Florian Obersteiner Date: Wed, 23 Feb 2022 10:52:08 +0100 Subject: [PATCH] isValidFileName revised and added as a warning --- src/icartt/dataset.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py index fd9cdc3..5c5946e 100644 --- a/src/icartt/dataset.py +++ b/src/icartt/dataset.py @@ -710,10 +710,10 @@ class Dataset: def isAsciiAlpha(x): return re.match("[a-zA-Z0-9-_.]", x) - allAsciiAlpha = all([isAsciiAlpha(x) for x in name]) + allAsciiAlpha = all(isAsciiAlpha(x) for x in name) lessThan128Characters = len(name) < 128 - return allAsciiAlpha and lessThan128Characters + return allAsciiAlpha and lessThan128Characters and name.endswith('.ict') def writeHeader(self, f=sys.stdout, delimiter=DEFAULT_FIELD_DELIM): """Write header @@ -914,7 +914,8 @@ class Dataset: else: self.inputFhandle = f - # TODO should we add a filename characters check, as we have it for the variable names? + if not self.isValidFileName(pathlib.Path(f).name): + warnings.warn(f"{pathlib.Path(f).name} is not a valid ICARTT filename") self.readHeader(splitChar) if loadData: -- GitLab