From nobody Sun Feb 8 22:57:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489647443799700.7674753665311; Wed, 15 Mar 2017 23:57:23 -0700 (PDT) Received: from localhost ([::1]:41252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coPLe-0004Dq-E2 for importer@patchew.org; Thu, 16 Mar 2017 02:57:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coOtZ-0006By-7m for qemu-devel@nongnu.org; Thu, 16 Mar 2017 02:28:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coOtQ-00076x-SY for qemu-devel@nongnu.org; Thu, 16 Mar 2017 02:28:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coOtQ-000733-Fq for qemu-devel@nongnu.org; Thu, 16 Mar 2017 02:28:12 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C66A80F98 for ; Thu, 16 Mar 2017 06:28:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E909C60F85 for ; Thu, 16 Mar 2017 06:28:11 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0779C113861F; Thu, 16 Mar 2017 07:28:06 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7C66A80F98 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7C66A80F98 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 16 Mar 2017 07:27:37 +0100 Message-Id: <1489645685-4750-22-git-send-email-armbru@redhat.com> In-Reply-To: <1489645685-4750-1-git-send-email-armbru@redhat.com> References: <1489645685-4750-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 16 Mar 2017 06:28:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for 2.9 21/49] qapi: Prefer single-quoted strings more consistently X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" PEP 8 advises: In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability. The QAPI generators succeed at picking a rule, but fail at sticking to it. Convert a bunch of double-quoted strings to single-quoted ones. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <1489582656-31133-20-git-send-email-armbru@redhat.com> --- scripts/qapi-event.py | 2 +- scripts/qapi-introspect.py | 4 +- scripts/qapi-types.py | 4 +- scripts/qapi-visit.py | 4 +- scripts/qapi.py | 96 +++++++++++++++++++++++-------------------= ---- scripts/qapi2texi.py | 46 +++++++++++----------- 6 files changed, 78 insertions(+), 78 deletions(-) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index f4eb7f8..0485e39 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -223,7 +223,7 @@ fdecl.write(mcgen(''' ''', prefix=3Dprefix)) =20 -event_enum_name =3D c_name(prefix + "QAPIEvent", protect=3DFalse) +event_enum_name =3D c_name(prefix + 'QAPIEvent', protect=3DFalse) =20 schema =3D QAPISchema(input_file) gen =3D QAPISchemaGenEventVisitor() diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index fb72c61..032bcea 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -170,10 +170,10 @@ const char %(c_name)s[] =3D %(c_string)s; opt_unmask =3D False =20 (input_file, output_dir, do_c, do_h, prefix, opts) =3D \ - parse_command_line("u", ["unmask-non-abi-names"]) + parse_command_line('u', ['unmask-non-abi-names']) =20 for o, a in opts: - if o in ("-u", "--unmask-non-abi-names"): + if o in ('-u', '--unmask-non-abi-names'): opt_unmask =3D True =20 c_comment =3D ''' diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index dabc42e..b45e7b5 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -244,10 +244,10 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): do_builtins =3D False =20 (input_file, output_dir, do_c, do_h, prefix, opts) =3D \ - parse_command_line("b", ["builtins"]) + parse_command_line('b', ['builtins']) =20 for o, a in opts: - if o in ("-b", "--builtins"): + if o in ('-b', '--builtins'): do_builtins =3D True =20 c_comment =3D ''' diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 330b9f3..3d3936e 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -335,10 +335,10 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): do_builtins =3D False =20 (input_file, output_dir, do_c, do_h, prefix, opts) =3D \ - parse_command_line("b", ["builtins"]) + parse_command_line('b', ['builtins']) =20 for o, a in opts: - if o in ("-b", "--builtins"): + if o in ('-b', '--builtins'): do_builtins =3D True =20 c_comment =3D ''' diff --git a/scripts/qapi.py b/scripts/qapi.py index 8088f60..8b7377e 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -58,9 +58,9 @@ all_names =3D {} =20 =20 def error_path(parent): - res =3D "" + res =3D '' while parent: - res =3D ("In file included from %s:%d:\n" % (parent['file'], + res =3D ('In file included from %s:%d:\n' % (parent['file'], parent['line'])) + res parent =3D parent['parent'] return res @@ -76,10 +76,10 @@ class QAPIError(Exception): self.msg =3D msg =20 def __str__(self): - loc =3D "%s:%d" % (self.fname, self.line) + loc =3D '%s:%d' % (self.fname, self.line) if self.col is not None: - loc +=3D ":%s" % self.col - return error_path(self.info) + "%s: %s" % (loc, self.msg) + loc +=3D ':%s' % self.col + return error_path(self.info) + '%s: %s' % (loc, self.msg) =20 =20 class QAPIParseError(QAPIError): @@ -113,7 +113,7 @@ class QAPIDoc(object): self.content.append(line) =20 def __repr__(self): - return "\n".join(self.content).strip() + return '\n'.join(self.content).strip() =20 class ArgSection(Section): def __init__(self, name): @@ -163,8 +163,8 @@ class QAPIDoc(object): # recognized, and get silently treated as ordinary text if self.symbol: self._append_symbol_line(line) - elif not self.body.content and line.startswith("@"): - if not line.endswith(":"): + elif not self.body.content and line.startswith('@'): + if not line.endswith(':'): raise QAPIParseError(self.parser, "Line should end with :") self.symbol =3D line[1:-1] # FIXME invalid names other than the empty string aren't flagg= ed @@ -176,14 +176,14 @@ class QAPIDoc(object): def _append_symbol_line(self, line): name =3D line.split(' ', 1)[0] =20 - if name.startswith("@") and name.endswith(":"): + if name.startswith('@') and name.endswith(':'): line =3D line[len(name)+1:] self._start_args_section(name[1:-1]) - elif name in ("Returns:", "Since:", + elif name in ('Returns:', 'Since:', # those are often singular or plural - "Note:", "Notes:", - "Example:", "Examples:", - "TODO:"): + 'Note:', 'Notes:', + 'Example:', 'Examples:', + 'TODO:'): line =3D line[len(name)+1:] self._start_section(name[:-1]) =20 @@ -203,8 +203,8 @@ class QAPIDoc(object): self.section =3D QAPIDoc.ArgSection(name) self.args[name] =3D self.section =20 - def _start_section(self, name=3D""): - if name in ("Returns", "Since") and self.has_section(name): + def _start_section(self, name=3D''): + if name in ('Returns', 'Since') and self.has_section(name): raise QAPIParseError(self.parser, "Duplicated '%s' section" % name) self.section =3D QAPIDoc.Section(name) @@ -217,7 +217,7 @@ class QAPIDoc(object): and line and not line[0].isspace()): self._start_section() if (in_arg or not self.section.name - or not self.section.name.startswith("Example")): + or not self.section.name.startswith('Example')): line =3D line.strip() # TODO Drop this once the dust has settled if (isinstance(self.section, QAPIDoc.ArgSection) @@ -262,7 +262,7 @@ class QAPISchemaParser(object): if 'include' in expr: if len(expr) !=3D 1: raise QAPISemError(info, "Invalid 'include' directive") - include =3D expr["include"] + include =3D expr['include'] if not isinstance(include, str): raise QAPISemError(info, "Value of 'include' must be a strin= g") @@ -347,7 +347,7 @@ class QAPISchemaParser(object): if not skip_comment: self.val =3D self.src[self.pos:self.cursor] return - elif self.tok in "{}:,[]": + elif self.tok in '{}:,[]': return elif self.tok =3D=3D "'": string =3D '' @@ -373,7 +373,7 @@ class QAPISchemaParser(object): for _ in range(0, 4): ch =3D self.src[self.cursor] self.cursor +=3D 1 - if ch not in "0123456789abcdefABCDEF": + if ch not in '0123456789abcdefABCDEF': raise QAPIParseError(self, '\\u escape needs= 4 ' 'hex digits') @@ -388,28 +388,28 @@ class QAPISchemaParser(object): 'only supports non-ze= ro ' 'values up to \\u007f= ') string +=3D chr(value) - elif ch in "\\/'\"": + elif ch in '\\/\'"': string +=3D ch else: raise QAPIParseError(self, "Unknown escape \\%s" % c= h) esc =3D False - elif ch =3D=3D "\\": + elif ch =3D=3D '\\': esc =3D True elif ch =3D=3D "'": self.val =3D string return else: string +=3D ch - elif self.src.startswith("true", self.pos): + elif self.src.startswith('true', self.pos): self.val =3D True self.cursor +=3D 3 return - elif self.src.startswith("false", self.pos): + elif self.src.startswith('false', self.pos): self.val =3D False self.cursor +=3D 4 return - elif self.src.startswith("null", self.pos): + elif self.src.startswith('null', self.pos): self.val =3D None self.cursor +=3D 3 return @@ -523,11 +523,11 @@ def find_alternate_member_qtype(qapi_type): if qapi_type in builtin_types: return builtin_types[qapi_type] elif find_struct(qapi_type): - return "QTYPE_QDICT" + return 'QTYPE_QDICT' elif find_enum(qapi_type): - return "QTYPE_QSTRING" + return 'QTYPE_QSTRING' elif find_union(qapi_type): - return "QTYPE_QDICT" + return 'QTYPE_QDICT' return None =20 =20 @@ -628,7 +628,7 @@ def find_union(name): def add_enum(name, info, enum_values=3DNone, implicit=3DFalse): global enum_types add_name(name, info, 'enum', implicit) - enum_types.append({"enum_name": name, "enum_values": enum_values}) + enum_types.append({'enum_name': name, 'enum_values': enum_values}) =20 =20 def find_enum(name): @@ -788,7 +788,7 @@ def check_union(expr, info): raise QAPISemError(info, "Discriminator value '%s' is not found = in " "enum '%s'" - % (key, enum_define["enum_name"])) + % (key, enum_define['enum_name'])) =20 # If discriminator is user-defined, ensure all values are covered if enum_define: @@ -993,7 +993,7 @@ def check_definition_doc(doc, expr, info): args =3D set([name.strip('*') for name in args]) if not doc_args.issubset(args): raise QAPISemError(info, "The following documented members are not= in " - "the declaration: %s" % ", ".join(doc_args - ar= gs)) + "the declaration: %s" % ', '.join(doc_args - ar= gs)) =20 =20 def check_docs(docs): @@ -1487,7 +1487,7 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): try: - parser =3D QAPISchemaParser(open(fname, "r")) + parser =3D QAPISchemaParser(open(fname, 'r')) self.exprs =3D check_exprs(parser.exprs) self.docs =3D check_docs(parser.docs) self._entity_dict =3D {} @@ -1740,8 +1740,8 @@ def camel_to_upper(value): l =3D len(c_fun_str) for i in range(l): c =3D c_fun_str[i] - # When c is upper and no "_" appears before, do more checks - if c.isupper() and (i > 0) and c_fun_str[i - 1] !=3D "_": + # When c is upper and no '_' appears before, do more checks + if c.isupper() and (i > 0) and c_fun_str[i - 1] !=3D '_': if i < l - 1 and c_fun_str[i + 1].islower(): new_name +=3D '_' elif c_fun_str[i - 1].isdigit(): @@ -1760,7 +1760,7 @@ c_name_trans =3D string.maketrans('.-', '__') =20 # Map @name to a valid C identifier. # If @protect, avoid returning certain ticklish identifiers (like -# C keywords) by prepending "q_". +# C keywords) by prepending 'q_'. # # Used for converting 'name' from a 'name':'type' qapi definition # into a generated struct member, as well as converting type names @@ -1798,7 +1798,7 @@ def c_name(name, protect=3DTrue): name =3D name.translate(c_name_trans) if protect and (name in c89_words | c99_words | c11_words | gcc_words | cpp_words | polluted_words): - return "q_" + name + return 'q_' + name return name =20 eatspace =3D '\033EATSPACE.' @@ -1806,9 +1806,9 @@ pointer_suffix =3D ' *' + eatspace =20 =20 def genindent(count): - ret =3D "" + ret =3D '' for _ in range(count): - ret +=3D " " + ret +=3D ' ' return ret =20 indent_level =3D 0 @@ -1948,26 +1948,26 @@ def gen_params(arg_type, boxed, extra): # =20 =20 -def parse_command_line(extra_options=3D"", extra_long_options=3D[]): +def parse_command_line(extra_options=3D'', extra_long_options=3D[]): =20 try: opts, args =3D getopt.gnu_getopt(sys.argv[1:], - "chp:o:" + extra_options, - ["source", "header", "prefix=3D", - "output-dir=3D"] + extra_long_opti= ons) + 'chp:o:' + extra_options, + ['source', 'header', 'prefix=3D', + 'output-dir=3D'] + extra_long_opti= ons) except getopt.GetoptError as err: print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err)) sys.exit(1) =20 - output_dir =3D "" - prefix =3D "" + output_dir =3D '' + prefix =3D '' do_c =3D False do_h =3D False extra_opts =3D [] =20 for oa in opts: o, a =3D oa - if o in ("-p", "--prefix"): + if o in ('-p', '--prefix'): match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a) if match.end() !=3D len(a): print >>sys.stderr, \ @@ -1975,11 +1975,11 @@ def parse_command_line(extra_options=3D"", extra_lo= ng_options=3D[]): % (sys.argv[0], a[match.end()]) sys.exit(1) prefix =3D a - elif o in ("-o", "--output-dir"): - output_dir =3D a + "/" - elif o in ("-c", "--source"): + elif o in ('-o', '--output-dir'): + output_dir =3D a + '/' + elif o in ('-c', '--source'): do_c =3D True - elif o in ("-h", "--header"): + elif o in ('-h', '--header'): do_h =3D True else: extra_opts.append(oa) diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index 4583477..91cd593 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -50,7 +50,7 @@ def subst_vars(doc): =20 def subst_braces(doc): """Replaces {} with @{ @}""" - return doc.replace("{", "@{").replace("}", "@}") + return doc.replace('{', '@{').replace('}', '@}') =20 =20 def texi_example(doc): @@ -79,10 +79,10 @@ def texi_format(doc): doc =3D subst_vars(doc) doc =3D subst_emph(doc) doc =3D subst_strong(doc) - inlist =3D "" + inlist =3D '' lastempty =3D False for line in doc.split('\n'): - empty =3D line =3D=3D "" + empty =3D line =3D=3D '' =20 # FIXME: Doing this in a single if / elif chain is # problematic. For instance, a line without markup terminates @@ -92,35 +92,35 @@ def texi_format(doc): # # Make sure to update section "Documentation markup" in # docs/qapi-code-gen.txt when fixing this. - if line.startswith("| "): + if line.startswith('| '): line =3D EXAMPLE_FMT(code=3Dline[2:]) - elif line.startswith("=3D "): - line =3D "@section " + line[2:] - elif line.startswith("=3D=3D "): - line =3D "@subsection " + line[3:] + elif line.startswith('=3D '): + line =3D '@section ' + line[2:] + elif line.startswith('=3D=3D '): + line =3D '@subsection ' + line[3:] elif re.match(r'^([0-9]*\.) ', line): if not inlist: - lines.append("@enumerate") - inlist =3D "enumerate" - line =3D line[line.find(" ")+1:] - lines.append("@item") + lines.append('@enumerate') + inlist =3D 'enumerate' + line =3D line[line.find(' ')+1:] + lines.append('@item') elif re.match(r'^[*-] ', line): if not inlist: - lines.append("@itemize %s" % {'*': "@bullet", - '-': "@minus"}[line[0]]) - inlist =3D "itemize" - lines.append("@item") + lines.append('@itemize %s' % {'*': '@bullet', + '-': '@minus'}[line[0]]) + inlist =3D 'itemize' + lines.append('@item') line =3D line[2:] elif lastempty and inlist: - lines.append("@end %s\n" % inlist) - inlist =3D "" + lines.append('@end %s\n' % inlist) + inlist =3D '' =20 lastempty =3D empty lines.append(line) =20 if inlist: - lines.append("@end %s\n" % inlist) - return "\n".join(lines) + lines.append('@end %s\n' % inlist) + return '\n'.join(lines) =20 =20 def texi_body(doc): @@ -158,12 +158,12 @@ def texi_sections(doc): for section in doc.sections: name, doc =3D (section.name, str(section)) func =3D texi_format - if name.startswith("Example"): + if name.startswith('Example'): func =3D texi_example =20 if name: # prefer @b over @strong, so txt doesn't translate it to *Foo:* - body +=3D "\n\n@b{%s:}\n" % name + body +=3D '\n\n@b{%s:}\n' % name =20 body +=3D func(doc) return body @@ -269,5 +269,5 @@ def main(argv): print texi_schema(schema) =20 =20 -if __name__ =3D=3D "__main__": +if __name__ =3D=3D '__main__': main(sys.argv) --=20 2.7.4