From nobody Tue Feb 10 12:58:24 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517872282074681.4408551450268; Mon, 5 Feb 2018 15:11:22 -0800 (PST) Received: from localhost ([::1]:48778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eipur-0002u0-MT for importer@patchew.org; Mon, 05 Feb 2018 18:11:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eipsp-0001Rr-0B for qemu-devel@nongnu.org; Mon, 05 Feb 2018 18:09:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eipsn-0006Oj-9a for qemu-devel@nongnu.org; Mon, 05 Feb 2018 18:09:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56130) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eipsn-0006Nm-1E for qemu-devel@nongnu.org; Mon, 05 Feb 2018 18:09:05 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62C643683C; Mon, 5 Feb 2018 23:09:04 +0000 (UTC) Received: from localhost (ovpn-116-12.gru2.redhat.com [10.97.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5AB517CE9; Mon, 5 Feb 2018 23:09:03 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 21:08:40 -0200 Message-Id: <20180205230900.11344-2-ehabkost@redhat.com> In-Reply-To: <20180205230900.11344-1-ehabkost@redhat.com> References: <20180205230900.11344-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Feb 2018 23:09:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 01/21] qapi: convert to use python print function instead of statement 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: , Cc: Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: "Daniel P. Berrange" Python 3 no longer supports the bare "print" statement, it must be called as a normal function with round brackets. It is possible to opt-in to this new syntax with Python 2.6 onwards by importing the "print_function" from the "__future__" module, making it easy to support Python 2 and 3 in parallel. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel P. Berrange Message-Id: <20180116134217.8725-2-berrange@redhat.com> Signed-off-by: Eduardo Habkost --- scripts/qapi.py | 12 ++++++------ scripts/qapi2texi.py | 9 +++++---- tests/qapi-schema/test-qapi.py | 41 +++++++++++++++++++++-----------------= --- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 43a54bf40f..64fde4b6c5 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -11,6 +11,7 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 +from __future__ import print_function import errno import getopt import os @@ -1467,7 +1468,7 @@ class QAPISchema(object): self._def_exprs() self.check() except QAPIError as err: - print >>sys.stderr, err + print(err, file=3Dsys.stderr) exit(1) =20 def _def_entity(self, ent): @@ -1931,7 +1932,7 @@ def parse_command_line(extra_options=3D'', extra_long= _options=3D[]): ['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)) + print("%s: %s" % (sys.argv[0], str(err)), file=3Dsys.stderr) sys.exit(1) =20 output_dir =3D '' @@ -1945,9 +1946,8 @@ def parse_command_line(extra_options=3D'', extra_long= _options=3D[]): 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, \ - "%s: 'funny character '%s' in argument of --prefix" \ - % (sys.argv[0], a[match.end()]) + print("%s: 'funny character '%s' in argument of --prefix" \ + % (sys.argv[0], a[match.end()]), file=3Dsys.stderr) sys.exit(1) prefix =3D a elif o in ('-o', '--output-dir'): @@ -1964,7 +1964,7 @@ def parse_command_line(extra_options=3D'', extra_long= _options=3D[]): do_h =3D True =20 if len(args) !=3D 1: - print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0] + print("%s: need exactly one argument" % sys.argv[0], file=3Dsys.st= derr) sys.exit(1) fname =3D args[0] =20 diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index 92e2af2cd6..70e1fe76ef 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -4,6 +4,7 @@ # This work is licensed under the terms of the GNU LGPL, version 2+. # See the COPYING file in the top-level directory. """This script produces the documentation of a qapi schema in texinfo form= at""" +from __future__ import print_function import re import sys =20 @@ -274,15 +275,15 @@ def texi_schema(schema): def main(argv): """Takes schema argument, prints result to stdout""" if len(argv) !=3D 2: - print >>sys.stderr, "%s: need exactly 1 argument: SCHEMA" % argv[0] + print("%s: need exactly 1 argument: SCHEMA" % argv[0], file=3Dsys.= stderr) sys.exit(1) =20 schema =3D qapi.QAPISchema(argv[1]) if not qapi.doc_required: - print >>sys.stderr, ("%s: need pragma 'doc-required' " - "to generate documentation" % argv[0]) + print("%s: need pragma 'doc-required' " + "to generate documentation" % argv[0], file=3Dsys.stderr) sys.exit(1) - print texi_schema(schema) + print(texi_schema(schema)) =20 =20 if __name__ =3D=3D '__main__': diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index fe0ca08d78..a43fa873e1 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -10,6 +10,7 @@ # See the COPYING file in the top-level directory. # =20 +from __future__ import print_function from qapi import * from pprint import pprint import os @@ -18,51 +19,51 @@ import sys =20 class QAPISchemaTestVisitor(QAPISchemaVisitor): def visit_enum_type(self, name, info, values, prefix): - print 'enum %s %s' % (name, values) + print('enum %s %s' % (name, values)) if prefix: - print ' prefix %s' % prefix + print(' prefix %s' % prefix) =20 def visit_object_type(self, name, info, base, members, variants): - print 'object %s' % name + print('object %s' % name) if base: - print ' base %s' % base.name + print(' base %s' % base.name) for m in members: - print ' member %s: %s optional=3D%s' % \ - (m.name, m.type.name, m.optional) + print(' member %s: %s optional=3D%s' % \ + (m.name, m.type.name, m.optional)) self._print_variants(variants) =20 def visit_alternate_type(self, name, info, variants): - print 'alternate %s' % name + print('alternate %s' % name) self._print_variants(variants) =20 def visit_command(self, name, info, arg_type, ret_type, gen, success_response, boxed): - print 'command %s %s -> %s' % \ - (name, arg_type and arg_type.name, ret_type and ret_type.name) - print ' gen=3D%s success_response=3D%s boxed=3D%s' % \ - (gen, success_response, boxed) + print('command %s %s -> %s' % \ + (name, arg_type and arg_type.name, ret_type and ret_type.nam= e)) + print(' gen=3D%s success_response=3D%s boxed=3D%s' % \ + (gen, success_response, boxed)) =20 def visit_event(self, name, info, arg_type, boxed): - print 'event %s %s' % (name, arg_type and arg_type.name) - print ' boxed=3D%s' % boxed + print('event %s %s' % (name, arg_type and arg_type.name)) + print(' boxed=3D%s' % boxed) =20 @staticmethod def _print_variants(variants): if variants: - print ' tag %s' % variants.tag_member.name + print(' tag %s' % variants.tag_member.name) for v in variants.variants: - print ' case %s: %s' % (v.name, v.type.name) + print(' case %s: %s' % (v.name, v.type.name)) =20 schema =3D QAPISchema(sys.argv[1]) schema.visit(QAPISchemaTestVisitor()) =20 for doc in schema.docs: if doc.symbol: - print 'doc symbol=3D%s' % doc.symbol + print('doc symbol=3D%s' % doc.symbol) else: - print 'doc freeform' - print ' body=3D\n%s' % doc.body.text + print('doc freeform') + print(' body=3D\n%s' % doc.body.text) for arg, section in doc.args.iteritems(): - print ' arg=3D%s\n%s' % (arg, section.text) + print(' arg=3D%s\n%s' % (arg, section.text)) for section in doc.sections: - print ' section=3D%s\n%s' % (section.name, section.text) + print(' section=3D%s\n%s' % (section.name, section.text)) --=20 2.14.3