comparison src/plugins/plugin_xep_0100.py @ 941:c6d8fc63b1db

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
author Goffi <goffi@goffi.org>
date Fri, 28 Mar 2014 18:07:02 +0100
parents 1a759096ccbd
children 301b342c697a
comparison
equal deleted inserted replaced
940:92e41e7c7e00 941:c6d8fc63b1db
20 from sat.core.i18n import _, D_ 20 from sat.core.i18n import _, D_
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from sat.core import exceptions 22 from sat.core import exceptions
23 from sat.tools import xml_tools 23 from sat.tools import xml_tools
24 from logging import debug, info, warning, error 24 from logging import debug, info, warning, error
25 from twisted.words.protocols.jabber import client as jabber_client, jid 25 from twisted.words.protocols.jabber import jid
26 from twisted.words.protocols.jabber import error as jab_error
27 from twisted.internet import reactor, defer 26 from twisted.internet import reactor, defer
28 27
29 PLUGIN_INFO = { 28 PLUGIN_INFO = {
30 "name": "Gateways Plugin", 29 "name": "Gateways Plugin",
31 "import_name": "XEP-0100", 30 "import_name": "XEP-0100",
159 if isinstance(result.value, defer.CancelledError): 158 if isinstance(result.value, defer.CancelledError):
160 msg = _("Timeout") 159 msg = _("Timeout")
161 else: 160 else:
162 try: 161 try:
163 msg = result.value.condition 162 msg = result.value.condition
164 except AttibuteError: 163 except AttributeError:
165 msg = str(result) 164 msg = str(result)
166 ret.append((success, (msg, items[idx]))) 165 ret.append((success, (msg, items[idx])))
167 else: 166 else:
168 entity = items[idx].entity 167 entity = items[idx].entity
169 gateways = [(identity, result.identities[identity]) for identity in result.identities if identity[0] == 'gateway'] 168 gateways = [(identity, result.identities[identity]) for identity in result.identities if identity[0] == 'gateway']
204 203
205 def findGateways(self, target, profile): 204 def findGateways(self, target, profile):
206 """Find gateways in the target JID, using discovery protocol 205 """Find gateways in the target JID, using discovery protocol
207 """ 206 """
208 client = self.host.getClient(profile) 207 client = self.host.getClient(profile)
209 assert(client)
210 debug(_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target': target.full(), 'profile': profile}) 208 debug(_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target': target.full(), 'profile': profile})
211 d = client.disco.requestItems(target) 209 d = client.disco.requestItems(target)
212 d.addCallback(self._itemsReceived , target=target, client=client) 210 d.addCallback(self._itemsReceived , target=target, client=client)
213 return d 211 return d