From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com
Subject: [Qemu-devel] [PATCH v8 04/22] qapi: factor out checking for keys
Date: Thu, 13 Dec 2018 16:37:06 +0400 [thread overview]
Message-ID: <20181213123724.4866-5-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20181213123724.4866-1-marcandre.lureau@redhat.com>
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>
---
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.20.0
next prev parent reply other threads:[~2018-12-13 12:38 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-13 12:37 [Qemu-devel] [PATCH v8 00/22] qapi: add #if pre-processor conditions to generated code (part 2) Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 01/22] qapi: Do not define enumeration value explicitly Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 02/22] qapi: change enum visitor and gen_enum* to take QAPISchemaMember Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 03/22] tests: print enum type members more like object type members Marc-André Lureau
2018-12-13 12:37 ` Marc-André Lureau [this message]
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 05/22] qapi: improve reporting of unknown or missing keys Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 06/22] qapi: add a dictionary form with 'name' key for enum members Marc-André Lureau
2018-12-13 13:23 ` Markus Armbruster
2018-12-13 14:32 ` Markus Armbruster
2018-12-13 14:35 ` Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 07/22] qapi: pass long form enum to make_enum_members Marc-André Lureau
2018-12-13 14:29 ` Markus Armbruster
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 08/22] qapi: simplify make_enum_members() Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 09/22] qapi: add 'if' to enum members Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 10/22] qapi-events: add 'if' condition to implicit event enum Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 11/22] qapi: rename allow_dict to allow_implicit Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 12/22] qapi: add a dictionary form for TYPE Marc-André Lureau
2018-12-13 13:31 ` Markus Armbruster
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 13/22] qapi: add 'if' to implicit struct members Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 14/22] qapi: add an error in case a discriminator is conditional Marc-André Lureau
2018-12-13 13:34 ` Markus Armbruster
2018-12-13 15:45 ` Markus Armbruster
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 15/22] qapi: add 'if' to union members Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 16/22] qapi: add 'if' to alternate members Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 17/22] qapi: add #if conditions to generated code members Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 18/22] qapi: add 'If:' condition to enum values documentation Marc-André Lureau
2018-12-13 14:03 ` Markus Armbruster
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 19/22] qapi: add 'If:' condition to struct members documentation Marc-André Lureau
2018-12-13 14:05 ` Markus Armbruster
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 20/22] qapi: add condition to variants documentation Marc-André Lureau
2018-12-13 14:06 ` Markus Armbruster
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 21/22] qapi: add more conditions to SPICE Marc-André Lureau
2018-12-13 12:37 ` [Qemu-devel] [PATCH v8 22/22] qapi: add conditions to REPLICATION type/commands on the schema Marc-André Lureau
2018-12-13 14:47 ` [Qemu-devel] [PATCH v8 00/22] qapi: add #if pre-processor conditions to generated code (part 2) Markus Armbruster
2018-12-13 14:52 ` Marc-André Lureau
2018-12-13 16:52 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181213123724.4866-5-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).