diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-07-03 18:01:30 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-15 14:14:03 +0000 |
commit | 8c9f41922ad16f8a031ac612bb35e493e8581380 (patch) | |
tree | cebc4afe2d0238033362905a99400d4d2824d7dc /src/buildstream/_yaml.pyx | |
parent | d8466183f77c75bbd7ad27c7cbf5e58189945be1 (diff) | |
download | buildstream-8c9f41922ad16f8a031ac612bb35e493e8581380.tar.gz |
_yaml: Remove 'node_validate' and replace by 'MappingNode.validate_keys'
- adapt all call sites to use the new API
Diffstat (limited to 'src/buildstream/_yaml.pyx')
-rw-r--r-- | src/buildstream/_yaml.pyx | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx index 07209aa1f..1bdc43e6d 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -372,6 +372,30 @@ cdef class MappingNode(Node): except KeyError: pass + # validate_keys() + # + # Validate the node so as to ensure the user has not specified + # any keys which are unrecognized by buildstream (usually this + # means a typo which would otherwise not trigger an error). + # + # Args: + # valid_keys (list): A list of valid keys for the specified node + # + # Raises: + # LoadError: In the case that the specified node contained + # one or more invalid keys + # + cpdef void validate_keys(self, list valid_keys) except *: + # Probably the fastest way to do this: https://stackoverflow.com/a/23062482 + cdef set valid_keys_set = set(valid_keys) + cdef str key + + for key in self.value: + if key not in valid_keys_set: + provenance = node_get_provenance(self, key=key) + raise LoadError(LoadErrorReason.INVALID_DATA, + "{}: Unexpected key: {}".format(provenance, key)) + cpdef object values(self): return self.value.values() @@ -1177,33 +1201,6 @@ cdef Node _new_node_from_list(list inlist, Node ref_node): return ret -# node_validate() -# -# Validate the node so as to ensure the user has not specified -# any keys which are unrecognized by buildstream (usually this -# means a typo which would otherwise not trigger an error). -# -# Args: -# node (Node): A dictionary loaded from YAML -# valid_keys (list): A list of valid keys for the specified node -# -# Raises: -# LoadError: In the case that the specified node contained -# one or more invalid keys -# -cpdef void node_validate(Node node, list valid_keys) except *: - - # Probably the fastest way to do this: https://stackoverflow.com/a/23062482 - cdef set valid_keys_set = set(valid_keys) - cdef str key - - for key in node.value: - if key not in valid_keys_set: - provenance = node_get_provenance(node, key=key) - raise LoadError(LoadErrorReason.INVALID_DATA, - "{}: Unexpected key: {}".format(provenance, key)) - - # assert_symbol_name() # # A helper function to check if a loaded string is a valid symbol |