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:
Goffi 2014-03-28 18:07:02 +01:00
commit a6897c76e0

View file

@ -256,7 +256,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
# 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 @@ class SOCKSv5(protocol.Protocol, FileSender):
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 @@ class SOCKSv5(protocol.Protocol, FileSender):
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 @@ class XEP_0065(object):
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 @@ class XEP_0065(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_0065_current_stream[sid]["file_obj"]
data["position"] = str(file_obj.tell())
@ -513,9 +507,6 @@ class XEP_0065(object):
@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 @@ class XEP_0065(object):
@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 @@ class XEP_0065(object):
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 @@ class XEP_0065(object):
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 @@ class XEP_0065(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_0065_current_stream[sid] = {}
data["from"] = from_jid
data["file_obj"] = file_obj
@ -731,8 +713,6 @@ class XEP_0065(object):
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 @@ class XEP_0065_handler(XMPPHandler):
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 @@ class XEP_0065_handler(XMPPHandler):
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()