@@ -1027,34 +1027,63 @@ def base36encode(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
10271027
10281028def sublist (part_list , full_list ):
10291029 for part in part_list :
1030- if "$." in part :
1031- if part [2 :] not in full_list :
1032- return False
1030+ if isinstance (part ,dict ):
1031+ if part ["type" ] == "template" :
1032+ template_references = re .finditer ("{(.+?)}" , part ["value" ])
1033+ for reference_match in template_references :
1034+ if "$." in reference_match .group (1 ):
1035+ if reference_match .group (1 )[2 :].split ("." )[0 ] not in full_list :
1036+ return False
1037+ else :
1038+ if reference_match .group (1 ) not in full_list :
1039+ return False
10331040 else :
1034- if part not in full_list :
1035- return False
1041+ if "$." in part :
1042+ if part [2 :] not in full_list :
1043+ return False
1044+ else :
1045+ if part not in full_list :
1046+ return False
10361047 return True
10371048
10381049def child_list (childs ):
10391050 value = ""
10401051 for child in childs :
1041- if child not in value :
1042- value += child + "_"
1052+ if isinstance (child ,dict ):
1053+ if child ["value" ] not in value :
1054+ value += child ["value" ] + "_"
1055+ else :
1056+ if child not in value :
1057+ value += child + "_"
10431058 return value [:- 1 ]
10441059
10451060def child_list_value (childs ,row ):
10461061 value = ""
10471062 v = []
10481063 for child in childs :
10491064 if child not in v :
1050- if "$." in child :
1051- if row [child [2 :]] != None :
1052- value += str (row [child [2 :]]) + "_"
1053- v .append (child [2 :])
1065+ if isinstance (child ,dict ):
1066+ if child ["type" ] == "template" :
1067+ if "$." in child ["value" ]:
1068+ inter_value = string_substitution_json (child ["value" ], "{(.+?)}" ,row , "object" , "yes" , "" )
1069+ else :
1070+ inter_value = string_substitution (child ["value" ], "{(.+?)}" ,row , "object" , "yes" , "" )
1071+ if inter_value != None :
1072+ value += inter_value + "_"
1073+ v .append (child ["value" ])
1074+ else :
1075+ value += child ["value" ] + "_"
1076+ v .append (child ["value" ])
10541077 else :
1055- if row [child ] != None :
1056- value += str (row [child ]) + "_"
1057- v .append (child )
1078+ if "$." in child :
1079+ inter_value = string_substitution_json (child , ".+" ,row , "object" , "yes" , "" )
1080+ if inter_value != None :
1081+ value += inter_value [1 :- 1 ] + "_"
1082+ v .append (child [2 :])
1083+ else :
1084+ if row [child ] != None :
1085+ value += str (row [child ]) + "_"
1086+ v .append (child )
10581087 return value [:- 1 ]
10591088
10601089def child_list_value_array (childs ,row ,row_headers ):
@@ -1095,6 +1124,45 @@ def string_substitution_json(string, pattern, row, term, ignore, iterator):
10951124 match = temp_match [2 :- 2 ]
10961125 else :
10971126 match = reference_match .group (1 )[2 :]
1127+ elif "$" == reference_match .group (1 )[:1 ]:
1128+ if "['\\ {" in reference_match .group (1 ) or "[\" \\ {" in reference_match .group (1 ):
1129+ match = reference_match .group (1 ).split ("[" )[1 ]
1130+ match = match .split ("]" )[0 ]
1131+ match = match .replace ("\\ " ,"" )
1132+ match = match .replace ("{" ,"" )
1133+ match = match .replace ("}" ,"" )
1134+ match = match .replace ("'" ,"" )
1135+ match = match .replace ("\" " ,"" )
1136+ match = "{" + match + "}"
1137+ elif "[" in reference_match .group (1 )[1 :]:
1138+ match = reference_match .group (1 )[3 :- 2 ]
1139+ else :
1140+ match = reference_match .group (1 )[2 :]
1141+ elif "\\ {" in reference_match .group (1 ):
1142+ if "['\\ {" in reference_match .group (1 ) or "[\" \\ {" in reference_match .group (1 ):
1143+ match = reference_match .group (1 ).split ("[" )[1 ]
1144+ match = match .split ("]" )[0 ]
1145+ match = match .replace ("\\ " ,"" )
1146+ match = match .replace ("{" ,"" )
1147+ match = match .replace ("}" ,"" )
1148+ match = match .replace ("'" ,"" )
1149+ match = match .replace ("\" " ,"" )
1150+ match = "{" + match + "}"
1151+ else :
1152+ match = reference_match .group (1 ).replace ("\\ {" ,"" ).replace ("\\ }" ,"" )
1153+ match = match .replace ("{" ,"" ).replace ("}" ,"" )
1154+ if match [0 ] == " " :
1155+ match = match [1 :]
1156+ if "$." == match [:2 ]:
1157+ if "[" in match [1 :]:
1158+ match = match [3 :- 2 ]
1159+ else :
1160+ match = match [2 :]
1161+ elif "$" == match [:1 ]:
1162+ if "[" in match [1 :]:
1163+ match = match [3 :- 2 ]
1164+ else :
1165+ match = match [2 :]
10981166 else :
10991167 match = reference_match .group (1 )
11001168 else :
@@ -1103,6 +1171,11 @@ def string_substitution_json(string, pattern, row, term, ignore, iterator):
11031171 match = reference_match .group (1 )[2 :]
11041172 else :
11051173 match = reference_match .group (1 )[2 :]
1174+ elif "$" == reference_match .group (1 )[:1 ]:
1175+ if "[" in reference_match .group (1 )[2 :]:
1176+ match = reference_match .group (1 )[2 :]
1177+ else :
1178+ match = reference_match .group (1 )[2 :]
11061179 elif "." not in reference_match .group (1 ) and "[*]" not in reference_match .group (1 ):
11071180 match = reference_match .group (1 ).split ("[" )[0 ]
11081181 else :
@@ -1771,7 +1844,7 @@ def string_substitution(string, pattern, row, term, ignore, iterator):
17711844 if row == None :
17721845 return None
17731846 if match in row .keys ():
1774- if row [match ] != None and row [match ] != "nan" and row [match ] != "N/A" and row [match ] != "None" :
1847+ if row [match ] != None and row [match ] != "nan" and row [match ] != "N/A" and row [match ] != "None" and row [ match ] != "NULL" :
17751848 if (type (row [match ]).__name__ ) != "str" and row [match ] != None :
17761849 if (type (row [match ]).__name__ ) == "float" :
17771850 row [match ] = repr (row [match ])
@@ -1834,7 +1907,7 @@ def string_substitution(string, pattern, row, term, ignore, iterator):
18341907 print ("The index needs to be indicated.\n " )
18351908 return None
18361909 else :
1837- if row [match ] != None and row [match ] != "nan" and row [match ] != "N/A" and row [match ] != "None" :
1910+ if row [match ] != None and row [match ] != "nan" and row [match ] != "N/A" and row [match ] != "None" and row [ match ] != "NULL" :
18381911 if re .search ("^[\s|\t ]*$" , row [match ]) is None :
18391912 new_string = new_string [:start ] + row [match ].strip ().replace ("\" " , "'" ) + new_string [end :]
18401913 new_string = "\" " + new_string + "\" " if new_string [0 ] != "\" " and new_string [- 1 ] != "\" " else new_string
@@ -2135,7 +2208,9 @@ def clean_URL_suffix(URL_suffix):
21352208 return cleaned_URL
21362209
21372210def string_separetion (string ):
2138- if ("{" in string ) and ("[" in string ):
2211+ if "\\ {" in string :
2212+ return "" , ""
2213+ elif ("{" in string ) and ("[" in string ):
21392214 prefix = string .split ("{" )[0 ]
21402215 condition = string .split ("{" )[1 ].split ("}" )[0 ]
21412216 postfix = string .split ("{" )[1 ].split ("}" )[1 ]
0 commit comments