diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-06-25 21:14:40 +0100 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-27 15:08:11 +0100 |
commit | 4e66ca802766545084018441b2a2ddda81c34f2f (patch) | |
tree | 6b1c532cb502a78ca769d73c71ddbf724dad3d08 /src/buildstream/_yaml.pyx | |
parent | 4652bfa0cbd86bdf24dae416b75c2607e5edcd41 (diff) | |
download | buildstream-bschubert/node-api-keys.tar.gz |
_yaml: Remove 'node_items' and add 'MappingNode.items()'bschubert/node-api-keys
One difference is that 'MappingNode.items()' does not strip the
provenance from scalars and lists, which ends up not affecting the
code much.
Diffstat (limited to 'src/buildstream/_yaml.pyx')
-rw-r--r-- | src/buildstream/_yaml.pyx | 42 |
1 files changed, 3 insertions, 39 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx index e3d3f7df3..ae00924bc 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -232,6 +232,9 @@ cdef class MappingNode(Node): cdef ScalarNode scalar = self.get_scalar(key, default) return scalar.as_str() + cpdef object items(self): + return self.value.items() + cpdef list keys(self): return list(self.value.keys()) @@ -736,20 +739,6 @@ cpdef ProvenanceInformation node_get_provenance(Node node, str key=None, list in return ProvenanceInformation(nodeish) -cdef list __trim_list_provenance(list value): - cdef list ret = [] - cdef Node entry - - for entry in value: - if type(entry.value) is list: - ret.append(__trim_list_provenance(entry.value)) - elif type(entry.value) is dict: - ret.append(entry) - else: - ret.append(entry.value) - return ret - - # node_set() # # Set an item within the node. If using `indices` be aware that the entry must @@ -833,31 +822,6 @@ def node_extend_list(Node node, str key, Py_ssize_t length, object default): the_list.append(_create_node(value, file_index, line_num, next_synthetic_counter())) -# node_items() -# -# A convenience generator for iterating over loaded key/value -# tuples in a dictionary loaded from project YAML. -# -# Args: -# node (Node): The dictionary node -# -# Yields: -# (str): The key name -# (anything): The value for the key -# -def node_items(Node node): - cdef str key - cdef Node value - - for key, value in node.value.items(): - if type(value.value) is dict: - yield (key, value) - elif type(value.value) is list: - yield (key, __trim_list_provenance(value.value)) - else: - yield (key, value.value) - - # is_node() # # A test method which returns whether or not the passed in value |