-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xpath: add support for indexed xpath #112
xpath: add support for indexed xpath #112
Conversation
527a545
to
89847e0
Compare
libyang/xpath.py
Outdated
break | ||
j += 1 | ||
key_value = xpath[i:j] | ||
keys.append((KEY_INDEX, key_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit concerned that the keys
list can now contain tuples that are not only strings. It would be less disruptive if the key name would be an empty string in this case.
You can check that below without much hassle.
libyang/xpath.py
Outdated
@@ -134,6 +147,12 @@ def _list_find_key_index(keys: List[Tuple[str, str]], lst: List) -> int: | |||
if py_to_yang(elem) == keys[0][1]: | |||
return i | |||
|
|||
elif keys[0][0] == KEY_INDEX: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to:
elif keys[0][0] == "":
tests/test_xpath.py
Outdated
@@ -101,7 +102,7 @@ def test_xpath_set(self): | |||
{"name": "eth3", "mtu": 1000}, | |||
], | |||
"lst2": ["a", "b", "c"], | |||
"lstnum": [1, 10, 20, 30, 40, 100], | |||
"lstnum": [1, 10, 20, 30, 33, 100], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add more unit tests. This is a rather risky change. Thanks.
This patch adds support for indexed xpath to xpath_set. In the case of a leaf-list, it is now possible to apply xpath_set in this way: xpath_set(d, "/lstnum[5]", 33, after="4") This will replace the 5th element of the leaf-list with the new value 33. This feature is important because libyang can return this type of xpath when a callback is called with sr_module_change_subscribe from sysrepo. The tests are updated accordingly. Signed-off-by: Jean-Sébastien Bevilacqua <[email protected]>
89847e0
to
1347f5f
Compare
@rjarry I updated it |
This patch adds support for indexed xpath to xpath_set. In the case of a leaf-list, it is now possible to apply xpath_set in this way:
xpath_set(d, "/lstnum[5]", 33, after="4")
This will replace the 5th element of the leaf-list with the new value 33.
This feature is important because libyang can return this type of xpath when a callback is called with sr_module_change_subscribe from sysrepo.
The tests are updated accordingly.