diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py index a20d9334ae2298cf3a2c3fa660beeb29d0b43302..789231d3a3c00e0f824133ac0a967d06b62630fd 100644 --- a/src/icartt/dataset.py +++ b/src/icartt/dataset.py @@ -8,6 +8,8 @@ from enum import IntEnum import numpy as np +from . import ictutils as utl + DEFAULT_NUM_FORMAT = "%g" """Default number format for output. Provides the `fmt` parameter of :func:`numpy.savetxt` internally.""" @@ -340,15 +342,13 @@ class Variable: descstr += [str(self.longname)] return delimiter.join(descstr) - def isValidVariablename(self, name): # TODO: this could be a 'utils' function + def isValidVariablename(self, name): # ICARTT Standard v2 2.1.1 2) # Variable short names and variable standard names: # Uppercase and lowercase ASCII alphanumeric characters # and underscores. - def isAsciiAlphaOrUnderscore(x): # TODO: this could be a 'utils' function - return re.match("[a-zA-Z0-9_]", x) - allAreAlphaOrUnderscore = all(isAsciiAlphaOrUnderscore(x) for x in name) + allAreAlphaOrUnderscore = all(utl.isAsciiAlphaOrUnderscore(x) for x 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. @@ -401,10 +401,6 @@ class Variable: self.scale = scale self.miss = miss - def __repr__(self): - # TODO: this sould be something else than __str__ ? - return self.desc() - def __str__(self): return self.desc() diff --git a/src/icartt/ictutils.py b/src/icartt/ictutils.py new file mode 100644 index 0000000000000000000000000000000000000000..afedb847d44020c2f6c69a31f6218a97eda24cf2 --- /dev/null +++ b/src/icartt/ictutils.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +import re + + +def isAsciiAlphaOrUnderscore(x: str, _only="[a-zA-Z0-9_]") -> bool: + """check if string x contains only characters from [a-zA-Z0-9_] regex""" + return re.match(_only, x)