@@ -6,21 +6,31 @@ def jmspath_value_parser(path: str):
66 """
77 Get the JMSPath value path from 'path'.
88
9+ Two combinations are possible based on where reference key is defined. See example below.
10+
911 Args:
1012 path: "result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesReceived]"
13+ path: "result[0].$vrfs$.default.peerList[*].[peerAddress, prefixesReceived]"
14+
1115 Return:
1216 "result[0].vrfs.default.peerList[*].[prefixesReceived]"
17+ "result[0].vrfs.default.peerList[*].[peerAddress, prefixesReceived]"
1318 """
14- regex_match_value = re .search (r"\$.*\$\.|\$.*\$,|,\$.*\$" , path )
15-
16- if not regex_match_value :
17- return path
18- # $peers$. --> peers
19- regex_normalized_value = re .search (r"\$.*\$" , regex_match_value .group ())
20- if regex_normalized_value :
21- normalized_value = regex_match_value .group ().split ("$" )[1 ]
22- return path .replace (regex_normalized_value .group (), normalized_value )
23-
19+ regex_ref_key = re .compile (r"\$.*\$\.|\$.*\$,|,\$.*\$" )
20+ regex_match_ref_key = regex_ref_key .search (path )
21+ path_suffix = path .split ("." )[- 1 ]
22+
23+ if regex_match_ref_key :
24+ if regex_ref_key .search (path_suffix ):
25+ # [$peerAddress$,prefixesReceived] --> [prefixesReceived]
26+ reference_key = regex_match_ref_key .group ()
27+ return path .replace (reference_key , "" )
28+
29+ # result[0].$vrfs$.default... --> result[0].vrfs.default....
30+ regex_normalized_value = re .search (r"\$.*\$" , regex_match_ref_key .group ())
31+ if regex_normalized_value :
32+ normalized_value = regex_match_ref_key .group ().split ("$" )[1 ]
33+ return path .replace (regex_normalized_value .group (), normalized_value )
2434 return path
2535
2636
0 commit comments