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
16 changed files with 25 additions and 140 deletions
|
|
@ -23,9 +23,7 @@ from logging import debug, info, warning, error
|
|||
from twisted.words.xish import domish
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.protocols.jabber import error as jab_error
|
||||
import os
|
||||
from twisted.internet import reactor
|
||||
from sat.core.exceptions import ProfileNotInCacheError
|
||||
|
||||
from wokkel import data_form
|
||||
|
||||
|
|
@ -82,8 +80,6 @@ class Exp_Pipe(object):
|
|||
info(_("EXP-PIPE file transfer requested"))
|
||||
debug(si_el.toXml())
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
raise ProfileNotInCacheError
|
||||
pipe_elts = filter(lambda elt: elt.name == 'pipe', si_el.elements())
|
||||
feature_elts = self.host.plugins["XEP-0020"].getFeatureElt(si_el)
|
||||
|
||||
|
|
@ -94,7 +90,7 @@ class Exp_Pipe(object):
|
|||
|
||||
if feature_elts:
|
||||
feature_el = feature_elts[0]
|
||||
form = data_form.Form.fromElement(feature_el.firstChildElement())
|
||||
data_form.Form.fromElement(feature_el.firstChildElement())
|
||||
try:
|
||||
stream_method = self.host.plugins["XEP-0020"].negociate(feature_el, 'stream-method', self.managed_stream_m)
|
||||
except KeyError:
|
||||
|
|
@ -122,8 +118,6 @@ class Exp_Pipe(object):
|
|||
@param accepted: True if file transfer is accepted
|
||||
@param frontend_data: data sent by frontend"""
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
raise ProfileNotInCacheError
|
||||
data, timeout, stream_method, failed_methods, profile = client._pipe_waiting_for_approval[sid]
|
||||
if accepted:
|
||||
if timeout.active():
|
||||
|
|
@ -159,8 +153,6 @@ class Exp_Pipe(object):
|
|||
"""Called by the stream method when transfer successfuly finished
|
||||
@param id: stream id"""
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
raise ProfileNotInCacheError
|
||||
file_obj.close()
|
||||
info(_('Transfer %s successfuly finished') % sid)
|
||||
del(client._pipe_waiting_for_approval[sid])
|
||||
|
|
@ -170,12 +162,10 @@ class Exp_Pipe(object):
|
|||
@param id: stream id
|
||||
@param reason: can be TIMEOUT, IO_ERROR, PROTOCOL_ERROR"""
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
raise ProfileNotInCacheError
|
||||
data, timeout, stream_method, failed_methods, profile = client._pipe_waiting_for_approval[sid]
|
||||
warning(_('Transfer %(id)s failed with stream method %(s_method)s') % {'id': sid,
|
||||
's_method': stream_method})
|
||||
filepath = file_obj.name
|
||||
# filepath = file_obj.name
|
||||
file_obj.close()
|
||||
#TODO: session remenber (within a time limit) when a stream method fail, and avoid that stream method with full jid for the rest of the session
|
||||
warning(_("All stream methods failed, can't transfer the file"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue