From a347a1a68b8a6e370334be3a1d2d66675891e0f1 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Sat, 26 Jan 2019 14:08:20 +0000 Subject: [PATCH] python: Stop using basestring to test for strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The base class basestring doesn't exist in Python 3. Use string_types from six instead. Change-Id: I7e84903fb7dd4a0af7ae4e9f4ec2e54338f212bb Signed-off-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/c/15998 Reviewed-by: Nikos Nikoleris Reviewed-by: Juha Jäykkä --- src/mem/qos/QoSPolicy.py | 6 ++++-- src/mem/slicc/util.py | 3 ++- src/python/m5/util/grammar.py | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mem/qos/QoSPolicy.py b/src/mem/qos/QoSPolicy.py index 6db04aca1..be18cd64a 100644 --- a/src/mem/qos/QoSPolicy.py +++ b/src/mem/qos/QoSPolicy.py @@ -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: diff --git a/src/mem/slicc/util.py b/src/mem/slicc/util.py index 3a0cf5f35..dcb780d6b 100644 --- a/src/mem/slicc/util.py +++ b/src/mem/slicc/util.py @@ -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)): diff --git a/src/python/m5/util/grammar.py b/src/python/m5/util/grammar.py index 2d9e82cd6..caf8a2e39 100644 --- a/src/python/m5/util/grammar.py +++ b/src/python/m5/util/grammar.py @@ -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='', 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): -- 2.30.2