# HG changeset patch # User Goffi # Date 1396026422 -3600 # Node ID c6d8fc63b1dbd74b2f3eac84bc4d6036c3449e20 # Parent 92e41e7c7e00d50f145fa357b194c4b566231f37 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 diff -r 92e41e7c7e00 -r c6d8fc63b1db src/core/sat_main.py --- a/src/core/sat_main.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/core/sat_main.py Fri Mar 28 18:07:02 2014 +0100 @@ -26,7 +26,6 @@ from twisted.internet import reactor -from wokkel import compat from wokkel.xmppim import RosterItem from sat.bridge.DBus import DBusBridge @@ -40,7 +39,6 @@ from sat.core import exceptions from sat.core.constants import Const as C from sat.memory.memory import Memory -from sat.tools.xml_tools import tupleList2dataForm from sat.tools.misc import TriggerManager from glob import glob from uuid import uuid4 @@ -295,8 +293,6 @@ def getContacts(self, profile_key): client = self.getClient(profile_key) - if not client: - raise exceptions.ProfileUnknownError(_('Asking contacts for a non-existant profile')) ret = [] for item in client.roster.getItems(): # we get all items for client's roster # and convert them to expected format @@ -306,9 +302,7 @@ def getContactsFromGroup(self, group, profile_key): client = self.getClient(profile_key) - if not client: - raise exceptions.ProfileUnknownError(_("Asking group's contacts for a non-existant profile")) - return [jid.full() for jid in client.roster.getJidsFromGroup(group)] + return [jid_.full() for jid_ in client.roster.getJidsFromGroup(group)] def purgeClient(self, profile): """Remove reference to a profile client and purge cache @@ -350,7 +344,7 @@ @return: client or None if it doesn't exist""" profile = self.memory.getProfileName(profile_key) if not profile: - return None + raise exceptions.ProfileKeyUnknownError return self.profiles[profile] def getClients(self, profile_key): @@ -443,8 +437,6 @@ def getWaitingConf(self, profile_key=None): assert(profile_key) client = self.getClient(profile_key) - if not client: - raise exceptions.ProfileNotInCacheError ret = [] for conf_id in client._waiting_conf: conf_type, data = client._waiting_conf[conf_id][:2] @@ -769,8 +761,6 @@ """ # FIXME: use XMLUI and *callback methods for dialog client = self.getClient(profile) - if not client: - raise exceptions.ProfileUnknownError(_("Asking confirmation a non-existant profile")) if conf_id in client._waiting_conf: error(_("Attempt to register two callbacks for the same confirmation")) else: @@ -780,8 +770,6 @@ def confirmationAnswer(self, conf_id, accepted, data, profile): """Called by frontends to answer confirmation requests""" client = self.getClient(profile) - if not client: - raise exceptions.ProfileUnknownError(_("Confirmation answer from a non-existant profile")) debug(_("Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")}) if conf_id not in client._waiting_conf: error(_("Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile}) @@ -793,15 +781,11 @@ def registerProgressCB(self, progress_id, CB, profile): """Register a callback called when progress is requested for id""" client = self.getClient(profile) - if not client: - raise exceptions.ProfileUnknownError client._progress_cb_map[progress_id] = CB def removeProgressCB(self, progress_id, profile): """Remove a progress callback""" client = self.getClient(profile) - if not client: - raise exceptions.ProfileUnknownError if progress_id not in client._progress_cb_map: error(_("Trying to remove an unknow progress callback")) else: @@ -813,8 +797,6 @@ data['size'] : end_position """ client = self.getClient(profile) - if not profile: - raise exceptions.ProfileNotInCacheError data = {} try: client._progress_cb_map[progress_id](progress_id, data, profile) diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_exp_pipe.py --- a/src/plugins/plugin_exp_pipe.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_exp_pipe.py Fri Mar 28 18:07:02 2014 +0100 @@ -23,9 +23,7 @@ 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 @@ 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 @@ 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 @@ @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 @@ """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 @@ @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")) diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_misc_groupblog.py --- a/src/plugins/plugin_misc_groupblog.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_misc_groupblog.py Fri Mar 28 18:07:02 2014 +0100 @@ -154,9 +154,6 @@ raise exceptions.ProfileUnknownError client = self.host.getClient(profile) - if not client: - error(_('No client for this profile key: %s') % profile_key) - raise Exception("Unknown profile") yield client.client_initialized # we want to be sure that the client is initialized #we first check that we have a item-access pubsub server @@ -309,7 +306,7 @@ # FIXME: check comments node creation success, at the moment this is a potential security risk (if the node # already exists, the creation will silently fail, but the comments link will stay the same, linking to a # node owned by somebody else) - defer_blog = self.host.plugins["XEP-0060"].createNode(service, comments_node, _options, profile_key=client.profile) + self.host.plugins["XEP-0060"].createNode(service, comments_node, _options, profile_key=client.profile) def itemCreated(mblog_item): form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG) diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_misc_radiocol.py --- a/src/plugins/plugin_misc_radiocol.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_misc_radiocol.py Fri Mar 28 18:07:02 2014 +0100 @@ -99,9 +99,6 @@ # be streamed to the backend using XMPP file copy # Here we cheat because we know we are on the same host, and we don't # check data. Referee will have to parse the song himself to check it - client = self.host.getClient(profile) - if not client: - raise exceptions.NotConnectedProfileError(_("Can't access profile's data")) try: if song_path.lower().endswith('.mp3'): actual_song = MP3(song_path) diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_misc_room_game.py --- a/src/plugins/plugin_misc_room_game.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_misc_room_game.py Fri Mar 28 18:07:02 2014 +0100 @@ -427,9 +427,6 @@ d.addCallback(roomJoined) client = self.host.getClient(profile) - if not client: - error(_('No client for this profile key: %s') % profile_key) - return client.client_initialized.addCallback(lambda ignore: afterClientInit(room_jid_s)) def userJoinedTrigger(self, room, user, profile): diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0047.py --- 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() diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0050.py --- a/src/plugins/plugin_xep_0050.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0050.py Fri Mar 28 18:07:02 2014 +0100 @@ -23,7 +23,7 @@ from twisted.words.protocols.jabber import jid from twisted.words.protocols.jabber import error as xmpp_error from twisted.words.xish import domish -from twisted.internet import defer, reactor +from twisted.internet import defer from wokkel import disco, iwokkel, data_form, compat from sat.core import exceptions from sat.memory.memory import Sessions @@ -112,7 +112,7 @@ return False def getDiscoInfo(self, requestor, target, nodeIdentifier=''): - identities = [ID_CMD_LIST if self.node == NS_COMMANDS else ID_CMD_NODE] + # identities = [ID_CMD_LIST if self.node == NS_COMMANDS else ID_CMD_NODE] # FIXME return [disco.DiscoFeature(NS_COMMANDS)] + self.features def getDiscoItems(self, requestor, target, nodeIdentifier=''): @@ -303,8 +303,6 @@ node = session_data['node'] = data[xml_tools.SAT_FORM_PREFIX+'node'] client = self.host.getClient(profile) - if not client: - raise exceptions.ProfileUnknownError # we request execute node's command iq_elt = compat.IQ(client.xmlstream, 'set') @@ -360,7 +358,7 @@ x_elt = command_elt.elements(data_form.NS_X_DATA,'x').next() answer_form = data_form.Form.fromElement(x_elt) show = answer_form['show'] - except KeyError, StopIteration: + except (KeyError, StopIteration): raise AdHocError(XEP_0050.ERROR.BAD_PAYLOAD) if show not in SHOWS: raise AdHocError(XEP_0050.ERROR.BAD_PAYLOAD) diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0054.py --- a/src/plugins/plugin_xep_0054.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0054.py Fri Mar 28 18:07:02 2014 +0100 @@ -259,8 +259,6 @@ #TODO: This is a temporary way of setting avatar, as other VCard informations are not managed. # A proper full VCard management should be done (and more generaly a public/private profile) client = self.host.getClient(profile_key) - if not client: - raise exceptions.NotConnectedProfileError(_('Trying to set avatar for a non-existant or not connected profile')) vcard_set = IQ(client.xmlstream, 'set') d = threads.deferToThread(self._buildSetAvatar, vcard_set, filepath) diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0065.py --- a/src/plugins/plugin_xep_0065.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0065.py Fri Mar 28 18:07:02 2014 +0100 @@ -256,7 +256,7 @@ # 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ @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 @@ @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 @@ 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 @@ 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 @@ @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 @@ 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 @@ 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 @@ 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() diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0077.py --- a/src/plugins/plugin_xep_0077.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0077.py Fri Mar 28 18:07:02 2014 +0100 @@ -24,7 +24,6 @@ from twisted.words.protocols.jabber import jid from twisted.words.protocols.jabber.xmlstream import IQ from sat.tools import xml_tools -from sat.memory import memory from wokkel import data_form, compat @@ -105,8 +104,6 @@ def inBandRegister(self, to_jid, post_treat_cb=None, profile_key=C.PROF_KEY_NONE): """register to a target JID""" client = self.host.getClient(profile_key) - if not client: - raise exceptions.ProfileUnknownError debug(_("Asking registration for [%s]") % to_jid.full()) reg_request = IQ(client.xmlstream, 'get') reg_request["from"] = client.jid.full() diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0092.py --- a/src/plugins/plugin_xep_0092.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0092.py Fri Mar 28 18:07:02 2014 +0100 @@ -58,8 +58,6 @@ - os: operating system of the queried entity """ client = self.host.getClient(profile_key) - if not client: - raise exceptions.ProfileUnknownError iq_elt = compat.IQ(client.xmlstream, 'get') iq_elt['to'] = jid_.full() query_elt = iq_elt.addElement("query", NS_VERSION) diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0095.py --- a/src/plugins/plugin_xep_0095.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0095.py Fri Mar 28 18:07:02 2014 +0100 @@ -21,11 +21,7 @@ from sat.core.constants import Const as C from logging import debug, info, error from twisted.words.xish import domish -from twisted.internet import protocol -from twisted.words.protocols.jabber import client, jid -from twisted.words.protocols.jabber import error as jab_error -import os.path -from twisted.internet import reactor +from twisted.words.protocols.jabber import client import uuid from zope.interface import implements @@ -125,8 +121,7 @@ @param data: error specific data (dictionary) @param profile: %(doc_profile)s """ - _client = self.host.getClient(profile) - assert(_client) + client_ = self.host.getClient(profile) result = domish.Element((None, 'iq')) result['type'] = 'result' result['id'] = iq_id @@ -149,7 +144,7 @@ if 'custom' in data and data['custom'] == 'failed': condition_el.addContent('Stream failed') - _client.xmlstream.send(result) + client_.xmlstream.send(result) def acceptStream(self, iq_id, to_jid, feature_elt, misc_elts=[], profile=C.PROF_KEY_NONE): """Send the accept stream initiation answer diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0096.py --- a/src/plugins/plugin_xep_0096.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0096.py Fri Mar 28 18:07:02 2014 +0100 @@ -25,7 +25,6 @@ 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 @@ -81,8 +80,6 @@ info(_("XEP-0096 file transfer requested")) debug(si_el.toXml()) client = self.host.getClient(profile) - if not client: - raise ProfileNotInCacheError filename = "" file_size = "" file_date = None @@ -111,7 +108,7 @@ 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: @@ -146,8 +143,6 @@ @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 = client._xep_0096_waiting_for_approval[sid] can_range = data['can_range'] == "True" range_offset = 0 @@ -192,8 +187,6 @@ """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._xep_0096_waiting_for_approval[sid]) @@ -203,8 +196,6 @@ @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 = client._xep_0096_waiting_for_approval[sid] warning(_('Transfer %(id)s failed with stream method %(s_method)s: %(reason)s') % { 'id': sid, diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0100.py --- a/src/plugins/plugin_xep_0100.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0100.py Fri Mar 28 18:07:02 2014 +0100 @@ -22,8 +22,7 @@ from sat.core import exceptions from sat.tools import xml_tools from logging import debug, info, warning, error -from twisted.words.protocols.jabber import client as jabber_client, jid -from twisted.words.protocols.jabber import error as jab_error +from twisted.words.protocols.jabber import jid from twisted.internet import reactor, defer PLUGIN_INFO = { @@ -161,7 +160,7 @@ else: try: msg = result.value.condition - except AttibuteError: + except AttributeError: msg = str(result) ret.append((success, (msg, items[idx]))) else: @@ -206,7 +205,6 @@ """Find gateways in the target JID, using discovery protocol """ client = self.host.getClient(profile) - assert(client) debug(_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target': target.full(), 'profile': profile}) d = client.disco.requestItems(target) d.addCallback(self._itemsReceived , target=target, client=client) diff -r 92e41e7c7e00 -r c6d8fc63b1db src/plugins/plugin_xep_0115.py --- a/src/plugins/plugin_xep_0115.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/plugins/plugin_xep_0115.py Fri Mar 28 18:07:02 2014 +0100 @@ -21,11 +21,8 @@ from sat.core.constants import Const as C from logging import debug, info, error, warning from twisted.words.xish import domish -from twisted.words.protocols.jabber import client, jid, xmlstream -from twisted.words.protocols.jabber import error as jab_error -from twisted.words.protocols.jabber.xmlstream import IQ +from twisted.words.protocols.jabber import jid from sat.memory.persistent import PersistentBinaryDict -import os.path import types from zope.interface import implements @@ -126,9 +123,6 @@ raise HashGenerationError client = self.host.getClient(profile_key) - if not client: - error('Requesting hash for an inexistant client') - raise HashGenerationError def generateHash_2(services, profile): _s = [] @@ -149,7 +143,7 @@ debug(_('Capability hash generated: [%s]') % XEP_0115.cap_hash) self.presenceHack(profile) - services = client.discoHandler.info(client.jid, client.jid, '').addCallback(generateHash_2, profile) + client.discoHandler.info(client.jid, client.jid, '').addCallback(generateHash_2, profile) class XEP_0115_handler(XMPPHandler): diff -r 92e41e7c7e00 -r c6d8fc63b1db src/test/helpers.py --- a/src/test/helpers.py Fri Mar 28 18:06:51 2014 +0100 +++ b/src/test/helpers.py Fri Mar 28 18:07:02 2014 +0100 @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from sat.core.i18n import _ from sat.core import exceptions from constants import Const from wokkel.xmppim import RosterItem @@ -116,7 +115,7 @@ @return: client or None if it doesn't exist""" profile = self.memory.getProfileName(profile_key) if not profile: - return None + raise exceptions.ProfileKeyUnknownError if profile not in self.profiles: self.profiles[profile] = FakeClient(self, profile) self.profiles[profile].client_initialized.callback(None)