plugin XEP-0047: minor improvements

This commit is contained in:
Goffi 2015-11-02 22:02:41 +01:00
commit ed7e784ffe

View file

@ -20,6 +20,7 @@
from sat.core.i18n import _
from sat.core.log import getLogger
log = getLogger(__name__)
from sat.core.constants import Const as C
from sat.core import exceptions
from twisted.words.protocols.jabber import client as jabber_client
from twisted.words.protocols.jabber import jid
@ -277,7 +278,7 @@ class XEP_0047(object):
self._killSession(sid, client, error_condition)
client.xmlstream.send(iq_elt)
def startStream(self, file_obj, to_jid, sid, block_size=None, profile=None):
def startStream(self, file_obj, to_jid, sid, block_size=None, profile=C.PROF_KEY_NONE):
"""Launch the stream workflow
@param file_obj(file): file_obj to send
@ -287,7 +288,6 @@ class XEP_0047(object):
@param profile: %(doc_profile)s
"""
session_data = self._createSession(file_obj, to_jid, sid, profile)
session_defer = session_data[DEFER_KEY]
client = self.host.getClient(profile)
if block_size is None:
@ -295,7 +295,7 @@ class XEP_0047(object):
assert block_size <= 65535
session_data["block_size"] = block_size
iq_elt = jabber_client.IQ(client.xmlstream, 'set')
iq_elt = jabber_client.IQ(client.xmlstream, 'set') # FIXME: use client.IQ here
iq_elt['from'] = client.jid.full()
iq_elt['to'] = to_jid.full()
open_elt = iq_elt.addElement('open', NS_IBB)
@ -304,7 +304,7 @@ class XEP_0047(object):
open_elt['stanza'] = 'iq' # TODO: manage <message> stanza ?
iq_elt.addCallback(self._IQDataStream, session_data, client)
iq_elt.send()
return session_defer
return session_data[DEFER_KEY]
def _IQDataStream(self, session_data, client, iq_elt):
"""Called during the whole data streaming
@ -322,7 +322,7 @@ class XEP_0047(object):
buffer_ = session_data["file_obj"].read(session_data["block_size"])
if buffer_:
next_iq_elt = jabber_client.IQ(client.xmlstream, 'set')
next_iq_elt = jabber_client.IQ(client.xmlstream, 'set') # FIXME: use client.IQ here
next_iq_elt['to'] = session_data["to"].full()
data_elt = next_iq_elt.addElement('data', NS_IBB)
seq = session_data['seq'] = (session_data['seq'] + 1) % 65535