@@ -112,6 +112,17 @@ def revisions(self) -> Iterator["Revision"]:
112112 for revision in ly_array_iter (self .cdata .parsed .revs ):
113113 yield Revision (self .context , revision , self )
114114
115+ def typedefs (self ) -> Iterator ["Typedef" ]:
116+ for typedef in ly_array_iter (self .cdata .parsed .typedefs ):
117+ yield Typedef (self .context , typedef )
118+
119+ def get_typedef (self , name : str ) -> Optional ["Typedef" ]:
120+ for typedef in self .typedefs ():
121+ if typedef .name () != name :
122+ continue
123+ return typedef
124+ return None
125+
115126 def imports (self ) -> Iterator ["Import" ]:
116127 for i in ly_array_iter (self .cdata .parsed .imports ):
117128 yield Import (self .context , i , self )
@@ -533,6 +544,14 @@ def leafref_path(self) -> Optional["str"]:
533544 lr = ffi .cast ("struct lysc_type_leafref *" , self .cdata )
534545 return c2str (lib .lyxp_get_expr (lr .path ))
535546
547+ def typedef (self ) -> "Typedef" :
548+ if ":" in self .name ():
549+ module_prefix , type_name = self .name ().split (":" )
550+ import_module = self .module ().get_module_from_prefix (module_prefix )
551+ if import_module :
552+ return import_module .get_typedef (type_name )
553+ return None
554+
536555 def union_types (self ) -> Iterator ["Type" ]:
537556 if self .cdata .basetype != self .UNION :
538557 return
@@ -662,6 +681,59 @@ def __str__(self):
662681 return self .name ()
663682
664683
684+ # -------------------------------------------------------------------------------------
685+ class Typedef :
686+ __slots__ = ("context" , "cdata" , "__dict__" )
687+
688+ def __init__ (self , context : "libyang.Context" , cdata ):
689+ self .context = context
690+ self .cdata = cdata # C type: "struct lysp_tpdf *"
691+
692+ def name (self ) -> str :
693+ return c2str (self .cdata .name )
694+
695+ def description (self ) -> Optional [str ]:
696+ return c2str (self .cdata .dsc )
697+
698+ def units (self ) -> Optional [str ]:
699+ return c2str (self .cdata .units )
700+
701+ def reference (self ) -> Optional [str ]:
702+ return c2str (self .cdata .ref )
703+
704+ def extensions (self ) -> Iterator [ExtensionCompiled ]:
705+ ext = ffi .cast ("struct lysc_ext_instance *" , self .cdata .exts )
706+ if ext == ffi .NULL :
707+ return
708+ for extension in ly_array_iter (ext ):
709+ yield ExtensionCompiled (self .context , extension )
710+
711+ def get_extension (
712+ self , name : str , prefix : Optional [str ] = None , arg_value : Optional [str ] = None
713+ ) -> Optional [ExtensionCompiled ]:
714+ for ext in self .extensions ():
715+ if ext .name () != name :
716+ continue
717+ if prefix is not None and ext .module ().name () != prefix :
718+ continue
719+ if arg_value is not None and ext .argument () != arg_value :
720+ continue
721+ return ext
722+ return None
723+
724+ def deprecated (self ) -> bool :
725+ return bool (self .cdata .flags & lib .LYS_STATUS_DEPRC )
726+
727+ def obsolete (self ) -> bool :
728+ return bool (self .cdata .flags & lib .LYS_STATUS_OBSLT )
729+
730+ def module (self ) -> Module :
731+ return Module (self .context , self .cdata .module )
732+
733+ def __str__ (self ):
734+ return self .name ()
735+
736+
665737# -------------------------------------------------------------------------------------
666738class Feature :
667739 __slots__ = ("context" , "cdata" , "__dict__" )
0 commit comments