test: Make exceptions compatible with Python 3

Use "except Type as var" syntax to work with both Python >= 2.6
and Python 3.
This commit is contained in:
Martin Pitt 2014-03-11 17:39:19 +01:00 committed by Denis Kenzior
parent 0c1fcd2b50
commit 0393a41e35
17 changed files with 45 additions and 45 deletions

View File

@ -35,6 +35,6 @@ for path, properties in modems:
try:
context.SetProperty("Active", dbus.Boolean(1), timeout = 100)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Error activating %s: %s" % (path, str(e)))
exit(2)

View File

@ -33,6 +33,6 @@ for path, properties in modems:
try:
context.SetProperty("Active", dbus.Boolean(0))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Error activating %s: %s" % (path, str(e)))
exit(2)

View File

@ -41,7 +41,7 @@ if __name__ == "__main__":
try:
cf.DisableAll(type, timeout = 100)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to DisableAll %s" % e)
sys.exit(1);

View File

@ -46,13 +46,13 @@ if __name__ == "__main__":
try:
cf.SetProperty(property, dbus.UInt16(value),
timeout = 100)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable SetProperty %s" % e)
sys.exit(1);
else:
try:
cf.SetProperty(property, value, timeout = 100)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable SetProperty %s" % e)
sys.exit(1);

View File

@ -33,7 +33,7 @@ for path, properties in modems:
try:
context.SetProperty(sys.argv[2], sys.argv[3])
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Error setting context %s property %s: %s" %\
(path, sys.argv[2], str(e)))
exit(2)

View File

@ -67,7 +67,7 @@ if __name__ == "__main__":
print("Resetting Accumulated Call Meter")
try:
cm.Reset(pin)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to reset ACM: %s" % e)
sys.exit(1)
else:
@ -77,7 +77,7 @@ if __name__ == "__main__":
elif property == 'PricePerUnit':
newvalue = float(newvalue)
cm.SetProperty(property, newvalue, pin)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set property: %s" % e)
sys.exit(1)

View File

@ -60,13 +60,13 @@ if __name__ == "__main__":
print("Disabling all barrings")
try:
cb.DisableAll(pin)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to Disable All barrings: ", e)
sys.exit(1)
elif (sys.argv[1] == 'passwd'):
try:
cb.ChangePassword(old_password, new_password)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to change password: ", e)
sys.exit(1)
print("Password changed")
@ -74,7 +74,7 @@ if __name__ == "__main__":
else:
try:
cb.SetProperty(property, newvalue, pin)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set property: ", e)
sys.exit(1)

View File

@ -36,47 +36,47 @@ if __name__ == "__main__":
try:
cf.SetProperty("FoobarNoReplyTimeout", dbus.UInt16(19))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set timeout - Good")
try:
cf.SetProperty("VoiceNotReachableTimeout", dbus.UInt16(19))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set timeout - Good")
try:
cf.SetProperty("VoiceNoReplyTimeout", dbus.UInt16(19))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set timeout - Good")
try:
cf.SetProperty("DataNoReplyTimeout", dbus.UInt16(19))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set timeout - Good")
try:
cf.SetProperty("FaxNoReplyTimeout", dbus.UInt16(19))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set timeout - Good")
try:
cf.SetProperty("SmsNoReplyTimeout", dbus.UInt16(19))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set timeout - Good")
try:
cf.SetProperty("VoiceNoReply", "")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to erase voice no reply rule - Bad")
try:
cf.SetProperty("VoiceNoReply", "+134444")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to register voice no reply rule - Bad")
try:
cf.SetProperty("VoiceNoReplyTimeout", dbus.UInt16(30))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set voice no reply timeout - Bad")
properties = cf.GetProperties()
@ -86,7 +86,7 @@ if __name__ == "__main__":
try:
cf.SetProperty("VoiceUnconditional", "+155555")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set Voice Unconditional - Bad")
properties = cf.GetProperties()
@ -95,12 +95,12 @@ if __name__ == "__main__":
try:
cf.DisableAll("foobar")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to delete invalids - Good")
try:
cf.DisableAll("conditional")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to delete all conditional - Bad")
properties = cf.GetProperties()
@ -110,7 +110,7 @@ if __name__ == "__main__":
try:
cf.DisableAll("all")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to delete all conditional - Bad")
print(properties["VoiceUnconditional"])

View File

@ -67,7 +67,7 @@ if __name__ == "__main__":
try:
cs.SetProperty(property, newvalue)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set property: %s" % e)
sys.exit(1);

View File

@ -103,7 +103,7 @@ def set_topics(cbs):
try:
print("Setting Cell Broadcast topics...")
cbs.SetProperty("Topics", topics);
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set topic: %s" % e)
print("-----------------------------------------------------------")

View File

@ -44,21 +44,21 @@ def stdin_handler(fd, condition, gnss, path):
try:
gnss.SendPositioningElement(dbus.String(xml))
print("ok")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to send positioning element")
elif in_key == '1':
try:
gnss.RegisterPositioningRequestAgent("/test/posagent")
print("ok")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to register positioning agent")
elif in_key == '2':
try:
gnss.UnregisterPositioningRequestAgent(path)
print("ok")
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to unregister positioning agent")
elif in_key == 'x':
sys.exit(1)

View File

@ -61,7 +61,7 @@ if __name__ == "__main__":
obj = bus.get_object('org.ofono', plmn);
op = dbus.Interface(obj, 'org.ofono.NetworkOperator')
op.Register()
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to register: %s" % e)
sys.exit(1)

View File

@ -48,7 +48,7 @@ def message_delivery_report(sms, value):
try:
sms.SetProperty("UseDeliveryReports", dbus.Boolean(value))
except dbus.DBusException, e:
except dbus.DBusException as e:
if value == 1:
print("Unable to activate Delivery Reports - FAIL")
@ -58,13 +58,13 @@ def message_delivery_report(sms, value):
def message_service_center_address(sms, value):
try:
sms.SetProperty("ServiceCenterAddress",dbus.String(value))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set correct Service Center Address - FAIL")
def message_bearer(sms, value):
try:
sms.SetProperty("Bearer", dbus.String(value))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to set Bearer[%s] - FAIL" % (value))

View File

@ -22,7 +22,7 @@ ss = dbus.Interface(bus.get_object('org.ofono', modem),
try:
ss_type, properties = ss.Initiate(ss_code, timeout=100)
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Unable to perform operation: %s" % e)
sys.exit(1);

View File

@ -37,25 +37,25 @@ if __name__ == "__main__":
print("Trying invalid SS request for CB")
try:
print(ss.Initiate("*33#456666"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Trying invalid SS request for CB")
try:
print(ss.Initiate("*33*ABC#"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Trying invalid SS request for CB")
try:
print(ss.Initiate("*33**ABC#"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Trying invalid SS request for CB")
try:
print(ss.Initiate("*33***12#"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Query Outgoing All")

View File

@ -37,19 +37,19 @@ if __name__ == "__main__":
print("Trying invalid SS request for CLIR")
try:
print(ss.Initiate("*31#456666"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Trying invalid SS request for CLIR")
try:
print(ss.Initiate("*31*455*4#"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Trying invalid SS request for CLIR")
try:
print(ss.Initiate("*31**44435#"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Query CLIP")
@ -77,19 +77,19 @@ if __name__ == "__main__":
print("Trying invalid SS request for CW")
try:
print(ss.Initiate("*43#456666"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Trying invalid SS request for CW")
try:
print(ss.Initiate("*43*455*4#"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Trying invalid SS request for CW")
try:
print(ss.Initiate("*43**44435#"))
except dbus.DBusException, e:
except dbus.DBusException as e:
print("Failed with %s - Good" % e)
print("Query CW")

View File

@ -238,7 +238,7 @@ class StkAgent(dbus.service.Object):
if key == 't':
raise EndSession("User wishes to terminate"
" session")
except Exception, exc:
except Exception as exc:
print(exc)
@dbus.service.method("org.ofono.SimToolkitAgent",