Send empty lists rather than NotFoundError exceptions where appropriate; compact some code

This commit is contained in:
Dan Williams 2006-10-06 11:05:27 -04:00
parent 022c183016
commit 75fb1a33de
2 changed files with 9 additions and 24 deletions

View File

@ -4,8 +4,6 @@ PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
ACTIVITY_DBUS_OBJECT_PATH = "/org/laptop/Presence/Activities/"
ACTIVITY_DBUS_INTERFACE = "org.laptop.Presence.Activity"
class NotFoundError(Exception):
pass
class ActivityDBusHelper(dbus.service.Object):
def __init__(self, parent, bus_name, object_path):
@ -17,22 +15,16 @@ class ActivityDBusHelper(dbus.service.Object):
@dbus.service.method(ACTIVITY_DBUS_INTERFACE,
in_signature="s", out_signature="ao")
def getServicesOfType(self, stype):
services = self._parent.get_services_of_type(stype)
if not services:
raise NotFoundError("Not found")
ret = []
for serv in services:
for serv in self._parent.get_services_of_type(stype):
ret.append(serv.object_path())
return ret
@dbus.service.method(ACTIVITY_DBUS_INTERFACE,
in_signature="", out_signature="ao")
def getServices(self):
services = self._parent.get_services()
if not services:
raise NotFoundError("Not found")
ret = []
for serv in services:
for serv in self._parent.get_services():
ret.append(serv.object_path())
return ret
@ -49,11 +41,8 @@ class ActivityDBusHelper(dbus.service.Object):
@dbus.service.method(ACTIVITY_DBUS_INTERFACE,
in_signature="", out_signature="ao")
def getJoinedBuddies(self):
buddies = self._parent.get_joined_buddies()
if not buddies:
raise NotFoundError("Not found")
ret = []
for buddy in buddies:
for buddy in self._parent.get_joined_buddies():
ret.append(buddy.object_path())
return ret
@ -119,7 +108,7 @@ class Activity(object):
def get_services_of_type(self, stype):
if self._services.has_key(stype):
return self._services[stype]
return None
return []
def get_joined_buddies(self):
buddies = []

View File

@ -148,27 +148,24 @@ class PresenceServiceDBusHelper(dbus.service.Object):
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
in_signature="", out_signature="ao")
def getServices(self):
services = self._parent.get_services()
ret = []
for serv in services:
for serv in self._parent.get_services():
ret.append(serv.object_path())
return ret
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
in_signature="s", out_signature="ao")
def getServicesOfType(self, stype):
services = self._parent.get_services_of_type(stype)
ret = []
for serv in services:
for serv in self._parent.get_services_of_type(stype):
ret.append(serv.object_path())
return ret
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
in_signature="", out_signature="ao")
def getActivities(self):
activities = self._parent.get_activities()
ret = []
for act in activities:
for act in self._parent.get_activities():
ret.append(act.object_path())
return ret
@ -183,9 +180,8 @@ class PresenceServiceDBusHelper(dbus.service.Object):
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
in_signature="", out_signature="ao")
def getBuddies(self):
buddies = self._parent.get_buddies()
ret = []
for buddy in buddies:
for buddy in self._parent.get_buddies():
ret.append(buddy.object_path())
return ret
@ -260,7 +256,7 @@ class PresenceServiceDBusHelper(dbus.service.Object):
found_serv = serv
break
if not found_serv:
raise NotFoundError("The activity %s was not found." % service_op)
raise NotFoundError("The service %s was not found." % service_op)
return self._parent.unregister_service(found_serv, sender)
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,