Skip to content
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
28 changes: 21 additions & 7 deletions libyang/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1679,8 +1679,12 @@ class SRpcInOut(SNode):
def __iter__(self) -> Iterator[SNode]:
return self.children()

def children(self, types: Optional[Tuple[int, ...]] = None) -> Iterator[SNode]:
return iter_children(self.context, self.cdata, types=types)
def children(
self, types: Optional[Tuple[int, ...]] = None, with_choice: bool = False
) -> Iterator[SNode]:
return iter_children(
self.context, self.cdata, types=types, with_choice=with_choice
)


# -------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1710,11 +1714,17 @@ def output(self) -> Optional[SRpcInOut]:
def __iter__(self) -> Iterator[SNode]:
return self.children()

def children(self, types: Optional[Tuple[int, ...]] = None) -> Iterator[SNode]:
yield from iter_children(self.context, self.cdata, types=types)
def children(
self, types: Optional[Tuple[int, ...]] = None, with_choice: bool = False
) -> Iterator[SNode]:
yield from iter_children(
self.context, self.cdata, types=types, with_choice=with_choice
)
# With libyang2, you can get only input or output
# To keep behavior, we iter 2 times witt output options
yield from iter_children(self.context, self.cdata, types=types, output=True)
yield from iter_children(
self.context, self.cdata, types=types, output=True, with_choice=with_choice
)


# -------------------------------------------------------------------------------------
Expand All @@ -1723,8 +1733,12 @@ class SNotif(SNode):
def __iter__(self) -> Iterator[SNode]:
return self.children()

def children(self, types: Optional[Tuple[int, ...]] = None) -> Iterator[SNode]:
return iter_children(self.context, self.cdata, types=types)
def children(
self, types: Optional[Tuple[int, ...]] = None, with_choice: bool = False
) -> Iterator[SNode]:
return iter_children(
self.context, self.cdata, types=types, with_choice=with_choice
)


# -------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ def test_rpc_attrs(self):
self.assertEqual(self.rpc.nodetype(), SNode.RPC)
self.assertEqual(self.rpc.keyword(), "rpc")
self.assertEqual(self.rpc.schema_path(), "/yolo-system:format-disk")
choice = next(self.rpc.input().children((SNode.CHOICE,), with_choice=True))
self.assertIsInstance(choice, SChoice)

def test_rpc_extensions(self):
ext = list(self.rpc.extensions())
Expand Down
9 changes: 8 additions & 1 deletion tests/yang/yolo/yolo-system.yang
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,14 @@ module yolo-system {
ext:human-name "Disk";
type types:str;
}
anyxml html-info;
choice xml-or-json {
case xml {
anyxml html-info;
}
case json {
anydata json-info;
}
}
}
output {
leaf duration {
Expand Down