diff src/core/sat_main.py @ 941:c6d8fc63b1db

core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
author Goffi <goffi@goffi.org>
date Fri, 28 Mar 2014 18:07:02 +0100
parents cbf4122baae7
children 71926ec2114d
line wrap: on
line diff
--- a/src/core/sat_main.py	Fri Mar 28 18:06:51 2014 +0100
+++ b/src/core/sat_main.py	Fri Mar 28 18:07:02 2014 +0100
@@ -26,7 +26,6 @@
 
 from twisted.internet import reactor
 
-from wokkel import compat
 from wokkel.xmppim import RosterItem
 
 from sat.bridge.DBus import DBusBridge
@@ -40,7 +39,6 @@
 from sat.core import exceptions
 from sat.core.constants import Const as C
 from sat.memory.memory import Memory
-from sat.tools.xml_tools import tupleList2dataForm
 from sat.tools.misc import TriggerManager
 from glob import glob
 from uuid import uuid4
@@ -295,8 +293,6 @@
 
     def getContacts(self, profile_key):
         client = self.getClient(profile_key)
-        if not client:
-            raise exceptions.ProfileUnknownError(_('Asking contacts for a non-existant profile'))
         ret = []
         for item in client.roster.getItems():  # we get all items for client's roster
             # and convert them to expected format
@@ -306,9 +302,7 @@
 
     def getContactsFromGroup(self, group, profile_key):
         client = self.getClient(profile_key)
-        if not client:
-            raise exceptions.ProfileUnknownError(_("Asking group's contacts for a non-existant profile"))
-        return [jid.full() for jid in client.roster.getJidsFromGroup(group)]
+        return [jid_.full() for jid_ in client.roster.getJidsFromGroup(group)]
 
     def purgeClient(self, profile):
         """Remove reference to a profile client and purge cache
@@ -350,7 +344,7 @@
         @return: client or None if it doesn't exist"""
         profile = self.memory.getProfileName(profile_key)
         if not profile:
-            return None
+            raise exceptions.ProfileKeyUnknownError
         return self.profiles[profile]
 
     def getClients(self, profile_key):
@@ -443,8 +437,6 @@
     def getWaitingConf(self, profile_key=None):
         assert(profile_key)
         client = self.getClient(profile_key)
-        if not client:
-            raise exceptions.ProfileNotInCacheError
         ret = []
         for conf_id in client._waiting_conf:
             conf_type, data = client._waiting_conf[conf_id][:2]
@@ -769,8 +761,6 @@
         """
         # FIXME: use XMLUI and *callback methods for dialog
         client = self.getClient(profile)
-        if not client:
-            raise exceptions.ProfileUnknownError(_("Asking confirmation a non-existant profile"))
         if conf_id in client._waiting_conf:
             error(_("Attempt to register two callbacks for the same confirmation"))
         else:
@@ -780,8 +770,6 @@
     def confirmationAnswer(self, conf_id, accepted, data, profile):
         """Called by frontends to answer confirmation requests"""
         client = self.getClient(profile)
-        if not client:
-            raise exceptions.ProfileUnknownError(_("Confirmation answer from a non-existant profile"))
         debug(_("Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")})
         if conf_id not in client._waiting_conf:
             error(_("Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile})
@@ -793,15 +781,11 @@
     def registerProgressCB(self, progress_id, CB, profile):
         """Register a callback called when progress is requested for id"""
         client = self.getClient(profile)
-        if not client:
-            raise exceptions.ProfileUnknownError
         client._progress_cb_map[progress_id] = CB
 
     def removeProgressCB(self, progress_id, profile):
         """Remove a progress callback"""
         client = self.getClient(profile)
-        if not client:
-            raise exceptions.ProfileUnknownError
         if progress_id not in client._progress_cb_map:
             error(_("Trying to remove an unknow progress callback"))
         else:
@@ -813,8 +797,6 @@
         data['size'] : end_position
         """
         client = self.getClient(profile)
-        if not profile:
-            raise exceptions.ProfileNotInCacheError
         data = {}
         try:
             client._progress_cb_map[progress_id](progress_id, data, profile)