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:
@@ -66,16 +66,16 @@ class BaseProxy(object):
|
||||
|
||||
def __setattr__(self, attr, value):
|
||||
if not attr.startswith('_'):
|
||||
raise AttributeError, \
|
||||
"cannot set attribute '%s' on proxy object" % attr
|
||||
raise AttributeError(
|
||||
"cannot set attribute '%s' on proxy object" % attr)
|
||||
super(BaseProxy, self).__setattr__(attr, value)
|
||||
|
||||
# support for multiplying proxies by constants or other proxies to
|
||||
# other params
|
||||
def __mul__(self, other):
|
||||
if not (isinstance(other, (int, long, float)) or isproxy(other)):
|
||||
raise TypeError, \
|
||||
"Proxy multiplier must be a constant or a proxy to a param"
|
||||
raise TypeError(
|
||||
"Proxy multiplier must be a constant or a proxy to a param")
|
||||
self._multipliers.append(other)
|
||||
return self
|
||||
|
||||
@@ -88,8 +88,8 @@ class BaseProxy(object):
|
||||
# assert that we are multiplying with a compatible
|
||||
# param
|
||||
if not isinstance(multiplier, params.NumericParamValue):
|
||||
raise TypeError, \
|
||||
"Proxy multiplier must be a numerical param"
|
||||
raise TypeError(
|
||||
"Proxy multiplier must be a numerical param")
|
||||
multiplier = multiplier.getValue()
|
||||
result *= multiplier
|
||||
return result
|
||||
@@ -116,13 +116,13 @@ class BaseProxy(object):
|
||||
base._visited = False
|
||||
|
||||
if not done:
|
||||
raise AttributeError, \
|
||||
"Can't resolve proxy '%s' of type '%s' from '%s'" % \
|
||||
(self.path(), self._pdesc.ptype_str, base.path())
|
||||
raise AttributeError(
|
||||
"Can't resolve proxy '%s' of type '%s' from '%s'" % \
|
||||
(self.path(), self._pdesc.ptype_str, base.path()))
|
||||
|
||||
if isinstance(result, BaseProxy):
|
||||
if result == self:
|
||||
raise RuntimeError, "Cycle in unproxy"
|
||||
raise RuntimeError("Cycle in unproxy")
|
||||
result = result.unproxy(obj)
|
||||
|
||||
return self._mulcheck(result, base)
|
||||
@@ -157,7 +157,7 @@ class AttrProxy(BaseProxy):
|
||||
if attr.startswith('_'):
|
||||
return super(AttrProxy, self).__getattr__(self, attr)
|
||||
if hasattr(self, '_pdesc'):
|
||||
raise AttributeError, "Attribute reference on bound proxy"
|
||||
raise AttributeError("Attribute reference on bound proxy")
|
||||
# Return a copy of self rather than modifying self in place
|
||||
# since self could be an indirect reference via a variable or
|
||||
# parameter
|
||||
@@ -168,9 +168,9 @@ class AttrProxy(BaseProxy):
|
||||
# support indexing on proxies (e.g., Self.cpu[0])
|
||||
def __getitem__(self, key):
|
||||
if not isinstance(key, int):
|
||||
raise TypeError, "Proxy object requires integer index"
|
||||
raise TypeError("Proxy object requires integer index")
|
||||
if hasattr(self, '_pdesc'):
|
||||
raise AttributeError, "Index operation on bound proxy"
|
||||
raise AttributeError("Index operation on bound proxy")
|
||||
new_self = copy.deepcopy(self)
|
||||
new_self._modifiers.append(key)
|
||||
return new_self
|
||||
|
||||
Reference in New Issue
Block a user