Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8408ce

Browse files
committed
data: add missing DataType's
Simplify the code to using python enum functionality. Signed-off-by: Christian Hopps <[email protected]>
1 parent 3072af0 commit f8408ce

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
@@ -174,22 +174,10 @@ def dup_flags(
174174

175175

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

194182

195183
# -------------------------------------------------------------------------------------

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)