summaryrefslogtreecommitdiff
path: root/src/python/m5/util/convert.py
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2019-01-25 11:32:25 +0000
committerAndreas Sandberg <andreas.sandberg@arm.com>2019-02-12 09:38:12 +0000
commitfa21127a646b8d2a61fe412728762250ca38ecd2 (patch)
tree8f0c21351c0e7c7e30b1c03a81c3d4f122f566c5 /src/python/m5/util/convert.py
parent6ba4545b1f9553e68e992305c92cf46246a79dae (diff)
downloadgem5-fa21127a646b8d2a61fe412728762250ca38ecd2.tar.xz
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>
Diffstat (limited to 'src/python/m5/util/convert.py')
-rw-r--r--src/python/m5/util/convert.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/python/m5/util/convert.py b/src/python/m5/util/convert.py
index 5ae31216b..7b9cb3812 100644
--- a/src/python/m5/util/convert.py
+++ b/src/python/m5/util/convert.py
@@ -89,7 +89,7 @@ binary_prefixes = {
def assertStr(value):
if not isinstance(value, str):
- raise TypeError, "wrong type '%s' should be str" % type(value)
+ raise TypeError("wrong type '%s' should be str" % type(value))
# memory size configuration stuff
@@ -102,8 +102,8 @@ def toFloat(value, target_type='float', units=None, prefixes=[]):
try:
return float(value)
except ValueError:
- raise ValueError, "cannot convert '%s' to %s" % \
- (value, target_type)
+ raise ValueError("cannot convert '%s' to %s" % \
+ (value, target_type))
value = value[:-len(units)]
@@ -124,8 +124,8 @@ def toInteger(value, target_type='integer', units=None, prefixes=[]):
value = toFloat(value, target_type, units, prefixes)
result = long(value)
if value != result:
- raise ValueError, "cannot convert '%s' to integer %s" % \
- (value, target_type)
+ raise ValueError("cannot convert '%s' to integer %s" % \
+ (value, target_type))
return result
@@ -155,7 +155,7 @@ def anyToLatency(value):
"""result is a clock period"""
try:
return 1 / toFrequency(value)
- except ValueError, ZeroDivisionError:
+ except (ValueError, ZeroDivisionError):
pass
try:
@@ -163,7 +163,7 @@ def anyToLatency(value):
except ValueError:
pass
- raise ValueError, "cannot convert '%s' to clock period" % value
+ raise ValueError("cannot convert '%s' to clock period" % value)
def anyToFrequency(value):
"""result is a clock period"""
@@ -174,10 +174,10 @@ def anyToFrequency(value):
try:
return 1 / toLatency(value)
- except ValueError, ZeroDivisionError:
+ except ValueError as ZeroDivisionError:
pass
- raise ValueError, "cannot convert '%s' to clock period" % value
+ raise ValueError("cannot convert '%s' to clock period" % value)
def toNetworkBandwidth(value):
return toMetricFloat(value, 'network bandwidth', 'bps')
@@ -190,29 +190,29 @@ def toMemorySize(value):
def toIpAddress(value):
if not isinstance(value, str):
- raise TypeError, "wrong type '%s' should be str" % type(value)
+ raise TypeError("wrong type '%s' should be str" % type(value))
bytes = value.split('.')
if len(bytes) != 4:
- raise ValueError, 'invalid ip address %s' % value
+ raise ValueError('invalid ip address %s' % value)
for byte in bytes:
if not 0 <= int(byte) <= 0xff:
- raise ValueError, 'invalid ip address %s' % value
+ raise ValueError('invalid ip address %s' % value)
return (int(bytes[0]) << 24) | (int(bytes[1]) << 16) | \
(int(bytes[2]) << 8) | (int(bytes[3]) << 0)
def toIpNetmask(value):
if not isinstance(value, str):
- raise TypeError, "wrong type '%s' should be str" % type(value)
+ raise TypeError("wrong type '%s' should be str" % type(value))
(ip, netmask) = value.split('/')
ip = toIpAddress(ip)
netmaskParts = netmask.split('.')
if len(netmaskParts) == 1:
if not 0 <= int(netmask) <= 32:
- raise ValueError, 'invalid netmask %s' % netmask
+ raise ValueError('invalid netmask %s' % netmask)
return (ip, int(netmask))
elif len(netmaskParts) == 4:
netmaskNum = toIpAddress(netmask)
@@ -223,18 +223,18 @@ def toIpNetmask(value):
testVal |= (1 << (31 - i))
if testVal == netmaskNum:
return (ip, i + 1)
- raise ValueError, 'invalid netmask %s' % netmask
+ raise ValueError('invalid netmask %s' % netmask)
else:
- raise ValueError, 'invalid netmask %s' % netmask
+ raise ValueError('invalid netmask %s' % netmask)
def toIpWithPort(value):
if not isinstance(value, str):
- raise TypeError, "wrong type '%s' should be str" % type(value)
+ raise TypeError("wrong type '%s' should be str" % type(value))
(ip, port) = value.split(':')
ip = toIpAddress(ip)
if not 0 <= int(port) <= 0xffff:
- raise ValueError, 'invalid port %s' % port
+ raise ValueError('invalid port %s' % port)
return (ip, int(port))
def toVoltage(value):