summaryrefslogtreecommitdiff
path: root/src/buildstream/_yaml.pyx
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-06-25 21:14:40 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-15 14:14:03 +0000
commit1aa0fb1fefa7e86586831a13200a92f6dd9bd3b4 (patch)
tree8e675fc215ab9f1fcf8851470c95c0e2039f42ee /src/buildstream/_yaml.pyx
parent42d3d8406a15cd5f6f4a7d00e298dba019a50ed6 (diff)
downloadbuildstream-1aa0fb1fefa7e86586831a13200a92f6dd9bd3b4.tar.gz
_yaml: Remove 'node_items' and add 'MappingNode.items()'
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.pyx42
1 files changed, 3 insertions, 39 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index a00691b0e..c1cc21d70 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -229,6 +229,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())
@@ -733,20 +736,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
@@ -830,31 +819,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