From a3e170e9558c85be2ed539bf50a86458f4c812cd Mon Sep 17 00:00:00 2001 From: Thomas Cram Date: Wed, 8 Oct 2025 11:42:13 -0600 Subject: [PATCH 1/3] add unidecode to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index f038d89..a1482d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ pluggy==1.5.0 psycopg2-binary==2.9.10 pytest==8.3.5 rda-python-globus +unidecode From e7a35626b3760a13752b8816db47efbed17d2f42 Mon Sep 17 00:00:00 2001 From: Thomas Cram Date: Wed, 8 Oct 2025 12:03:02 -0600 Subject: [PATCH 2/3] refactor: improve character conversion to use unidecode for better ASCII representation --- src/rda_python_common/PgLOG.py | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/rda_python_common/PgLOG.py b/src/rda_python_common/PgLOG.py index 54ce0e2..d6f8c0d 100644 --- a/src/rda_python_common/PgLOG.py +++ b/src/rda_python_common/PgLOG.py @@ -28,6 +28,7 @@ import socket import shutil import traceback +from unidecode import unidecode # define some constants for logging actions MSGLOG = (0x00001) # logging message @@ -1579,33 +1580,18 @@ def check_process_host(hosts, chost = None, mflag = None, pinfo = None, logact = return ret # -# convert special characters +# convert special foreign characters into ascii characters # def convert_chars(name, default = 'X'): if not name: return default - if re.match(r'^[a-zA-Z0-9]+$', name): return name # no need convert - - z = ord('z') - newchrs = ochrs = '' - for i in range(len(name)): - ch = name[i] - if re.match(r'^[a-zA-Z0-9]$', ch): - newchrs += ch - elif (ch == ' ' or ch == '_') and newchrs: - newchrs += '_' - elif ord(ch) > z and ochrs != None: - if not ochrs: - ochrs = None - with open(PGLOG['DSSHOME'] + "/lib/ExtChrs.txt", "r") as CHR: - ochrs = CHR.readline() - nchrs = CHR.readline() - if ochrs is None: continue - idx = ochrs.find(ch) - if idx >= 0: newchrs += nchrs[idx] - - if newchrs: - return newchrs + if re.match(r'^[a-zA-Z0-9]+$', name): return name # conversion not needed + + decoded_name = unidecode(name).strip() + cleaned_name = re.sub(r'[^a-zA-Z0-9]', '', decoded_name) + + if cleaned_name: + return cleaned_name else: return default From 2ba2ee082c7d4bda8594f4dcaf0fbf60d82e5bc7 Mon Sep 17 00:00:00 2001 From: Thomas Cram Date: Wed, 8 Oct 2025 12:10:57 -0600 Subject: [PATCH 3/3] refactor: enhance character conversion to allow underscores in cleaned names --- src/rda_python_common/PgLOG.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/rda_python_common/PgLOG.py b/src/rda_python_common/PgLOG.py index d6f8c0d..c08b3e3 100644 --- a/src/rda_python_common/PgLOG.py +++ b/src/rda_python_common/PgLOG.py @@ -1583,13 +1583,11 @@ def check_process_host(hosts, chost = None, mflag = None, pinfo = None, logact = # convert special foreign characters into ascii characters # def convert_chars(name, default = 'X'): - if not name: return default if re.match(r'^[a-zA-Z0-9]+$', name): return name # conversion not needed - decoded_name = unidecode(name).strip() - cleaned_name = re.sub(r'[^a-zA-Z0-9]', '', decoded_name) - + # remove any non-alphanumeric and non-underscore characters + cleaned_name = re.sub(r'[^a-zA-Z0-9_]', '', decoded_name) if cleaned_name: return cleaned_name else: