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
This commit is contained in:
parent
ed9df2984d
commit
a6897c76e0
1 changed files with 25 additions and 140 deletions
|
|
@ -21,9 +21,7 @@ from sat.core.i18n import _
|
|||
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 @@ class XEP_0047(object):
|
|||
|
||||
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 @@ class XEP_0047(object):
|
|||
@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 @@ class XEP_0047(object):
|
|||
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 @@ class XEP_0047(object):
|
|||
@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 @@ class XEP_0047(object):
|
|||
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 @@ class XEP_0047(object):
|
|||
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 @@ class XEP_0047(object):
|
|||
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 @@ class XEP_0047(object):
|
|||
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 @@ class XEP_0047(object):
|
|||
@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 @@ class XEP_0047(object):
|
|||
@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 @@ class XEP_0047(object):
|
|||
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 @@ class XEP_0047(object):
|
|||
@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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue