Skip to content
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

schema: adds nested extensions access #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ def parent_node(self) -> Optional[Union["PNode", "PIdentity"]]:
return None
return None

def extensions(self) -> Iterator["ExtensionParsed"]:
for ext in ly_array_iter(self.cdata.exts):
yield ExtensionParsed(self.context, ext, self.module_parent)


# -------------------------------------------------------------------------------------
class ExtensionCompiled(Extension):
Expand Down Expand Up @@ -462,6 +466,10 @@ def parent_node(self) -> Optional[Union["SNode", "Identity"]]:
return None
return None

def extensions(self) -> Iterator["ExtensionCompiled"]:
for ext in ly_array_iter(self.cdata.exts):
yield ExtensionCompiled(self.context, ext)


# -------------------------------------------------------------------------------------
class _EnumBit:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from libyang import (
Context,
Extension,
ExtensionCompiled,
ExtensionParsed,
Identity,
IfFeature,
Expand Down Expand Up @@ -498,12 +499,14 @@ def test_rpc_extensions(self):
ext = list(self.rpc.extensions())
self.assertEqual(len(ext), 1)
ext = self.rpc.get_extension("require-admin", prefix="omg-extensions")
self.assertIsInstance(ext, Extension)
self.assertIsInstance(ext, ExtensionCompiled)
self.assertIsInstance(ext.parent_node(), SRpc)
self.assertIsNone(next(ext.extensions(), None))
parsed = self.rpc.parsed()
ext = parsed.get_extension("require-admin", prefix="omg-extensions")
self.assertIsInstance(ext, ExtensionParsed)
self.assertIsInstance(ext.parent_node(), PAction)
self.assertIsNone(next(ext.extensions(), None))

def test_rpc_params(self):
leaf = next(self.rpc.children())
Expand Down
Loading