Mercurial > libervia-backend
diff src/plugins/plugin_xep_0047.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 | 301b342c697a |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0047.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0047.py Fri Mar 28 18:07:02 2014 +0100 @@ -21,9 +21,7 @@ from logging import debug, info, warning, error from twisted.words.protocols.jabber import client as jabber_client, jid from twisted.words.xish import domish -import twisted.internet.error from twisted.internet import reactor -from sat.core.exceptions import ProfileNotInCacheError from wokkel import disco, iwokkel @@ -69,8 +67,6 @@ def profileConnected(self, profile): client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError client.xep_0047_current_stream = {} # key: stream_id, value: data(dict) def _timeOut(self, sid, profile): @@ -85,9 +81,6 @@ @param sid: id of client.xep_0047_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_0047_current_stream: warning(_("kill id called on a non existant id")) return @@ -112,8 +105,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_0047_current_stream[sid]["file_obj"] data["position"] = str(file_obj.tell()) @@ -131,8 +122,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_0047_current_stream[sid] = {} data["from"] = from_jid data["file_obj"] = file_obj @@ -148,8 +137,6 @@ debug(_("IBB stream opening")) IQ.handled = True client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError open_elt = IQ.firstChildElement() block_size = open_elt.getAttribute('block-size') sid = open_elt.getAttribute('sid') @@ -190,8 +177,6 @@ def streamClosing(self, IQ, profile): IQ.handled = True client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError debug(_("IBB stream closing")) data_elt = IQ.firstChildElement() sid = data_elt.getAttribute('sid') @@ -205,8 +190,6 @@ def iqData(self, IQ, profile): IQ.handled = True client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError data_elt = IQ.firstChildElement() if self._manageDataElt(data_elt, 'iq', IQ['id'], jid.JID(IQ['from']), profile): @@ -219,7 +202,6 @@ client.xmlstream.send(result) def messageData(self, message_elt, profile): - data_elt = message_elt.firstChildElement() sid = message_elt.getAttribute('id', '') self._manageDataElt(message_elt, 'message', sid, jid.JID(message_elt['from']), profile) @@ -228,8 +210,6 @@ @param data_elt: "data" domish element @return: True if success""" client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError sid = data_elt.getAttribute('sid') if sid not in client.xep_0047_current_stream: error(_("Received data for an unknown session id")) @@ -289,8 +269,6 @@ @param failureCb: method to call when something goes wrong @param profile: %(doc_profile)s""" client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError if length is not None: error(_('stream length not managed yet')) return @@ -317,8 +295,6 @@ def iqResult(self, sid, seq, length, profile, iq_elt): """Called when the result of open iq is received""" client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError data = client.xep_0047_current_stream[sid] if iq_elt["type"] == "error": warning(_("Transfer failed")) @@ -351,8 +327,6 @@ @param callback: method to call after finishing @param failure_reason: reason of the failure, or None if steam was successful""" client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError data = client.xep_0047_current_stream[sid] iq_elt = jabber_client.IQ(client.xmlstream, 'set') iq_elt['to'] = data["to"].full()