diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-28 12:29:25 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-15 14:14:03 +0000 |
commit | 8565ab2b3340c73f142cbb40c2c49d458de39370 (patch) | |
tree | ed1555db5df6f25a54052529f06ea08f84864a10 /src/buildstream/_yaml.pyx | |
parent | c86de17c83ef09d51dd6deddf65c31c28a16eb73 (diff) | |
download | buildstream-8565ab2b3340c73f142cbb40c2c49d458de39370.tar.gz |
_cachekey: Remove the 'node_sanitization' done before the json string
Since ujson already sorts the keys, we just need to be able to jsonify
Nodes sensibly. This is done by implementing __json__ on the 'Node' base
class.
This does not break the cache keys.
Diffstat (limited to 'src/buildstream/_yaml.pyx')
-rw-r--r-- | src/buildstream/_yaml.pyx | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx index d68f64772..82262f60b 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -29,6 +29,7 @@ from collections.abc import Mapping, Sequence from copy import deepcopy from ruamel import yaml + from ._exceptions import LoadError, LoadErrorReason @@ -83,6 +84,12 @@ cdef class Node: cpdef Node copy(self): raise NotImplementedError() + cpdef object strip_node_info(self): + raise NotImplementedError() + + def __json__(self): + raise ValueError("Nodes should not be allowed when jsonify-ing data", self) + cdef class ScalarNode(Node): @@ -132,6 +139,9 @@ cdef class ScalarNode(Node): return None return str(self.value) + cpdef object strip_node_info(self): + return self.value + cdef bint _walk_find(self, Node target, list path) except *: return self._shares_position_with(target) @@ -270,6 +280,12 @@ cdef class MappingNode(Node): cpdef object values(self): return self.value.values() + cpdef object strip_node_info(self): + cdef str key + cdef Node value + + return {key: value.strip_node_info() for key, value in self.value.items()} + def __delitem__(self, str key): del self.value[key] @@ -362,6 +378,10 @@ cdef class SequenceNode(Node): cpdef list as_str_list(self): return [node.as_str() for node in self.value] + cpdef object strip_node_info(self): + cdef Node value + return [value.strip_node_info() for value in self.value] + cdef bint _walk_find(self, Node target, list path) except *: cdef int i cdef Node v |