aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-12-13 16:37:06 +0400
committerMarkus Armbruster <armbru@redhat.com>2018-12-13 19:20:11 +0100
commit563bd35d87f7bcab644381319d6247e8aee8a4f4 (patch)
treef7886509c80b6ec43e4a5234fe41d90b4f536c5c /scripts
parent1e381b655910b515d7c52fc60b67b4167dd9c4c6 (diff)
downloadqemu-563bd35d87f7bcab644381319d6247e8aee8a4f4.zip
qemu-563bd35d87f7bcab644381319d6247e8aee8a4f4.tar.gz
qemu-563bd35d87f7bcab644381319d6247e8aee8a4f4.tar.bz2
qapi: factor out checking for keys
Introduce a new helper function to check if the given keys are known, and if mandatory keys are present. The function will be reused in other places in the following code changes. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20181213123724.4866-5-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi/common.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 1fa2f79..18f5872 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -873,6 +873,17 @@ def check_struct(expr, info):
allow_metas=['struct'])
+def check_known_keys(info, source, keys, required, optional):
+ for key in keys:
+ if key not in required and key not in optional:
+ raise QAPISemError(info, "Unknown key '%s' in %s" % (key, source))
+
+ for key in required:
+ if key not in keys:
+ raise QAPISemError(info, "Key '%s' is missing from %s"
+ % (key, source))
+
+
def check_keys(expr_elem, meta, required, optional=[]):
expr = expr_elem['expr']
info = expr_elem['info']
@@ -880,10 +891,9 @@ def check_keys(expr_elem, meta, required, optional=[]):
if not isinstance(name, str):
raise QAPISemError(info, "'%s' key must have a string value" % meta)
required = required + [meta]
+ source = "%s '%s'" % (meta, name)
+ check_known_keys(info, source, expr.keys(), required, optional)
for (key, value) in expr.items():
- if key not in required and key not in optional:
- raise QAPISemError(info, "Unknown key '%s' in %s '%s'"
- % (key, meta, name))
if key in ['gen', 'success-response'] and value is not False:
raise QAPISemError(info,
"'%s' of %s '%s' should only use false value"
@@ -895,10 +905,6 @@ def check_keys(expr_elem, meta, required, optional=[]):
% (key, meta, name))
if key == 'if':
check_if(expr, info)
- for key in required:
- if key not in expr:
- raise QAPISemError(info, "Key '%s' is missing from %s '%s'"
- % (key, meta, name))
def check_exprs(exprs):