diff src/plugins/plugin_xep_0065.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 1fe00f0c9a91
children e1842ebcb2f3
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0065.py	Fri Mar 28 18:06:51 2014 +0100
+++ b/src/plugins/plugin_xep_0065.py	Fri Mar 28 18:07:02 2014 +0100
@@ -256,7 +256,7 @@
                 # Any other command is not supported
                 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED)
 
-        except struct.error, why:
+        except struct.error:
             return None
 
     def _makeRequest(self):
@@ -300,7 +300,7 @@
                 self.state = STATE_TARGET_READY
                 self.factory.activateCb(self.sid, self.factory.iq_id, self.profile)
 
-        except struct.error, why:
+        except struct.error:
             return None
 
     def connectionMade(self):
@@ -323,8 +323,6 @@
             return
         self.sid, self.profile = self.factory.hash_sid_map[addr]
         client = self.factory.host.getClient(self.profile)
-        if not client:
-            raise ProfileNotInCacheError
         client.xep_0065_current_stream[self.sid]["start_transfer_cb"] = self.startTransfer
         self.connectCompleted(addr, 0)
         self.transport.stopReading()
@@ -481,8 +479,6 @@
 
     def profileConnected(self, profile):
         client = self.host.getClient(profile)
-        if not client:
-            raise ProfileNotInCacheError
         client.xep_0065_current_stream = {}  # key: stream_id, value: data(dict)
 
     def getExternalIP(self):
@@ -492,8 +488,6 @@
     def getProgress(self, sid, data, profile):
         """Fill data with position of current transfer"""
         client = self.host.getClient(profile)
-        if not client:
-            raise ProfileNotInCacheError
         try:
             file_obj = client.xep_0065_current_stream[sid]["file_obj"]
             data["position"] = str(file_obj.tell())
@@ -513,9 +507,6 @@
         @param sid: id of client.xep_0065_current_stream"""
         assert(profile)
         client = self.host.getClient(profile)
-        if not client:
-            warning(_("Client no more in cache"))
-            return
         if sid not in client.xep_0065_current_stream:
             warning(_("kill id called on a non existant id"))
             return
@@ -553,9 +544,6 @@
         @param profile: %(doc_profile)s"""
         assert(profile)
         client = self.host.getClient(profile)
-        if not client:
-            error(_("Unknown profile, this should not happen"))
-            raise ProfileNotInCacheError
 
         if length is not None:
             error(_('stream length not managed yet'))
@@ -604,8 +592,6 @@
             warning(_("Transfer failed"))
             return
         client = self.host.getClient(profile)
-        if not client:
-            raise ProfileNotInCacheError
         try:
             data = client.xep_0065_current_stream[sid]
             file_obj = data["file_obj"]
@@ -641,8 +627,6 @@
     def activateProxyStream(self, sid, iq_id, start_transfer_cb, profile):
         debug(_("activating stream"))
         client = self.host.getClient(profile)
-        if not client:
-            raise ProfileNotInCacheError
         data = client.xep_0065_current_stream[sid]
         profile_jid, xmlstream = self.host.getJidNStream(profile)
 
@@ -672,8 +656,6 @@
         @param failure_cb: method to call when something goes wrong
         @param profile: %(doc_profile)s"""
         client = self.host.getClient(profile)
-        if not client:
-            raise ProfileNotInCacheError
         data = client.xep_0065_current_stream[sid] = {}
         data["from"] = from_jid
         data["file_obj"] = file_obj
@@ -731,8 +713,6 @@
 
     def activateStream(self, sid, iq_id, profile):
         client = self.host.getClient(profile)
-        if not client:
-            raise ProfileNotInCacheError
         debug(_("activating stream"))
         result = domish.Element((None, 'iq'))
         data = client.xep_0065_current_stream[sid]
@@ -799,11 +779,11 @@
         if len(streamhost_elts) != 1:
             warning(_("Multiple streamhost elements in proxy not managed, keeping only the first one"))
         streamhost_elt = streamhost_elts[0]
-        proxy = self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid", ""),
-                                          "File Transfer", profile_key=self.parent.profile)
-        proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host", ""),
-                                          "File Transfer", profile_key=self.parent.profile)
-        proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port", ""),
+        self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid", ""),
+                                  "File Transfer", profile_key=self.parent.profile)
+        self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host", ""),
+                                  "File Transfer", profile_key=self.parent.profile)
+        self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port", ""),
                                           "File Transfer", profile_key=self.parent.profile)
 
     def connectionInitialized(self):
@@ -814,7 +794,7 @@
                 return
             iq_elt = jabber_client.IQ(self.parent.xmlstream, 'get')
             iq_elt["to"] = proxy_ent.full()
-            query_elt = iq_elt.addElement('query', NS_BS)
+            iq_elt.addElement('query', NS_BS)
             iq_elt.addCallback(self._proxyDataResult)
             iq_elt.send()