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