@@ -1119,38 +1119,37 @@ def cdata_leaf_value(cdata, context: "libyang.Context" = None) -> Any:
1119
1119
return None
1120
1120
1121
1121
val = c2str (val )
1122
- term_node = ffi .cast ("struct lyd_node_term *" , cdata )
1123
- val_type = ffi .new ("const struct lysc_type **" , ffi .NULL )
1124
-
1125
- # get real value type
1126
- ctx = context .cdata if context else ffi .NULL
1127
- ret = lib .lyd_value_validate (
1128
- ctx ,
1129
- term_node .schema ,
1130
- str2c (val ),
1131
- len (val ),
1132
- ffi .NULL ,
1133
- val_type ,
1134
- ffi .NULL ,
1135
- )
1136
1122
1137
- if ret in (lib .LY_SUCCESS , lib .LY_EINCOMPLETE ):
1138
- val_type = val_type [0 ].basetype
1139
- if val_type in Type .STR_TYPES :
1140
- return val
1141
- if val_type in Type .NUM_TYPES :
1142
- return int (val )
1143
- if val_type == Type .BOOL :
1144
- return val == "true"
1145
- if val_type == Type .DEC64 :
1146
- return float (val )
1147
- if val_type == Type .LEAFREF :
1148
- return DLeaf .cdata_leaf_value (cdata .value .leafref , context )
1149
- if val_type == Type .EMPTY :
1150
- return None
1123
+ if cdata .schema == ffi .NULL :
1124
+ # opaq node
1151
1125
return val
1152
1126
1153
- raise TypeError ("value type validation error" )
1127
+ if cdata .schema .nodetype == SNode .LEAF :
1128
+ snode = ffi .cast ("struct lysc_node_leaf *" , cdata .schema )
1129
+ elif cdata .schema .nodetype == SNode .LEAFLIST :
1130
+ snode = ffi .cast ("struct lysc_node_leaflist *" , cdata .schema )
1131
+
1132
+ # find the real type used
1133
+ cdata = ffi .cast ("struct lyd_node_term *" , cdata )
1134
+ curr_type = snode .type
1135
+ while curr_type .basetype in (Type .LEAFREF , Type .UNION ):
1136
+ if curr_type .basetype == Type .LEAFREF :
1137
+ curr_type = cdata .value .realtype
1138
+ if curr_type .basetype == Type .UNION :
1139
+ curr_type = cdata .value .subvalue .value .realtype
1140
+
1141
+ val_type = curr_type .basetype
1142
+ if val_type in Type .STR_TYPES :
1143
+ return val
1144
+ if val_type in Type .NUM_TYPES :
1145
+ return int (val )
1146
+ if val_type == Type .BOOL :
1147
+ return val == "true"
1148
+ if val_type == Type .DEC64 :
1149
+ return float (val )
1150
+ if val_type == Type .EMPTY :
1151
+ return None
1152
+ return val
1154
1153
1155
1154
1156
1155
# -------------------------------------------------------------------------------------
0 commit comments