def _to_dict(node, parent_dic): if not lib.lyd_node_should_print(node, flags): return name = _node_name(node) if node.schema.nodetype == SNode.LIST: list_element = {} child = node.child while child: _to_dict(child, list_element) child = child.next if name not in parent_dic: parent_dic[name] = _init_yang_list(node.schema) parent_dic[name].append(list_element) elif node.schema.nodetype & (SNode.CONTAINER | SNode.RPC | SNode.ACTION): container = {} child = node.child while child: _to_dict(child, container) child = child.next parent_dic[name] = container elif node.schema.nodetype == SNode.LEAFLIST: if name not in parent_dic: parent_dic[name] = _init_yang_list(node.schema) parent_dic[name].append(DLeaf.cdata_leaf_value(node)) elif node.schema.nodetype == SNode.LEAF: parent_dic[name] = DLeaf.cdata_leaf_value(node)
def _to_dict(node, parent_dic): if not lib.lyd_node_should_print(node._node, flags): return if strip_prefixes: name = node.name() else: name = '%s:%s' % (node.module().name(), node.name()) if isinstance(node, DList): list_element = {} for child in node: _to_dict(child, list_element) parent_dic.setdefault(name, []).append(list_element) elif isinstance(node, (DContainer, DRpc)): container = {} for child in node: _to_dict(child, container) parent_dic[name] = container elif isinstance(node, DLeafList): parent_dic.setdefault(name, []).append(node.value()) elif isinstance(node, DLeaf): parent_dic[name] = node.value()
def should_print( self, include_implicit_defaults: bool = False, trim_default_values: bool = False, keep_empty_containers: bool = False, ) -> bool: """ Check if a node should be "printed". :arg bool include_implicit_defaults: Include implicit default nodes. :arg bool trim_default_values: Exclude nodes with the value equal to their default value. :arg bool keep_empty_containers: Preserve empty non-presence containers. """ flags = printer_flags( include_implicit_defaults=include_implicit_defaults, trim_default_values=trim_default_values, keep_empty_containers=keep_empty_containers, ) return bool(lib.lyd_node_should_print(self.cdata, flags))