@@ -156,26 +156,50 @@ def safe_literal_eval(filename, defaultValue):
156156# ===================================================================
157157# Parameter Parsing
158158# ===================================================================
159+ def parse_params (sparams : str ) -> dict :
160+ params = {}
161+ if not sparams :
162+ return params
163+
164+ s = sparams .strip ()
165+
166+ #full dict literal
167+ if s .startswith ("{" ) and s .endswith ("}" ):
168+ try :
169+ val = literal_eval (s )
170+ if isinstance (val , dict ):
171+ return val
172+ except (ValueError , SyntaxError ):
173+ pass
174+
175+ for item in s .split (";" ):
176+ if "=" in item :
177+ key , value = item .split ("=" , 1 ) # split only once
178+ key = key .strip ()
179+ value = value .strip ()
180+ #try to convert to python type (int, float, list, etc.)
181+ # Use literal_eval to preserve backward compatibility (integers/lists)
182+ # Fallback to string for unquoted values (paths, URLs)
183+ try :
184+ params [key ] = literal_eval (value )
185+ except (ValueError , SyntaxError ):
186+ params [key ] = value
187+ return params
188+
159189try :
160190 sparams_path = concore_params_file
161191 if os .path .exists (sparams_path ):
162192 with open (sparams_path , "r" ) as f :
163- sparams = f .read ()
193+ sparams = f .read (). strip ()
164194 if sparams : # Ensure sparams is not empty
165195 # Windows sometimes keeps quotes
166196 if sparams [0 ] == '"' and sparams [- 1 ] == '"' : #windows keeps "" need to remove
167197 sparams = sparams [1 :- 1 ]
168198
169- # Convert key=value;key2=value2 to Python dict format
170- if sparams != '{' and not (sparams .startswith ('{' ) and sparams .endswith ('}' )): # Check if it needs conversion
171- logging .debug ("converting sparams: " + sparams )
172- sparams = "{'" + re .sub (';' ,",'" ,re .sub ('=' ,"':" ,re .sub (' ' ,'' ,sparams )))+ "}"
173- logging .debug ("converted sparams: " + sparams )
174- try :
175- params = literal_eval (sparams )
176- except Exception as e :
177- logging .warning (f"bad params content: { sparams } , error: { e } " )
178- params = dict ()
199+ # Parse params using clean function instead of regex
200+ logging .debug ("parsing sparams: " + sparams )
201+ params = parse_params (sparams )
202+ logging .debug ("parsed params: " + str (params ))
179203 else :
180204 params = dict ()
181205 else :
0 commit comments