diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-09-06 16:52:26 +0100 |
---|---|---|
committer | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-09-13 17:10:10 +0100 |
commit | 06b4d3aeae88a30d922cd044feaf9f255946fe55 (patch) | |
tree | 0c0ab31cd4339fbe5d6bea24831c45056afa616d /buildstream | |
parent | 5b995dd1543b9476abfe6f1d42dc43cd5d0ea7dc (diff) | |
download | buildstream-06b4d3aeae88a30d922cd044feaf9f255946fe55.tar.gz |
Add _yaml.validate_node
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_yaml.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py index 5ba540fc9..aead2ed84 100644 --- a/buildstream/_yaml.py +++ b/buildstream/_yaml.py @@ -575,6 +575,19 @@ def node_sanitize(node): return node +def validate_node(node, valid_keys): + + # Probably the fastest way to do this: https://stackoverflow.com/a/23062482 + valid_keys = set(valid_keys) + valid_keys.add(PROVENANCE_KEY) + invalid = next((key for key in node if key not in valid_keys), None) + + if invalid: + provenance = node_get_provenance(node, key=invalid) + raise LoadError(LoadErrorReason.INVALID_DATA, + "[{}]: Unexpected key: {}".format(provenance, invalid)) + + def node_chain_copy(source): copy = collections.ChainMap({}, source) for key, value in source.items(): |