Skip to content

Commit c145a57

Browse files
committed
integrate comments from PR
1 parent dbbd62e commit c145a57

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

netcompare/utils/jmspath_parsers.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ def jmspath_value_parser(path: str):
1616
"result[0].vrfs.default.peerList[*].[prefixesReceived]"
1717
"result[0].vrfs.default.peerList[*].[peerAddress, prefixesReceived]"
1818
"""
19-
regex_match_ref_key = re.search(r"\$.*\$\.|\$.*\$,|,\$.*\$", path)
19+
regex_ref_key = re.compile(r"\$.*\$\.|\$.*\$,|,\$.*\$")
20+
regex_match_ref_key = regex_ref_key.search(path)
2021
path_suffix = path.split(".")[-1]
22+
2123
if regex_match_ref_key:
22-
if re.search(r"\$.*\$\.|\$.*\$,|,\$.*\$", path_suffix):
24+
if regex_ref_key.search(path_suffix):
2325
# [$peerAddress$,prefixesReceived] --> [prefixesReceived]
24-
if regex_match_ref_key:
25-
reference_key = regex_match_ref_key.group()
26-
return path.replace(reference_key, "")
27-
else:
28-
# result[0].$vrfs$.default... --> result[0].vrfs.default....
29-
regex_normalized_value = re.search(r"\$.*\$", regex_match_ref_key.group())
30-
if regex_normalized_value:
31-
normalized_value = regex_match_ref_key.group().split("$")[1]
32-
return path.replace(regex_normalized_value.group(), normalized_value)
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)
3334
return path
3435

3536

0 commit comments

Comments
 (0)