From nobody Sun Feb 8 23:42:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589428458; cv=none; d=zohomail.com; s=zohoarc; b=LwLvrpg/iryyW3VvbMUfD7fDI2ltf2PxwpC8FzOmdOQHMWaZTFa23YMKolm6aZ/vWKpQr4ctrECRsk96R/9EBS8hyQkZXNV/QTiicitEZIodfXFRFoFgeblorAnPXalC3/5bJo4FwwQMFkIpasKCjkiSIzDZbWvz2hLTpL9BEgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589428458; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=yD0TU94we56szasilAIpzwZMhWQiIOGUsKTJ7pmU5CY=; b=Xbr/HbxajvrSQPfifmwgqM+OgiYoRRsU8e04tJbKMKk37rPyMMvwchTVaJZk4h1sRlw6D9CR5jMuiBZxbYRaLVxVy3q94m1DerrUxHCluRb8kjEM4rrLeaGEmYrAGiBLAnupJ6FIVJzDmJsT5tX8mBDr+09i5v4tnj4aDP75+ws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1589428458075554.6435637179873; Wed, 13 May 2020 20:54:18 -0700 (PDT) Received: from localhost ([::1]:41342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ4wq-0006mU-Rw for importer@patchew.org; Wed, 13 May 2020 23:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ4vJ-00053u-An for qemu-devel@nongnu.org; Wed, 13 May 2020 23:52:41 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:37730 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ4vI-0000mk-A5 for qemu-devel@nongnu.org; Wed, 13 May 2020 23:52:40 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-194-GVSpX6_qOSqX228wGHeK8A-1; Wed, 13 May 2020 23:52:38 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C9BE9A0BD7; Thu, 14 May 2020 03:52:36 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB17810027AF; Thu, 14 May 2020 03:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589428359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yD0TU94we56szasilAIpzwZMhWQiIOGUsKTJ7pmU5CY=; b=QgnUD/JuCdeioAoJbfjf04lpGpndXb8OCdllBFy+Qzgqiy/vOTPhL4zP6ztqXtzhOCCdPS +GnBXdoDsgEXZlMn6XGrSnQXmcg1mzR5+dvlAv91K74au6Q7O5v6VLW1bsvYXilv+lfSwv aML1R3hd2+kGq2LcZx0aecyOOSvEXVg= X-MC-Unique: GVSpX6_qOSqX228wGHeK8A-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH] python: remove more instances of sys.version_info Date: Wed, 13 May 2020 23:52:30 -0400 Message-Id: <20200514035230.25756-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We guarantee 3.5+ everywhere; remove more dead checks. In general, try to avoid using version checks and instead prefer to attempt behavior when possible. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/analyze-migration.py | 5 ----- scripts/decodetree.py | 25 +++++++++--------------- scripts/qmp/qmp-shell | 3 --- tests/docker/docker.py | 5 +++-- tests/qemu-iotests/nbd-fault-injector.py | 5 +---- 5 files changed, 13 insertions(+), 30 deletions(-) diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py index 96a31d3974..95838cbff3 100755 --- a/scripts/analyze-migration.py +++ b/scripts/analyze-migration.py @@ -25,11 +25,6 @@ import sys =20 =20 -MIN_PYTHON =3D (3, 2) -if sys.version_info < MIN_PYTHON: - sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON) - - def mkdir_p(path): try: os.makedirs(path) diff --git a/scripts/decodetree.py b/scripts/decodetree.py index 46ab917807..f9d204aa36 100755 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -75,13 +75,6 @@ def output(*args): output_fd.write(a) =20 =20 -if sys.version_info >=3D (3, 4): - re_fullmatch =3D re.fullmatch -else: - def re_fullmatch(pat, str): - return re.match('^' + pat + '$', str) - - def output_autogen(): output('/* This file is autogenerated by scripts/decodetree.py. */\n\= n') =20 @@ -428,18 +421,18 @@ def parse_field(lineno, name, toks): width =3D 0 func =3D None for t in toks: - if re_fullmatch('!function=3D' + re_ident, t): + if re.fullmatch('!function=3D' + re_ident, t): if func: error(lineno, 'duplicate function') func =3D t.split('=3D') func =3D func[1] continue =20 - if re_fullmatch('[0-9]+:s[0-9]+', t): + if re.fullmatch('[0-9]+:s[0-9]+', t): # Signed field extract subtoks =3D t.split(':s') sign =3D True - elif re_fullmatch('[0-9]+:[0-9]+', t): + elif re.fullmatch('[0-9]+:[0-9]+', t): # Unsigned field extract subtoks =3D t.split(':') sign =3D False @@ -488,11 +481,11 @@ def parse_arguments(lineno, name, toks): flds =3D [] extern =3D False for t in toks: - if re_fullmatch('!extern', t): + if re.fullmatch('!extern', t): extern =3D True anyextern =3D True continue - if not re_fullmatch(re_ident, t): + if not re.fullmatch(re_ident, t): error(lineno, 'invalid argument set token "{0}"'.format(t)) if t in flds: error(lineno, 'duplicate argument "{0}"'.format(t)) @@ -621,13 +614,13 @@ def parse_generic(lineno, is_format, name, toks): continue =20 # 'Foo=3D%Bar' imports a field with a different name. - if re_fullmatch(re_ident + '=3D%' + re_ident, t): + if re.fullmatch(re_ident + '=3D%' + re_ident, t): (fname, iname) =3D t.split('=3D%') flds =3D add_field_byname(lineno, flds, fname, iname) continue =20 # 'Foo=3Dnumber' sets an argument field to a constant value - if re_fullmatch(re_ident + '=3D[+-]?[0-9]+', t): + if re.fullmatch(re_ident + '=3D[+-]?[0-9]+', t): (fname, value) =3D t.split('=3D') value =3D int(value) flds =3D add_field(lineno, flds, fname, ConstField(value)) @@ -635,7 +628,7 @@ def parse_generic(lineno, is_format, name, toks): =20 # Pattern of 0s, 1s, dots and dashes indicate required zeros, # required ones, or dont-cares. - if re_fullmatch('[01.-]+', t): + if re.fullmatch('[01.-]+', t): shift =3D len(t) fms =3D t.replace('0', '1') fms =3D fms.replace('.', '0') @@ -652,7 +645,7 @@ def parse_generic(lineno, is_format, name, toks): fixedmask =3D (fixedmask << shift) | fms undefmask =3D (undefmask << shift) | ubm # Otherwise, fieldname:fieldwidth - elif re_fullmatch(re_ident + ':s?[0-9]+', t): + elif re.fullmatch(re_ident + ':s?[0-9]+', t): (fname, flen) =3D t.split(':') sign =3D False if flen[0] =3D=3D 's': diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index a01d31de1e..c5eef06f3f 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -77,9 +77,6 @@ import re sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) from qemu import qmp =20 -if sys.version_info[0] =3D=3D 2: - input =3D raw_input - class QMPCompleter(list): def complete(self, text, state): for cmd in self: diff --git a/tests/docker/docker.py b/tests/docker/docker.py index d8268c1111..5a9735db78 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -258,12 +258,13 @@ def _kill_instances(self, *args, **kwargs): return self._do_kill_instances(True) =20 def _output(self, cmd, **kwargs): - if sys.version_info[1] >=3D 6: + try: return subprocess.check_output(self._command + cmd, stderr=3Dsubprocess.STDOUT, encoding=3D'utf-8', **kwargs) - else: + except TypeError: + # 'encoding' argument was added in 3.6+ return subprocess.check_output(self._command + cmd, stderr=3Dsubprocess.STDOUT, **kwargs).decode('utf-8') diff --git a/tests/qemu-iotests/nbd-fault-injector.py b/tests/qemu-iotests/= nbd-fault-injector.py index 588d62aebf..78f42c4214 100755 --- a/tests/qemu-iotests/nbd-fault-injector.py +++ b/tests/qemu-iotests/nbd-fault-injector.py @@ -47,10 +47,7 @@ import socket import struct import collections -if sys.version_info.major >=3D 3: - import configparser -else: - import ConfigParser as configparser +import configparser =20 FAKE_DISK_SIZE =3D 8 * 1024 * 1024 * 1024 # 8 GB =20 --=20 2.21.1