def cdata_leaf_value(cdata) -> Any: cdata = ffi.cast("struct lyd_node_leaf_list *", cdata) val_type = cdata.value_type if val_type in Type.STR_TYPES: return c2str(cdata.value_str) if val_type in Type.NUM_TYPES: return int(c2str(cdata.value_str)) if val_type == Type.BOOL: return bool(cdata.value.bln) if val_type == Type.DEC64: return lib.lyd_dec64_to_double(ffi.cast("struct lyd_node *", cdata)) if val_type == Type.LEAFREF: return DLeaf.cdata_leaf_value(cdata.value.leafref) return None
def value(self): if self._leaf.value_type == Type.EMPTY: return None if self._leaf.value_type in Type.NUM_TYPES: return int(c2str(self._leaf.value_str)) if self._leaf.value_type in (Type.STRING, Type.BINARY, Type.ENUM, Type.IDENT, Type.BITS): return c2str(self._leaf.value_str) if self._leaf.value_type == Type.DEC64: return lib.lyd_dec64_to_double(self._node) if self._leaf.value_type == Type.LEAFREF: referenced = DNode.new(self.context, self._leaf.value.leafref) return referenced.value() if self._leaf.value_type == Type.BOOL: return bool(self._leaf.value.bln) return None