コード例 #1
0
    def __getitem__(self, *args):
        context = self._context
        node = self._node
        (keys,
         values) = Common.Utils.get_key_val_tuples(context, node, list(args))
        predicates = Common.Utils.encode_xpath_predicates('', keys, values)
        if not context.dal.has_item(node.real_data_path + predicates):
            raise Errors.ListDoesNotContainElement(node.real_data_path +
                                                   predicates)

        # Return Object
        new_node = Common.YangNode(node.libyang_node, node.real_schema_path,
                                   node.real_data_path + predicates)
        return ListElement(context, new_node, self)
コード例 #2
0
    def get(self, *args):
        """
        Get an item from the list

        Example:
          node.get(value)                   - fetch item where there is a single key.
          node.get(value1, value2)          - fetch item where there is a composite key.

        Returns a ListElement Node.

        Alternatively access data by node[value] or node[value1, value2]
        """
        context = self._context
        node = self._node
        (keys,
         values) = Common.Utils.get_key_val_tuples(context, node, list(args))
        predicates = Common.Utils.encode_xpath_predicates('', keys, values)
        if not context.dal.has_item(node.real_data_path + predicates):
            raise Errors.ListDoesNotContainElement(node.real_data_path +
                                                   predicates)
        # Return Object
        new_node = Common.YangNode(node.libyang_node, node.real_schema_path,
                                   node.real_data_path + predicates)
        return ListElement(context, new_node, self)