From 933855d914a4487eaf4e9c70bc870f2631c38b1c Mon Sep 17 00:00:00 2001
From: Florian Obersteiner <florian.obersteiner@kit.edu>
Date: Thu, 7 Apr 2022 11:38:25 +0200
Subject: [PATCH] created .py for utility functions

---
 src/icartt/dataset.py  | 12 ++++--------
 src/icartt/ictutils.py |  8 ++++++++
 2 files changed, 12 insertions(+), 8 deletions(-)
 create mode 100644 src/icartt/ictutils.py

diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py
index a20d933..789231d 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 0000000..afedb84
--- /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)
-- 
GitLab