Commit 80a85700 authored by Alex Pearce's avatar Alex Pearce Committed by kreczko
Browse files

Use Python 3 compatible `except` syntax.

The forward compatible syntax from 2.6 plus is:

    except SomeException as err

rather than

    except SomeException, err
parent aeb156f0
......@@ -447,7 +447,7 @@ class gaudimain(object):
# It may not be 100% correct, but usually it means a segfault in C++
self.ip.setProperty('ReturnCode', str(128 + 11))
statuscode = False
except Exception, x:
except Exception as x:
print 'Exception:', x
# for other exceptions, just set a generic error code
self.ip.setProperty('ReturnCode', '1')
......
......@@ -67,18 +67,18 @@ if '__main__' == __name__:
try:
xp2.SVector5 = [1, 2, 3, 4, 5, 6]
except Exception, e:
except Exception as e:
print ' Exception: ', e
try:
xp2.Point3D = (1, 2, 3, 4)
except Exception, e:
except Exception as e:
print ' Exception: ', e
if not isWin:
try:
xp2.Vector4D = (1, 2, 3)
except Exception, e:
except Exception as e:
print ' Exception: ', e
xp2.Vectors3D = [(1, 2, 3), (4, 5, 6), [7, 8, 9]]
......
......@@ -52,7 +52,7 @@ def test():
if __name__ == '__main__':
try:
test()
except AssertionError, a:
except AssertionError as a:
print "FAILURE:", a
sys.exit(1)
print "SUCCESS"
......@@ -514,7 +514,7 @@ class Configurable(object):
if hasattr(cc, 'setParent') and parent:
try:
cc.setParent(parent)
except RuntimeError, e:
except RuntimeError as e:
# temporary backdoor resolution for compatibility
log.error(str(e) + '%s', error_explanation)
ccbd = cc.configurables[cc.getJobOptName()]
......
......@@ -138,7 +138,7 @@ def loadConfigurableDb():
log.debug("\t-loading [%s]...", confDb)
try:
cfgDb._loadModule(confDb)
except Exception, err:
except Exception as err:
log.warning("Could not load file [%s] !", confDb)
log.warning("Reason: %s", err)
nFiles += 1
......
......@@ -146,7 +146,7 @@ class PropertyProxy(object):
except AttributeError:
# value not yet set
pass
except ValueError, e:
except ValueError as e:
if allowcompat:
log.error('inconsistent value types for %s.%s (%s)' %
(obj.getName(), self.descr.__name__, str(e)))
......@@ -199,7 +199,7 @@ class GaudiHandlePropertyProxyBase(PropertyProxy):
default = self.convertDefaultToBeSet(obj, default)
if default:
self.__set__(obj, default)
except AttributeError, e:
except AttributeError as e:
# change type of exception to avoid false error message
raise RuntimeError(*e.args)
......@@ -266,7 +266,7 @@ class GaudiHandlePropertyProxyBase(PropertyProxy):
# print self.fullPropertyName(obj) + ": Setting default private configurable (from default handle): %r" % conf
except AttributeError, e:
except AttributeError as e:
# change type of exception to avoid false error message
raise RuntimeError(*e.args)
if conf is None:
......@@ -389,7 +389,7 @@ class DataObjectHandleBasePropertyProxy(PropertyProxy):
default = self.convertValueToBeSet(obj, default)
if default:
self.__set__(obj, default)
except AttributeError, e:
except AttributeError as e:
# change type of exception to avoid false error message
raise RuntimeError(*e.args)
......
......@@ -68,7 +68,7 @@ def loadConfigurableDb():
log.debug("\t-loading [%s]..." % confDb)
try:
cfgDb._loadModule(confDb)
except Exception, err:
except Exception as err:
# It may happen that the file is found but not completely
# written, usually during parallel builds, but we do not care.
log.warning("Could not load file [%s] !", confDb)
......@@ -278,7 +278,7 @@ def main():
try:
logging.info("Creating directory %r", output_dir)
os.makedirs(output_dir, 0755)
except OSError, err:
except OSError as err:
import errno
if err.errno == errno.EEXIST:
# somebody already - perhaps concurrently - created that dir.
......
......@@ -53,7 +53,7 @@ def test_invalid_value():
raise
except ValueError:
pass
except Exception, x:
except Exception as x:
assert False, 'ValueError exception expected, got %s' % type(
x).__name__
......@@ -64,7 +64,7 @@ def test_invalid_value():
raise
except ValueError:
pass
except Exception, x:
except Exception as x:
assert False, 'ValueError exception expected, got %s' % type(
x).__name__
......@@ -89,7 +89,7 @@ def test_invalid_key():
raise
except AttributeError:
pass
except Exception, x:
except Exception as x:
assert False, 'AttributeError exception expected, got %s' % type(
x).__name__
......
......@@ -55,7 +55,7 @@ def kill_tree(ppid, sig):
try:
log.debug('killing process %d', ppid)
os.kill(ppid, sig)
except OSError, err:
except OSError as err:
if err.errno != 3: # No such process
raise
log.debug('no such process %d', ppid)
......
......@@ -178,7 +178,7 @@ def zipdir(directory, no_pyc=False):
log.info("File '%s' closed", filename)
else:
log.info("Nothing to do on '%s'", filename)
except UnicodeDecodeError, x:
except UnicodeDecodeError as x:
log.error("Wrong encoding in file '%s':", src)
log.error(" %s", x)
log.error("Probably you forgot the line '# -*- coding: utf-8 -*-'")
......
......@@ -111,7 +111,7 @@ class InterfaceCast(object):
return ip
else:
print "ERROR: queryInterface failed for", obj, "interface:", self.type
except Exception, e:
except Exception as e:
print "ERROR: exception", e, "caught when retrieving interface", self.type, "for object", obj
import traceback
traceback.print_stack()
......@@ -358,7 +358,7 @@ class iProperty(object):
for p in props:
try:
dct[p.name()] = PropertyEntry(p)
except (ValueError, TypeError), e:
except (ValueError, TypeError) as e:
raise ValueError, "gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
(e.__class__.__name__, e.args,
propsFrom, p.name(), p.value())
......@@ -1443,7 +1443,7 @@ def getComponentProperties(name):
obj = factory.instantiate(dummysvc)
else:
obj = factory.instantiate(svcloc)
except RuntimeError, text:
except RuntimeError as text:
print 'Error instantiating', cname, ' from ', name
print text
continue
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment