From 75fb1a33de7243cb33be322597d0ae21ae95311b Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 06 Oct 2006 15:05:27 +0000 Subject: Send empty lists rather than NotFoundError exceptions where appropriate; compact some code --- (limited to 'services') diff --git a/services/presence/Activity.py b/services/presence/Activity.py index a900ea1..e03a98b 100644 --- a/services/presence/Activity.py +++ b/services/presence/Activity.py @@ -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 = [] diff --git a/services/presence/PresenceService.py b/services/presence/PresenceService.py index 5fdc48c..71fd641 100644 --- a/services/presence/PresenceService.py +++ b/services/presence/PresenceService.py @@ -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, -- cgit v0.9.1