Skip to content

Commit e977f94

Browse files
choppsv1rjarry
authored andcommitted
data: add missing DataType's
Simplify the code to using python enum functionality. Signed-off-by: Christian Hopps <[email protected]>
1 parent aa3f506 commit e977f94

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

cffi/cdefs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ enum lyd_type {
296296
LYD_TYPE_REPLY_YANG,
297297
LYD_TYPE_RPC_NETCONF,
298298
LYD_TYPE_NOTIF_NETCONF,
299-
LYD_TYPE_REPLY_NETCONF
299+
LYD_TYPE_REPLY_NETCONF,
300+
LYD_TYPE_RPC_RESTCONF,
301+
LYD_TYPE_NOTIF_RESTCONF,
302+
LYD_TYPE_REPLY_RESTCONF
300303
};
301304

302305
#define LYD_PRINT_KEEPEMPTYCONT ...

libyang/data.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,10 @@ def dup_flags(
177177

178178

179179
# -------------------------------------------------------------------------------------
180-
def data_type(dtype):
181-
if dtype == DataType.DATA_YANG:
182-
return lib.LYD_TYPE_DATA_YANG
183-
if dtype == DataType.RPC_YANG:
184-
return lib.LYD_TYPE_RPC_YANG
185-
if dtype == DataType.NOTIF_YANG:
186-
return lib.LYD_TYPE_NOTIF_YANG
187-
if dtype == DataType.REPLY_YANG:
188-
return lib.LYD_TYPE_REPLY_YANG
189-
if dtype == DataType.RPC_NETCONF:
190-
return lib.LYD_TYPE_RPC_NETCONF
191-
if dtype == DataType.NOTIF_NETCONF:
192-
return lib.LYD_TYPE_NOTIF_NETCONF
193-
if dtype == DataType.REPLY_NETCONF:
194-
return lib.LYD_TYPE_REPLY_NETCONF
195-
raise ValueError("Unknown data type")
180+
def data_type(dtype: DataType) -> int:
181+
if not isinstance(dtype, DataType):
182+
dtype = DataType(dtype)
183+
return dtype.value
196184

197185

198186
# -------------------------------------------------------------------------------------

libyang/util.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,16 @@ class IOType(enum.Enum):
7777

7878
# -------------------------------------------------------------------------------------
7979
class DataType(enum.Enum):
80-
DATA_YANG = enum.auto()
81-
RPC_YANG = enum.auto()
82-
NOTIF_YANG = enum.auto()
83-
REPLY_YANG = enum.auto()
84-
RPC_NETCONF = enum.auto()
85-
NOTIF_NETCONF = enum.auto()
86-
REPLY_NETCONF = enum.auto()
80+
DATA_YANG = lib.LYD_TYPE_DATA_YANG
81+
RPC_YANG = lib.LYD_TYPE_RPC_YANG
82+
NOTIF_YANG = lib.LYD_TYPE_NOTIF_YANG
83+
REPLY_YANG = lib.LYD_TYPE_REPLY_YANG
84+
RPC_NETCONF = lib.LYD_TYPE_RPC_NETCONF
85+
NOTIF_NETCONF = lib.LYD_TYPE_NOTIF_NETCONF
86+
REPLY_NETCONF = lib.LYD_TYPE_REPLY_NETCONF
87+
RPC_RESTCONF = lib.LYD_TYPE_RPC_RESTCONF
88+
NOTIF_RESTCONF = lib.LYD_TYPE_NOTIF_RESTCONF
89+
REPLY_RESTCONF = lib.LYD_TYPE_REPLY_RESTCONF
8790

8891

8992
# -------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)