python: Make exception handling Python 3 safe
Change-Id: I9c2cdfad20deb1ddfa224320cf93f2105d126652 Reviewed-on: https://gem5-review.googlesource.com/c/15980 Maintainer: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
This commit is contained in:
@@ -483,8 +483,8 @@ class MetaSimObject(type):
|
||||
if isinstance(c, MetaSimObject):
|
||||
bTotal += 1
|
||||
if bTotal > 1:
|
||||
raise TypeError, \
|
||||
"SimObjects do not support multiple inheritance"
|
||||
raise TypeError(
|
||||
"SimObjects do not support multiple inheritance")
|
||||
|
||||
base = bases[0]
|
||||
|
||||
@@ -543,8 +543,8 @@ class MetaSimObject(type):
|
||||
|
||||
def _set_keyword(cls, keyword, val, kwtype):
|
||||
if not isinstance(val, kwtype):
|
||||
raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \
|
||||
(keyword, type(val), kwtype)
|
||||
raise TypeError('keyword %s has bad type %s (expecting %s)' % \
|
||||
(keyword, type(val), kwtype))
|
||||
if isinstance(val, FunctionType):
|
||||
val = classmethod(val)
|
||||
type.__setattr__(cls, keyword, val)
|
||||
@@ -562,7 +562,7 @@ class MetaSimObject(type):
|
||||
try:
|
||||
hr_value = value
|
||||
value = param.convert(value)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
msg = "%s\nError setting param %s.%s to %s\n" % \
|
||||
(e, cls.__name__, name, value)
|
||||
e.args = (msg, )
|
||||
@@ -622,10 +622,10 @@ class MetaSimObject(type):
|
||||
return
|
||||
|
||||
if isSimObjectOrSequence(value) and cls._instantiated:
|
||||
raise RuntimeError, \
|
||||
raise RuntimeError(
|
||||
"cannot set SimObject parameter '%s' after\n" \
|
||||
" class %s has been instantiated or subclassed" \
|
||||
% (attr, cls.__name__)
|
||||
% (attr, cls.__name__))
|
||||
|
||||
# check for param
|
||||
param = cls._params.get(attr)
|
||||
@@ -639,8 +639,8 @@ class MetaSimObject(type):
|
||||
return
|
||||
|
||||
# no valid assignment... raise exception
|
||||
raise AttributeError, \
|
||||
"Class %s has no parameter \'%s\'" % (cls.__name__, attr)
|
||||
raise AttributeError(
|
||||
"Class %s has no parameter \'%s\'" % (cls.__name__, attr))
|
||||
|
||||
def __getattr__(cls, attr):
|
||||
if attr == 'cxx_class_path':
|
||||
@@ -658,8 +658,8 @@ class MetaSimObject(type):
|
||||
if cls._children.has_key(attr):
|
||||
return cls._children[attr]
|
||||
|
||||
raise AttributeError, \
|
||||
"object '%s' has no attribute '%s'" % (cls.__name__, attr)
|
||||
raise AttributeError(
|
||||
"object '%s' has no attribute '%s'" % (cls.__name__, attr))
|
||||
|
||||
def __str__(cls):
|
||||
return cls.__name__
|
||||
@@ -1152,9 +1152,9 @@ class SimObject(object):
|
||||
# no memo_dict: must be top-level clone operation.
|
||||
# this is only allowed at the root of a hierarchy
|
||||
if self._parent:
|
||||
raise RuntimeError, "attempt to clone object %s " \
|
||||
raise RuntimeError("attempt to clone object %s " \
|
||||
"not at the root of a tree (parent = %s)" \
|
||||
% (self, self._parent)
|
||||
% (self, self._parent))
|
||||
# create a new dict and use that.
|
||||
memo_dict = {}
|
||||
kwargs['_memo'] = memo_dict
|
||||
@@ -1196,7 +1196,7 @@ class SimObject(object):
|
||||
err_string += "\n (C++ object is not yet constructed," \
|
||||
" so wrapped C++ methods are unavailable.)"
|
||||
|
||||
raise AttributeError, err_string
|
||||
raise AttributeError(err_string)
|
||||
|
||||
# Set attribute (called on foo.attr = value when foo is an
|
||||
# instance of class cls).
|
||||
@@ -1216,7 +1216,7 @@ class SimObject(object):
|
||||
try:
|
||||
hr_value = value
|
||||
value = param.convert(value)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
msg = "%s\nError setting param %s.%s to %s\n" % \
|
||||
(e, self.__class__.__name__, attr, value)
|
||||
e.args = (msg, )
|
||||
@@ -1240,8 +1240,8 @@ class SimObject(object):
|
||||
return
|
||||
|
||||
# no valid assignment... raise exception
|
||||
raise AttributeError, "Class %s has no parameter %s" \
|
||||
% (self.__class__.__name__, attr)
|
||||
raise AttributeError("Class %s has no parameter %s" \
|
||||
% (self.__class__.__name__, attr))
|
||||
|
||||
|
||||
# this hack allows tacking a '[0]' onto parameters that may or may
|
||||
@@ -1249,7 +1249,7 @@ class SimObject(object):
|
||||
def __getitem__(self, key):
|
||||
if key == 0:
|
||||
return self
|
||||
raise IndexError, "Non-zero index '%s' to SimObject" % key
|
||||
raise IndexError("Non-zero index '%s' to SimObject" % key)
|
||||
|
||||
# this hack allows us to iterate over a SimObject that may
|
||||
# not be a vector, so we can call a loop over it and get just one
|
||||
@@ -1352,18 +1352,18 @@ class SimObject(object):
|
||||
|
||||
if isinstance(child, ptype) and not visited:
|
||||
if found_obj != None and child != found_obj:
|
||||
raise AttributeError, \
|
||||
raise AttributeError(
|
||||
'parent.any matched more than one: %s %s' % \
|
||||
(found_obj.path, child.path)
|
||||
(found_obj.path, child.path))
|
||||
found_obj = child
|
||||
# search param space
|
||||
for pname,pdesc in self._params.iteritems():
|
||||
if issubclass(pdesc.ptype, ptype):
|
||||
match_obj = self._values[pname]
|
||||
if found_obj != None and found_obj != match_obj:
|
||||
raise AttributeError, \
|
||||
raise AttributeError(
|
||||
'parent.any matched more than one: %s and %s' % \
|
||||
(found_obj.path, match_obj.path)
|
||||
(found_obj.path, match_obj.path))
|
||||
found_obj = match_obj
|
||||
return found_obj, found_obj != None
|
||||
|
||||
@@ -1533,7 +1533,7 @@ class SimObject(object):
|
||||
if not self._ccObject:
|
||||
# Make sure this object is in the configuration hierarchy
|
||||
if not self._parent and not isRoot(self):
|
||||
raise RuntimeError, "Attempt to instantiate orphan node"
|
||||
raise RuntimeError("Attempt to instantiate orphan node")
|
||||
# Cycles in the configuration hierarchy are not supported. This
|
||||
# will catch the resulting recursion and stop.
|
||||
self._ccObject = -1
|
||||
@@ -1541,8 +1541,8 @@ class SimObject(object):
|
||||
params = self.getCCParams()
|
||||
self._ccObject = params.create()
|
||||
elif self._ccObject == -1:
|
||||
raise RuntimeError, "%s: Cycle found in configuration hierarchy." \
|
||||
% self.path()
|
||||
raise RuntimeError("%s: Cycle found in configuration hierarchy." \
|
||||
% self.path())
|
||||
return self._ccObject
|
||||
|
||||
def descendants(self):
|
||||
@@ -1650,7 +1650,7 @@ def tryAsSimObjectOrVector(value):
|
||||
def coerceSimObjectOrVector(value):
|
||||
value = tryAsSimObjectOrVector(value)
|
||||
if value is None:
|
||||
raise TypeError, "SimObject or SimObjectVector expected"
|
||||
raise TypeError("SimObject or SimObjectVector expected")
|
||||
return value
|
||||
|
||||
baseClasses = allClasses.copy()
|
||||
|
||||
Reference in New Issue
Block a user