[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 18/32] qapi: factor out checking for keys
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 18/32] qapi: factor out checking for keys |
Date: |
Thu, 13 Dec 2018 19:43:26 +0100 |
From: Marc-André Lureau <address@hidden>
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 <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
scripts/qapi/common.py | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 1fa2f79990..18f5872808 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):
--
2.17.2
- [Qemu-devel] [PULL 21/32] qapi: add 'if' to enum members, (continued)
- [Qemu-devel] [PULL 21/32] qapi: add 'if' to enum members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 01/32] cutils: Add qemu_strtod() and qemu_strtod_finite(), Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 09/32] test-string-input-visitor: Add range overflow tests, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 32/32] qapi: add conditions to REPLICATION type/commands on the schema, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 26/32] qapi: add 'if' to alternate members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 20/32] qapi: add a dictionary form with 'name' key for enum members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 25/32] qapi: add 'if' to union members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 11/32] json: Fix to reject duplicate object member names, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 29/32] qapi: add 'If:' condition to struct members documentation, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 16/32] qapi: change enum visitor and gen_enum* to take QAPISchemaMember, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 18/32] qapi: factor out checking for keys,
Markus Armbruster <=
- [Qemu-devel] [PULL 24/32] qapi: Add 'if' to implicit struct members, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 22/32] qapi-events: add 'if' condition to implicit event enum, Markus Armbruster, 2018/12/13
- [Qemu-devel] [PULL 23/32] qapi: add a dictionary form for TYPE, Markus Armbruster, 2018/12/13
- Re: [Qemu-devel] [PULL 00/32] QAPI patches for 2018-12-13, Markus Armbruster, 2018/12/14