Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pluggy==1.5.0
psycopg2-binary==2.9.10
pytest==8.3.5
rda-python-globus
unidecode
32 changes: 8 additions & 24 deletions src/rda_python_common/PgLOG.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import socket
import shutil
import traceback
from unidecode import unidecode

# define some constants for logging actions
MSGLOG = (0x00001) # logging message
Expand Down Expand Up @@ -1579,33 +1580,16 @@ 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()
# 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:
return default

Expand Down