Skip to content

Commit d3dd5f0

Browse files
stewegrjarry
authored andcommitted
schema: adds ability to get various outputs as extension parent_node
This patch adds ability to get also PRefine, PType and PEnum as a valid output using extension parent_node function Signed-off-by: Stefan Gula <steweg@gmail.com>
1 parent 4147016 commit d3dd5f0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

libyang/schema.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,21 @@ def name(self) -> str:
423423
def module(self) -> Module:
424424
return self._module_from_parsed()
425425

426-
def parent_node(self) -> Optional[Union["PNode", "PIdentity"]]:
426+
def parent_node(
427+
self,
428+
) -> Optional[Union["PNode", "PIdentity", "PRefine", "PType", "PEnum"]]:
427429
if self.cdata.parent_stmt == lib.LY_STMT_IDENTITY:
428430
cdata = ffi.cast("struct lysp_ident *", self.cdata.parent)
429431
return PIdentity(self.context, cdata, self.module_parent)
432+
if self.cdata.parent_stmt == lib.LY_STMT_REFINE:
433+
cdata = ffi.cast("struct lysp_refine *", self.cdata.parent)
434+
return PRefine(self.context, cdata, self.module_parent)
435+
if self.cdata.parent_stmt == lib.LY_STMT_TYPE:
436+
cdata = ffi.cast("struct lysp_type *", self.cdata.parent)
437+
return PType(self.context, cdata, self.module_parent)
438+
if self.cdata.parent_stmt == lib.LY_STMT_ENUM:
439+
cdata = ffi.cast("struct lysp_type_enum *", self.cdata.parent)
440+
return PEnum(self.context, cdata, self.module_parent)
430441
if bool(self.cdata.parent_stmt & lib.LY_STMT_NODE_MASK):
431442
try:
432443
return PNode.new(self.context, self.cdata.parent, self.module_parent)

0 commit comments

Comments
 (0)