summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2011-12-13 11:55:44 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-12-13 11:55:44 +0000
commit14225c74b5bd75cf6c4cda3647341dc20214e6b8 (patch)
tree681f90d0f96ac02d393a74f9312de33d1c6f7cb3
parent959ce518a3b5b8794b9813bac82c64540c21fc31 (diff)
downloaddbus-python-14225c74b5bd75cf6c4cda3647341dc20214e6b8.tar.gz
Use Python 3 syntax to catch exceptions
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r--dbus/_expat_introspect_parser.py2
-rw-r--r--dbus/bus.py2
-rw-r--r--dbus/connection.py6
-rw-r--r--dbus/proxies.py2
-rw-r--r--dbus/service.py6
-rw-r--r--examples/example-client.py2
-rw-r--r--test/cross-test-client.py8
-rwxr-xr-xtest/test-client.py12
-rwxr-xr-xtest/test-service.py2
9 files changed, 21 insertions, 21 deletions
diff --git a/dbus/_expat_introspect_parser.py b/dbus/_expat_introspect_parser.py
index 96b27ad..de38c45 100644
--- a/dbus/_expat_introspect_parser.py
+++ b/dbus/_expat_introspect_parser.py
@@ -81,5 +81,5 @@ def process_introspection_data(data):
"""
try:
return _Parser().parse(data)
- except Exception, e:
+ except Exception as e:
raise IntrospectionParserException('%s: %s' % (e.__class__, e))
diff --git a/dbus/bus.py b/dbus/bus.py
index 86c655d..6f775de 100644
--- a/dbus/bus.py
+++ b/dbus/bus.py
@@ -176,7 +176,7 @@ class BusConnection(Connection):
and bus_name != BUS_DAEMON_NAME):
try:
return self.get_name_owner(bus_name)
- except DBusException, e:
+ except DBusException as e:
if e.get_dbus_name() != _NAME_HAS_NO_OWNER:
raise
# else it doesn't exist: try to start it
diff --git a/dbus/connection.py b/dbus/connection.py
index d76aaf2..10f03c7 100644
--- a/dbus/connection.py
+++ b/dbus/connection.py
@@ -525,7 +525,7 @@ class Connection(_Connection):
for cb in self.__call_on_disconnection:
try:
cb(self)
- except Exception, e:
+ except Exception as e:
# basicConfig is a no-op if logging is already configured
logging.basicConfig()
_logger.error('Exception in handler for Disconnected '
@@ -564,7 +564,7 @@ class Connection(_Connection):
# Add the arguments to the function
try:
message.append(signature=signature, *args)
- except Exception, e:
+ except Exception as e:
logging.basicConfig()
_logger.error('Unable to set arguments %r according to '
'signature %r: %s: %s',
@@ -618,7 +618,7 @@ class Connection(_Connection):
# Add the arguments to the function
try:
message.append(signature=signature, *args)
- except Exception, e:
+ except Exception as e:
logging.basicConfig()
_logger.error('Unable to set arguments %r according to '
'signature %r: %s: %s',
diff --git a/dbus/proxies.py b/dbus/proxies.py
index bf99a1c..51d8d9f 100644
--- a/dbus/proxies.py
+++ b/dbus/proxies.py
@@ -388,7 +388,7 @@ class ProxyObject(object):
try:
try:
self._introspect_method_map = process_introspection_data(data)
- except IntrospectionParserException, e:
+ except IntrospectionParserException as e:
self._introspect_error_handler(e)
return
diff --git a/dbus/service.py b/dbus/service.py
index b92d840..f1b3a9b 100644
--- a/dbus/service.py
+++ b/dbus/service.py
@@ -250,12 +250,12 @@ def _method_reply_return(connection, message, method_name, signature, *retval):
reply = MethodReturnMessage(message)
try:
reply.append(signature=signature, *retval)
- except Exception, e:
+ except Exception as e:
logging.basicConfig()
if signature is None:
try:
signature = reply.guess_signature(retval) + ' (guessed)'
- except Exception, e:
+ except Exception as e:
_logger.error('Unable to guess signature for arguments %r: '
'%s: %s', retval, e.__class__, e)
raise
@@ -743,7 +743,7 @@ class Object(Interface):
retval = (retval,)
_method_reply_return(connection, message, method_name, signature, *retval)
- except Exception, exception:
+ except Exception as exception:
# send error reply
_method_reply_error(connection, message, exception)
diff --git a/examples/example-client.py b/examples/example-client.py
index 796f262..262f892 100644
--- a/examples/example-client.py
+++ b/examples/example-client.py
@@ -65,7 +65,7 @@ def main():
# D-Bus exceptions are mapped to Python exceptions
try:
iface.RaiseException()
- except dbus.DBusException, e:
+ except dbus.DBusException as e:
print str(e)
# introspection is automatically supported
diff --git a/test/cross-test-client.py b/test/cross-test-client.py
index ee18f77..e2e155f 100644
--- a/test/cross-test-client.py
+++ b/test/cross-test-client.py
@@ -86,7 +86,7 @@ class Client(SignalTestsImpl):
method = getattr(if_obj, member)
try:
real_ret = method(*args)
- except Exception, e:
+ except Exception as e:
self.fail_id += 1
print "%s.%s fail %d" % (interface, member, self.fail_id)
s = ("report %d: %s.%s%r: raised %r \"%s\""
@@ -97,7 +97,7 @@ class Client(SignalTestsImpl):
return
try:
check_fn(real_ret, check_arg)
- except Exception, e:
+ except Exception as e:
self.fail_id += 1
print "%s.%s fail %d" % (interface, member, self.fail_id)
s = ("report %d: %s.%s%r: %s"
@@ -122,7 +122,7 @@ class Client(SignalTestsImpl):
for i in xrange(len(exp)):
try:
equals(real_ret[i], exp[i])
- except AssertionError, e:
+ except AssertionError as e:
if not isinstance(e.args, tuple):
e.args = (e.args,)
e.args = e.args + ('(at position %d in sequence)' % i,)
@@ -131,7 +131,7 @@ class Client(SignalTestsImpl):
for k in exp:
try:
equals(real_ret[k], exp[k])
- except AssertionError, e:
+ except AssertionError as e:
if not isinstance(e.args, tuple):
e.args = (e.args,)
e.args = e.args + ('(at key %r in dict)' % k,)
diff --git a/test/test-client.py b/test/test-client.py
index 753d892..e0e639c 100755
--- a/test/test-client.py
+++ b/test/test-client.py
@@ -199,7 +199,7 @@ class TestDBusBindings(unittest.TestCase):
elif not self.utf8 and isinstance(val, dbus.UTF8String):
failures.append('%r should not have been utf8' % val)
return
- except Exception, e:
+ except Exception as e:
failures.append("%s:\n%s" % (e.__class__, e))
def error_handler(self, error):
@@ -371,7 +371,7 @@ class TestDBusBindings(unittest.TestCase):
try:
print "requesting %s" % name
busname = dbus.service.BusName(name, dbus.SessionBus())
- except Exception, e:
+ except Exception as e:
print "%s:\n%s" % (e.__class__, e)
self.assert_(not succeed, 'did not expect registering bus name %s to fail' % name)
else:
@@ -462,7 +462,7 @@ class TestDBusBindings(unittest.TestCase):
self.assertRaises(dbus.DBusException, self.iface.AsyncRaise)
try:
self.iface.AsyncRaise()
- except dbus.DBusException, e:
+ except dbus.DBusException as e:
self.assert_(e.get_dbus_name() ==
'org.freedesktop.bugzilla.bug12403',
e.get_dbus_name())
@@ -518,7 +518,7 @@ class TestDBusBindings(unittest.TestCase):
try:
self.iface.RaiseValueError()
- except Exception, e:
+ except Exception as e:
self.assert_(isinstance(e, dbus.DBusException), e.__class__)
self.assert_('.ValueError: Traceback ' in str(e),
'Wanted a traceback but got:\n"""%s"""' % str(e))
@@ -527,7 +527,7 @@ class TestDBusBindings(unittest.TestCase):
try:
self.iface.RaiseDBusExceptionNoTraceback()
- except Exception, e:
+ except Exception as e:
self.assert_(isinstance(e, dbus.DBusException), e.__class__)
self.assertEquals(str(e),
'com.example.Networking.ServerError: '
@@ -537,7 +537,7 @@ class TestDBusBindings(unittest.TestCase):
try:
self.iface.RaiseDBusExceptionWithTraceback()
- except Exception, e:
+ except Exception as e:
self.assert_(isinstance(e, dbus.DBusException), e.__class__)
self.assert_(str(e).startswith('com.example.Misc.RealityFailure: '
'Traceback '),
diff --git a/test/test-service.py b/test/test-service.py
index 51865eb..bd80f26 100755
--- a/test/test-service.py
+++ b/test/test-service.py
@@ -267,7 +267,7 @@ class TestObject(dbus.service.Object, TestInterface):
return_cb(variant)
return False # do not run again
- except Exception, e:
+ except Exception as e:
error_cb(e)
@dbus.service.method(IFACE, in_signature='', out_signature='s', sender_keyword='sender')