]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
qapi: Drop conditionals for Python 2
authorMarkus Armbruster <armbru@redhat.com>
Wed, 4 Mar 2020 15:59:30 +0000 (16:59 +0100)
committerMarkus Armbruster <armbru@redhat.com>
Thu, 5 Mar 2020 08:24:11 +0000 (09:24 +0100)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200304155932.20452-3-armbru@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
scripts/qapi/common.py
scripts/qapi/gen.py
scripts/qapi/parser.py
tests/qapi-schema/test-qapi.py

index e00dcafce7705cc81e5e22d1269245a8df3ef120..ba35abea478e1647da077a2699bbf7455cead2f9 100644 (file)
@@ -12,7 +12,6 @@
 # See the COPYING file in the top-level directory.
 
 import re
-import string
 
 
 # ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1
@@ -43,10 +42,7 @@ def c_enum_const(type_name, const_name, prefix=None):
     return camel_to_upper(type_name) + '_' + c_name(const_name, False).upper()
 
 
-if hasattr(str, 'maketrans'):
-    c_name_trans = str.maketrans('.-', '__')
-else:
-    c_name_trans = string.maketrans('.-', '__')
+c_name_trans = str.maketrans('.-', '__')
 
 
 # Map @name to a valid C identifier.
index a53a705c73019cef940b97be3de87304bae13af4..317cd7260133578ead760abf2b0a1df19e2852b5 100644 (file)
@@ -15,7 +15,6 @@
 import errno
 import os
 import re
-import sys
 from contextlib import contextmanager
 
 from qapi.common import *
@@ -54,10 +53,7 @@ class QAPIGen:
                 if e.errno != errno.EEXIST:
                     raise
         fd = os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666)
-        if sys.version_info[0] >= 3:
-            f = open(fd, 'r+', encoding='utf-8')
-        else:
-            f = os.fdopen(fd, 'r+')
+        f = open(fd, 'r+', encoding='utf-8')
         text = self.get_content()
         oldtext = f.read(len(text) + 1)
         if text != oldtext:
index 2e3a3c5d76593428cf0883ec9a6a2e2398262d04..cf14e5426c33c73dddfdb0d5ca0212202089f737 100644 (file)
@@ -16,7 +16,6 @@
 
 import os
 import re
-import sys
 from collections import OrderedDict
 
 from qapi.error import QAPIParseError, QAPISemError
@@ -30,10 +29,7 @@ class QAPISchemaParser:
         previously_included.add(os.path.abspath(fname))
 
         try:
-            if sys.version_info[0] >= 3:
-                fp = open(fname, 'r', encoding='utf-8')
-            else:
-                fp = open(fname, 'r')
+            fp = open(fname, 'r', encoding='utf-8')
             self.src = fp.read()
         except IOError as e:
             raise QAPISemError(incl_info or QAPISourceInfo(None, None, None),
index 41232c11a3901abcdf12110dd2b7cb01d1dbe471..bee18ee34452a30b5acb2257880a0b406c002dd5 100755 (executable)
@@ -16,15 +16,11 @@ import argparse
 import difflib
 import os
 import sys
+from io import StringIO
 
 from qapi.error import QAPIError
 from qapi.schema import QAPISchema, QAPISchemaVisitor
 
-if sys.version_info[0] < 3:
-    from cStringIO import StringIO
-else:
-    from io import StringIO
-
 
 class QAPISchemaTestVisitor(QAPISchemaVisitor):