python: Stop using basestring to test for strings
authorAndreas Sandberg <andreas.sandberg@arm.com>
Sat, 26 Jan 2019 14:08:20 +0000 (14:08 +0000)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Mon, 25 Feb 2019 14:25:24 +0000 (14:25 +0000)
The base class basestring doesn't exist in Python 3. Use string_types
from six instead.

Change-Id: I7e84903fb7dd4a0af7ae4e9f4ec2e54338f212bb
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/15998
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Juha Jäykkä <juha.jaykka@arm.com>
src/mem/qos/QoSPolicy.py
src/mem/slicc/util.py
src/python/m5/util/grammar.py

index 6db04aca1b137759cbc8127b97546827f28e2809..be18cd64af8112539a112c1efa4a8ce171d28be3 100644 (file)
@@ -35,6 +35,8 @@
 #
 # Authors: Giacomo Travaglini
 
+from six import string_types
+
 from m5.SimObject import *
 from m5.params import *
 
@@ -71,7 +73,7 @@ class QoSFixedPriorityPolicy(QoSPolicy):
             for mprio in self._mpriorities:
                 master = mprio[0]
                 priority = mprio[1]
-                if isinstance(master, basestring):
+                if isinstance(master, string_types):
                     self.getCCObject().initMasterName(
                         master, int(priority))
                 else:
@@ -108,7 +110,7 @@ class QoSPropFairPolicy(QoSPolicy):
             for mprio in self._mscores:
                 master = mprio[0]
                 score = mprio[1]
-                if isinstance(master, basestring):
+                if isinstance(master, string_types):
                     self.getCCObject().initMasterName(
                         master, float(score))
                 else:
index 3a0cf5f356f666773849c15e6516f8f21ca18cab..dcb780d6b344a29dc03127326099f6a1e4dd472e 100644 (file)
@@ -25,6 +25,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 from __future__ import print_function
+from six import string_types
 
 import os
 import sys
@@ -49,7 +50,7 @@ class PairContainer(object):
 
 class Location(object):
     def __init__(self, filename, lineno, no_warning=False):
-        if not isinstance(filename, basestring):
+        if not isinstance(filename, string_types):
             raise AttributeError, \
                 "filename must be a string, found '%s'" % (type(filename), )
         if not isinstance(lineno, (int, long)):
index 2d9e82cd66feae882685d1522de759291967aa10..caf8a2e39075c002cbb5bb7bf8e864957f2f93ba 100644 (file)
@@ -25,6 +25,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import os
+from six import string_types
 
 import ply.lex
 import ply.yacc
@@ -93,7 +94,7 @@ class Grammar(object):
             "'%s' object has no attribute '%s'" % (type(self), attr))
 
     def parse_string(self, data, source='<string>', debug=None, tracking=0):
-        if not isinstance(data, basestring):
+        if not isinstance(data, string_types):
             raise AttributeError(
                 "argument must be a string, was '%s'" % type(f))
 
@@ -113,7 +114,7 @@ class Grammar(object):
         return result
 
     def parse_file(self, f, **kwargs):
-        if isinstance(f, basestring):
+        if isinstance(f, string_types):
             source = f
             f = open(f, 'r')
         elif isinstance(f, file):