66
77from _libyang import ffi , lib
88from .keyed_list import KeyedList
9- from .schema import Module , SContainer , SLeaf , SLeafList , SList , SNode , SRpc , Type
9+ from .schema import (
10+ Module ,
11+ SContainer ,
12+ SLeaf ,
13+ SLeafList ,
14+ SList ,
15+ SNode ,
16+ SNotif ,
17+ SRpc ,
18+ Type ,
19+ )
1020from .util import LibyangError , c2str , deprecated , str2c
1121
1222
@@ -69,16 +79,20 @@ def parser_flags(
6979 edit : bool = False ,
7080 rpc : bool = False ,
7181 rpcreply : bool = False ,
82+ notification : bool = False ,
7283 strict : bool = False ,
7384 trusted : bool = False ,
7485 no_yanglib : bool = False ,
7586 destruct : bool = False ,
7687 no_siblings : bool = False ,
7788 explicit : bool = False ,
7889) -> int :
79- if (data , config , get , getconfig , edit , rpc , rpcreply ).count (True ) > 1 :
90+ if (data , config , get , getconfig , edit , rpc , rpcreply , notification ).count (
91+ True
92+ ) > 1 :
8093 raise ValueError (
81- "Only one of data, config, get, getconfig, edit, rpc, rpcreply can be True"
94+ "Only one of data, config, get, getconfig, edit, rpc, rpcreply, "
95+ "notification can be True"
8296 )
8397 flags = 0
8498 if data :
@@ -95,6 +109,8 @@ def parser_flags(
95109 flags |= lib .LYD_OPT_RPC
96110 if rpcreply :
97111 flags |= lib .LYD_OPT_RPCREPLY
112+ if notification :
113+ flags |= lib .LYD_OPT_NOTIF
98114 if strict :
99115 flags |= lib .LYD_OPT_STRICT
100116 if trusted :
@@ -261,6 +277,7 @@ def validate(
261277 edit : bool = False ,
262278 rpc : bool = False ,
263279 rpcreply : bool = False ,
280+ notification : bool = False ,
264281 no_yanglib : bool = False ,
265282 ) -> None :
266283 if self .cdata .parent :
@@ -273,6 +290,7 @@ def validate(
273290 edit = edit ,
274291 rpc = rpc ,
275292 rpcreply = rpcreply ,
293+ notification = notification ,
276294 no_yanglib = no_yanglib ,
277295 )
278296 node_p = ffi .new ("struct lyd_node **" )
@@ -476,7 +494,9 @@ def _to_dict(node, parent_dic):
476494 if name not in parent_dic :
477495 parent_dic [name ] = _init_yang_list (node .schema )
478496 parent_dic [name ].append (list_element )
479- elif node .schema .nodetype & (SNode .CONTAINER | SNode .RPC | SNode .ACTION ):
497+ elif node .schema .nodetype & (
498+ SNode .CONTAINER | SNode .RPC | SNode .ACTION | SNode .NOTIF
499+ ):
480500 container = {}
481501 child = node .child
482502 while child :
@@ -666,6 +686,12 @@ class DLeafList(DLeaf):
666686 pass
667687
668688
689+ # -------------------------------------------------------------------------------------
690+ @DNode .register (SNode .NOTIF )
691+ class DNotif (DContainer ):
692+ pass
693+
694+
669695# -------------------------------------------------------------------------------------
670696def dict_to_dnode (
671697 dic : Dict [str , Any ],
@@ -678,6 +704,7 @@ def dict_to_dnode(
678704 edit : bool = False ,
679705 rpc : bool = False ,
680706 rpcreply : bool = False ,
707+ notification : bool = False ,
681708 strict : bool = False ,
682709 no_yanglib : bool = False ,
683710 validate : bool = True ,
@@ -709,6 +736,8 @@ def dict_to_dnode(
709736 Data represents RPC or action input parameters.
710737 :arg rpcreply:
711738 Data represents RPC or action output parameters.
739+ :arg notification:
740+ Data represents notification parameters.
712741 :arg strict:
713742 Instead of ignoring (with a warning message) data without schema definition,
714743 raise an error.
@@ -874,6 +903,10 @@ def _to_dnode(_dic, _schema, _parent=ffi.NULL, in_rpc_output=False):
874903 n = _create_container (_parent , module , name , in_rpc_output )
875904 _to_dnode (v , s , n , in_rpc_output )
876905
906+ elif isinstance (s , SNotif ):
907+ n = _create_container (_parent , module , name , in_rpc_output )
908+ _to_dnode (value , s , n , in_rpc_output )
909+
877910 result = None
878911
879912 try :
@@ -900,6 +933,7 @@ def _to_dnode(_dic, _schema, _parent=ffi.NULL, in_rpc_output=False):
900933 edit = edit ,
901934 rpc = rpc ,
902935 rpcreply = rpcreply ,
936+ notification = notification ,
903937 no_yanglib = no_yanglib ,
904938 )
905939 except :
0 commit comments