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:
@@ -155,7 +155,7 @@ class ParamDesc(object):
|
||||
self.default = args[0]
|
||||
self.desc = args[1]
|
||||
else:
|
||||
raise TypeError, 'too many arguments'
|
||||
raise TypeError('too many arguments')
|
||||
|
||||
if kwargs.has_key('desc'):
|
||||
assert(not hasattr(self, 'desc'))
|
||||
@@ -168,10 +168,10 @@ class ParamDesc(object):
|
||||
del kwargs['default']
|
||||
|
||||
if kwargs:
|
||||
raise TypeError, 'extra unknown kwargs %s' % kwargs
|
||||
raise TypeError('extra unknown kwargs %s' % kwargs)
|
||||
|
||||
if not hasattr(self, 'desc'):
|
||||
raise TypeError, 'desc attribute missing'
|
||||
raise TypeError('desc attribute missing')
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr == 'ptype':
|
||||
@@ -180,8 +180,8 @@ class ParamDesc(object):
|
||||
self.ptype = ptype
|
||||
return ptype
|
||||
|
||||
raise AttributeError, "'%s' object has no attribute '%s'" % \
|
||||
(type(self).__name__, attr)
|
||||
raise AttributeError("'%s' object has no attribute '%s'" % \
|
||||
(type(self).__name__, attr))
|
||||
|
||||
def example_str(self):
|
||||
if hasattr(self.ptype, "ex_str"):
|
||||
@@ -234,8 +234,8 @@ class ParamDesc(object):
|
||||
class VectorParamValue(list):
|
||||
__metaclass__ = MetaParamValue
|
||||
def __setattr__(self, attr, value):
|
||||
raise AttributeError, \
|
||||
"Not allowed to set %s on '%s'" % (attr, type(self).__name__)
|
||||
raise AttributeError("Not allowed to set %s on '%s'" % \
|
||||
(attr, type(self).__name__))
|
||||
|
||||
def config_value(self):
|
||||
return [v.config_value() for v in self]
|
||||
@@ -539,8 +539,8 @@ class CheckedInt(NumericParamValue):
|
||||
|
||||
def _check(self):
|
||||
if not self.min <= self.value <= self.max:
|
||||
raise TypeError, 'Integer param out of bounds %d < %d < %d' % \
|
||||
(self.min, self.value, self.max)
|
||||
raise TypeError('Integer param out of bounds %d < %d < %d' % \
|
||||
(self.min, self.value, self.max))
|
||||
|
||||
def __init__(self, value):
|
||||
if isinstance(value, str):
|
||||
@@ -548,8 +548,8 @@ class CheckedInt(NumericParamValue):
|
||||
elif isinstance(value, (int, long, float, NumericParamValue)):
|
||||
self.value = long(value)
|
||||
else:
|
||||
raise TypeError, "Can't convert object of type %s to CheckedInt" \
|
||||
% type(value).__name__
|
||||
raise TypeError("Can't convert object of type %s to CheckedInt" \
|
||||
% type(value).__name__)
|
||||
self._check()
|
||||
|
||||
def __call__(self, value):
|
||||
@@ -614,8 +614,8 @@ class Float(ParamValue, float):
|
||||
if isinstance(value, (int, long, float, NumericParamValue, Float, str)):
|
||||
self.value = float(value)
|
||||
else:
|
||||
raise TypeError, "Can't convert object of type %s to Float" \
|
||||
% type(value).__name__
|
||||
raise TypeError("Can't convert object of type %s to Float" \
|
||||
% type(value).__name__)
|
||||
|
||||
def __call__(self, value):
|
||||
self.__init__(value)
|
||||
@@ -711,7 +711,7 @@ class AddrRange(ParamValue):
|
||||
elif 'size' in kwargs:
|
||||
self.end = self.start + Addr(kwargs.pop('size')) - 1
|
||||
else:
|
||||
raise TypeError, "Either end or size must be specified"
|
||||
raise TypeError("Either end or size must be specified")
|
||||
|
||||
# Now on to the optional bit
|
||||
if 'intlvHighBit' in kwargs:
|
||||
@@ -742,10 +742,10 @@ class AddrRange(ParamValue):
|
||||
self.start = Addr(args[0])
|
||||
self.end = Addr(args[1])
|
||||
else:
|
||||
raise TypeError, "Too many arguments specified"
|
||||
raise TypeError("Too many arguments specified")
|
||||
|
||||
if kwargs:
|
||||
raise TypeError, "Too many keywords: %s" % kwargs.keys()
|
||||
raise TypeError("Too many keywords: %s" % list(kwargs.keys()))
|
||||
|
||||
def __str__(self):
|
||||
return '%s:%s:%s:%s:%s:%s' \
|
||||
@@ -885,15 +885,15 @@ class EthernetAddr(ParamValue):
|
||||
return
|
||||
|
||||
if not isinstance(value, str):
|
||||
raise TypeError, "expected an ethernet address and didn't get one"
|
||||
raise TypeError("expected an ethernet address and didn't get one")
|
||||
|
||||
bytes = value.split(':')
|
||||
if len(bytes) != 6:
|
||||
raise TypeError, 'invalid ethernet address %s' % value
|
||||
raise TypeError('invalid ethernet address %s' % value)
|
||||
|
||||
for byte in bytes:
|
||||
if not 0 <= int(byte, base=16) <= 0xff:
|
||||
raise TypeError, 'invalid ethernet address %s' % value
|
||||
raise TypeError('invalid ethernet address %s' % value)
|
||||
|
||||
self.value = value
|
||||
|
||||
@@ -966,7 +966,7 @@ class IpAddress(ParamValue):
|
||||
|
||||
def verifyIp(self):
|
||||
if self.ip < 0 or self.ip >= (1 << 32):
|
||||
raise TypeError, "invalid ip address %#08x" % self.ip
|
||||
raise TypeError("invalid ip address %#08x" % self.ip)
|
||||
|
||||
def getValue(self):
|
||||
from _m5.net import IpAddress
|
||||
@@ -991,7 +991,7 @@ class IpNetmask(IpAddress):
|
||||
elif elseVal:
|
||||
setattr(self, key, elseVal)
|
||||
else:
|
||||
raise TypeError, "No value set for %s" % key
|
||||
raise TypeError("No value set for %s" % key)
|
||||
|
||||
if len(args) == 0:
|
||||
handle_kwarg(self, kwargs, 'ip')
|
||||
@@ -1000,7 +1000,7 @@ class IpNetmask(IpAddress):
|
||||
elif len(args) == 1:
|
||||
if kwargs:
|
||||
if not 'ip' in kwargs and not 'netmask' in kwargs:
|
||||
raise TypeError, "Invalid arguments"
|
||||
raise TypeError("Invalid arguments")
|
||||
handle_kwarg(self, kwargs, 'ip', args[0])
|
||||
handle_kwarg(self, kwargs, 'netmask', args[0])
|
||||
elif isinstance(args[0], IpNetmask):
|
||||
@@ -1013,10 +1013,10 @@ class IpNetmask(IpAddress):
|
||||
self.ip = args[0]
|
||||
self.netmask = args[1]
|
||||
else:
|
||||
raise TypeError, "Too many arguments specified"
|
||||
raise TypeError("Too many arguments specified")
|
||||
|
||||
if kwargs:
|
||||
raise TypeError, "Too many keywords: %s" % kwargs.keys()
|
||||
raise TypeError("Too many keywords: %s" % list(kwargs.keys()))
|
||||
|
||||
self.verify()
|
||||
|
||||
@@ -1041,7 +1041,7 @@ class IpNetmask(IpAddress):
|
||||
def verify(self):
|
||||
self.verifyIp()
|
||||
if self.netmask < 0 or self.netmask > 32:
|
||||
raise TypeError, "invalid netmask %d" % netmask
|
||||
raise TypeError("invalid netmask %d" % netmask)
|
||||
|
||||
def getValue(self):
|
||||
from _m5.net import IpNetmask
|
||||
@@ -1065,7 +1065,7 @@ class IpWithPort(IpAddress):
|
||||
elif elseVal:
|
||||
setattr(self, key, elseVal)
|
||||
else:
|
||||
raise TypeError, "No value set for %s" % key
|
||||
raise TypeError("No value set for %s" % key)
|
||||
|
||||
if len(args) == 0:
|
||||
handle_kwarg(self, kwargs, 'ip')
|
||||
@@ -1074,7 +1074,7 @@ class IpWithPort(IpAddress):
|
||||
elif len(args) == 1:
|
||||
if kwargs:
|
||||
if not 'ip' in kwargs and not 'port' in kwargs:
|
||||
raise TypeError, "Invalid arguments"
|
||||
raise TypeError("Invalid arguments")
|
||||
handle_kwarg(self, kwargs, 'ip', args[0])
|
||||
handle_kwarg(self, kwargs, 'port', args[0])
|
||||
elif isinstance(args[0], IpWithPort):
|
||||
@@ -1087,10 +1087,10 @@ class IpWithPort(IpAddress):
|
||||
self.ip = args[0]
|
||||
self.port = args[1]
|
||||
else:
|
||||
raise TypeError, "Too many arguments specified"
|
||||
raise TypeError("Too many arguments specified")
|
||||
|
||||
if kwargs:
|
||||
raise TypeError, "Too many keywords: %s" % kwargs.keys()
|
||||
raise TypeError("Too many keywords: %s" % list(kwargs.keys()))
|
||||
|
||||
self.verify()
|
||||
|
||||
@@ -1115,7 +1115,7 @@ class IpWithPort(IpAddress):
|
||||
def verify(self):
|
||||
self.verifyIp()
|
||||
if self.port < 0 or self.port > 0xffff:
|
||||
raise TypeError, "invalid port %d" % self.port
|
||||
raise TypeError("invalid port %d" % self.port)
|
||||
|
||||
def getValue(self):
|
||||
from _m5.net import IpWithPort
|
||||
@@ -1157,7 +1157,7 @@ def parse_time(value):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
raise ValueError, "Could not parse '%s' as a time" % value
|
||||
raise ValueError("Could not parse '%s' as a time" % value)
|
||||
|
||||
class Time(ParamValue):
|
||||
cxx_type = 'tm'
|
||||
@@ -1226,22 +1226,22 @@ class MetaEnum(MetaParamValue):
|
||||
def __init__(cls, name, bases, init_dict):
|
||||
if init_dict.has_key('map'):
|
||||
if not isinstance(cls.map, dict):
|
||||
raise TypeError, "Enum-derived class attribute 'map' " \
|
||||
"must be of type dict"
|
||||
raise TypeError("Enum-derived class attribute 'map' " \
|
||||
"must be of type dict")
|
||||
# build list of value strings from map
|
||||
cls.vals = cls.map.keys()
|
||||
cls.vals.sort()
|
||||
elif init_dict.has_key('vals'):
|
||||
if not isinstance(cls.vals, list):
|
||||
raise TypeError, "Enum-derived class attribute 'vals' " \
|
||||
"must be of type list"
|
||||
raise TypeError("Enum-derived class attribute 'vals' " \
|
||||
"must be of type list")
|
||||
# build string->value map from vals sequence
|
||||
cls.map = {}
|
||||
for idx,val in enumerate(cls.vals):
|
||||
cls.map[val] = idx
|
||||
else:
|
||||
raise TypeError, "Enum-derived class must define "\
|
||||
"attribute 'map' or 'vals'"
|
||||
raise TypeError("Enum-derived class must define "\
|
||||
"attribute 'map' or 'vals'")
|
||||
|
||||
if cls.is_class:
|
||||
cls.cxx_type = '%s' % name
|
||||
@@ -1385,8 +1385,8 @@ class Enum(ParamValue):
|
||||
|
||||
def __init__(self, value):
|
||||
if value not in self.map:
|
||||
raise TypeError, "Enum param got bad value '%s' (not in %s)" \
|
||||
% (value, self.vals)
|
||||
raise TypeError("Enum param got bad value '%s' (not in %s)" \
|
||||
% (value, self.vals))
|
||||
self.value = value
|
||||
|
||||
def __call__(self, value):
|
||||
@@ -1491,7 +1491,7 @@ class Latency(TickParamValue):
|
||||
return self
|
||||
if attr == 'frequency':
|
||||
return Frequency(self)
|
||||
raise AttributeError, "Latency object has no attribute '%s'" % attr
|
||||
raise AttributeError("Latency object has no attribute '%s'" % attr)
|
||||
|
||||
def getValue(self):
|
||||
if self.ticks or self.value == 0:
|
||||
@@ -1533,7 +1533,7 @@ class Frequency(TickParamValue):
|
||||
return self
|
||||
if attr in ('latency', 'period'):
|
||||
return Latency(self)
|
||||
raise AttributeError, "Frequency object has no attribute '%s'" % attr
|
||||
raise AttributeError("Frequency object has no attribute '%s'" % attr)
|
||||
|
||||
# convert latency to ticks
|
||||
def getValue(self):
|
||||
@@ -1578,7 +1578,7 @@ class Clock(TickParamValue):
|
||||
return Frequency(self)
|
||||
if attr in ('latency', 'period'):
|
||||
return Latency(self)
|
||||
raise AttributeError, "Frequency object has no attribute '%s'" % attr
|
||||
raise AttributeError("Frequency object has no attribute '%s'" % attr)
|
||||
|
||||
def getValue(self):
|
||||
return self.period.getValue()
|
||||
@@ -1800,8 +1800,8 @@ class PortRef(object):
|
||||
if attr == 'peerObj':
|
||||
# shorthand for proxies
|
||||
return self.peer.simobj
|
||||
raise AttributeError, "'%s' object has no attribute '%s'" % \
|
||||
(self.__class__.__name__, attr)
|
||||
raise AttributeError("'%s' object has no attribute '%s'" % \
|
||||
(self.__class__.__name__, attr))
|
||||
|
||||
# Full connection is symmetric (both ways). Called via
|
||||
# SimObject.__setattr__ as a result of a port assignment, e.g.,
|
||||
@@ -1821,9 +1821,8 @@ class PortRef(object):
|
||||
if other.peer is not self:
|
||||
other.connect(self)
|
||||
else:
|
||||
raise TypeError, \
|
||||
"assigning non-port reference '%s' to port '%s'" \
|
||||
% (other, self)
|
||||
raise TypeError("assigning non-port reference '%s' to port '%s'" \
|
||||
% (other, self))
|
||||
|
||||
# Allow a master/slave port pair to be spliced between
|
||||
# a port and its connected peer. Useful operation for connecting
|
||||
@@ -1836,9 +1835,9 @@ class PortRef(object):
|
||||
|
||||
if not isinstance(new_master_peer, PortRef) or \
|
||||
not isinstance(new_slave_peer, PortRef):
|
||||
raise TypeError, \
|
||||
raise TypeError(
|
||||
"Splicing non-port references '%s','%s' to port '%s'" % \
|
||||
(new_master_peer, new_slave_peer, self)
|
||||
(new_master_peer, new_slave_peer, self))
|
||||
|
||||
old_peer = self.peer
|
||||
if self.role == 'SLAVE':
|
||||
@@ -1892,9 +1891,9 @@ class PortRef(object):
|
||||
|
||||
# check that we connect a master to a slave
|
||||
if self.role == peer.role:
|
||||
raise TypeError, \
|
||||
"cannot connect '%s' and '%s' due to identical role '%s'" \
|
||||
% (peer, self, self.role)
|
||||
raise TypeError(
|
||||
"cannot connect '%s' and '%s' due to identical role '%s'" % \
|
||||
(peer, self, self.role))
|
||||
|
||||
if self.role == 'SLAVE':
|
||||
# do nothing and let the master take care of it
|
||||
@@ -1951,7 +1950,7 @@ class VectorPortRef(object):
|
||||
|
||||
def __getitem__(self, key):
|
||||
if not isinstance(key, int):
|
||||
raise TypeError, "VectorPort index must be integer"
|
||||
raise TypeError("VectorPort index must be integer")
|
||||
if key >= len(self.elements):
|
||||
# need to extend list
|
||||
ext = [VectorPortElementRef(self.simobj, self.name, self.role, i)
|
||||
@@ -1964,7 +1963,7 @@ class VectorPortRef(object):
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
if not isinstance(key, int):
|
||||
raise TypeError, "VectorPort index must be integer"
|
||||
raise TypeError("VectorPort index must be integer")
|
||||
self[key].connect(value)
|
||||
|
||||
def connect(self, other):
|
||||
@@ -2029,7 +2028,7 @@ class MasterPort(Port):
|
||||
self.desc = args[0]
|
||||
self.role = 'MASTER'
|
||||
else:
|
||||
raise TypeError, 'wrong number of arguments'
|
||||
raise TypeError('wrong number of arguments')
|
||||
|
||||
class SlavePort(Port):
|
||||
# SlavePort("description")
|
||||
@@ -2038,7 +2037,7 @@ class SlavePort(Port):
|
||||
self.desc = args[0]
|
||||
self.role = 'SLAVE'
|
||||
else:
|
||||
raise TypeError, 'wrong number of arguments'
|
||||
raise TypeError('wrong number of arguments')
|
||||
|
||||
# VectorPort description object. Like Port, but represents a vector
|
||||
# of connections (e.g., as on a XBar).
|
||||
@@ -2057,7 +2056,7 @@ class VectorMasterPort(VectorPort):
|
||||
self.role = 'MASTER'
|
||||
VectorPort.__init__(self, *args)
|
||||
else:
|
||||
raise TypeError, 'wrong number of arguments'
|
||||
raise TypeError('wrong number of arguments')
|
||||
|
||||
class VectorSlavePort(VectorPort):
|
||||
# VectorSlavePort("description")
|
||||
@@ -2067,7 +2066,7 @@ class VectorSlavePort(VectorPort):
|
||||
self.role = 'SLAVE'
|
||||
VectorPort.__init__(self, *args)
|
||||
else:
|
||||
raise TypeError, 'wrong number of arguments'
|
||||
raise TypeError('wrong number of arguments')
|
||||
|
||||
# 'Fake' ParamDesc for Port references to assign to the _pdesc slot of
|
||||
# proxy objects (via set_param_desc()) so that proxy error messages
|
||||
|
||||
Reference in New Issue
Block a user