-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This patch allows user to use with_choices option in children() calls
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,8 +137,11 @@ def get_module_from_prefix(self, prefix: str) -> Optional["Module"]: | |
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_choices: bool = False | ||
This comment has been minimized.
Sorry, something went wrong.
samuel-gauthier
Collaborator
|
||
) -> Iterator["SNode"]: | ||
options = lib.LYS_GETNEXT_WITHCHOICE if with_choices else 0 | ||
return iter_children(self.context, self.cdata, types=types, options=options) | ||
|
||
def __str__(self) -> str: | ||
return self.name() | ||
|
@@ -1357,18 +1360,30 @@ def must_conditions(self) -> Iterator[str]: | |
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_choices: bool = False | ||
) -> Iterator[SNode]: | ||
options = lib.LYS_GETNEXT_WITHCHOICE if with_choices else 0 | ||
return iter_children(self.context, self.cdata, types=types, options=options) | ||
|
||
|
||
# ------------------------------------------------------------------------------------- | ||
@SNode.register(SNode.CHOICE) | ||
class SChoice(SNode): | ||
__slots__ = ("cdata_choice",) | ||
|
||
def __init__(self, context: "libyang.Context", cdata): | ||
super().__init__(context, cdata) | ||
self.cdata_choice = ffi.cast("struct lysc_node_choice *", cdata) | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
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_cases: bool = False | ||
) -> Iterator[SNode]: | ||
options = lib.LYS_GETNEXT_WITHCASE if with_cases else 0 | ||
return iter_children(self.context, self.cdata, types=types, options=options) | ||
|
||
|
||
# ------------------------------------------------------------------------------------- | ||
|
@@ -1377,8 +1392,11 @@ class SCase(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_choices: bool = False | ||
) -> Iterator[SNode]: | ||
options = lib.LYS_GETNEXT_WITHCHOICE if with_choices else 0 | ||
return iter_children(self.context, self.cdata, types=types, options=options) | ||
|
||
|
||
# ------------------------------------------------------------------------------------- | ||
|
@@ -1398,9 +1416,15 @@ def __iter__(self) -> Iterator[SNode]: | |
return self.children() | ||
|
||
def children( | ||
self, skip_keys: bool = False, types: Optional[Tuple[int, ...]] = None | ||
self, | ||
skip_keys: bool = False, | ||
types: Optional[Tuple[int, ...]] = None, | ||
with_choices: bool = False, | ||
) -> Iterator[SNode]: | ||
return iter_children(self.context, self.cdata, skip_keys=skip_keys, types=types) | ||
options = lib.LYS_GETNEXT_WITHCHOICE if with_choices else 0 | ||
return iter_children( | ||
self.context, self.cdata, skip_keys=skip_keys, types=types, options=options | ||
) | ||
|
||
def keys(self) -> Iterator[SNode]: | ||
node = lib.lysc_node_child(self.cdata) | ||
|
@@ -1498,15 +1522,19 @@ def iter_children( | |
options: int = 0, | ||
) -> Iterator[SNode]: | ||
if types is None: | ||
types = ( | ||
types = [ | ||
lib.LYS_ACTION, | ||
lib.LYS_CONTAINER, | ||
lib.LYS_LIST, | ||
lib.LYS_RPC, | ||
lib.LYS_LEAF, | ||
lib.LYS_LEAFLIST, | ||
lib.LYS_NOTIF, | ||
) | ||
] | ||
if options & lib.LYS_GETNEXT_WITHCHOICE: | ||
types.append(lib.LYS_CHOICE) | ||
This comment has been minimized.
Sorry, something went wrong.
samuel-gauthier
Collaborator
|
||
if options & lib.LYS_GETNEXT_WITHCASE: | ||
types.append(lib.LYS_CASE) | ||
|
||
def _skip(node) -> bool: | ||
if node.nodetype not in types: | ||
|
I don't think this is needed (see below).