From 96da4f77f156deb98d0df7108f8fddf3b221b3cc Mon Sep 17 00:00:00 2001 From: Florian Obersteiner <florian.obersteiner@kit.edu> Date: Thu, 7 Apr 2022 12:09:25 +0200 Subject: [PATCH] revised utils / simplified --- src/icartt/dataset.py | 4 ++-- src/icartt/ictutils.py | 12 ------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py index 660a2e9..1528158 100644 --- a/src/icartt/dataset.py +++ b/src/icartt/dataset.py @@ -348,7 +348,7 @@ class Variable: # Uppercase and lowercase ASCII alphanumeric characters # and underscores. - allAreAlphaOrUnderscore = all(utl.isAsciiAlphaOrUnderscore(x) for x in name) + allAreAlphaOrUnderscore = all(re.match("[a-zA-Z0-9_]", c) for c in name) # The first character must be a letter, firstIsAlpha = bool(re.match("[a-zA-Z]", name[0])) # and the name can be at most 31 characters in length. @@ -757,7 +757,7 @@ class Dataset: :return: is file name valid according to ICARTT standard? :rtype: bool """ - allAsciiAlpha = utl.isAsciiAlpha(name) + allAsciiAlpha = all(re.match("[a-zA-Z0-9-_.]", c) for c in name) lessThan128Characters = len(name) < 128 return allAsciiAlpha and lessThan128Characters and name.endswith(".ict") diff --git a/src/icartt/ictutils.py b/src/icartt/ictutils.py index 0f2066c..f7f666c 100644 --- a/src/icartt/ictutils.py +++ b/src/icartt/ictutils.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -import re - class FilehandleWithLinecounter: """a file handle that counts the number of files that were read""" @@ -19,16 +17,6 @@ class FilehandleWithLinecounter: return dmp -def isAsciiAlphaOrUnderscore(x: str) -> bool: - """check if string x contains only characters from [a-zA-Z0-9_] regex""" - return re.match("[a-zA-Z0-9_]", x) - - -def isAsciiAlpha(x): - """check if string x contains only characters from [a-zA-Z0-9-_.] regex""" - return re.match("[a-zA-Z0-9-_.]", x) - - def extractVardesc(line_parts: list) -> str: """extract variable description from ict header line parts (splitted line)""" shortname, units, standardname, longname, *_ = line_parts + [None] * 3 -- GitLab