comparison src/plugins/plugin_xep_0050.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 e1842ebcb2f3
comparison
equal deleted inserted replaced
940:92e41e7c7e00 941:c6d8fc63b1db
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from logging import debug, info, warning, error 22 from logging import debug, info, warning, error
23 from twisted.words.protocols.jabber import jid 23 from twisted.words.protocols.jabber import jid
24 from twisted.words.protocols.jabber import error as xmpp_error 24 from twisted.words.protocols.jabber import error as xmpp_error
25 from twisted.words.xish import domish 25 from twisted.words.xish import domish
26 from twisted.internet import defer, reactor 26 from twisted.internet import defer
27 from wokkel import disco, iwokkel, data_form, compat 27 from wokkel import disco, iwokkel, data_form, compat
28 from sat.core import exceptions 28 from sat.core import exceptions
29 from sat.memory.memory import Sessions 29 from sat.memory.memory import Sessions
30 from uuid import uuid4 30 from uuid import uuid4
31 from sat.tools import xml_tools 31 from sat.tools import xml_tools
110 if requestor.userhostJID() in allowed: 110 if requestor.userhostJID() in allowed:
111 return True 111 return True
112 return False 112 return False
113 113
114 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 114 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
115 identities = [ID_CMD_LIST if self.node == NS_COMMANDS else ID_CMD_NODE] 115 # identities = [ID_CMD_LIST if self.node == NS_COMMANDS else ID_CMD_NODE] # FIXME
116 return [disco.DiscoFeature(NS_COMMANDS)] + self.features 116 return [disco.DiscoFeature(NS_COMMANDS)] + self.features
117 117
118 def getDiscoItems(self, requestor, target, nodeIdentifier=''): 118 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
119 return [] 119 return []
120 120
301 except KeyError: 301 except KeyError:
302 # it's the first time we know the node, we save it in session data 302 # it's the first time we know the node, we save it in session data
303 node = session_data['node'] = data[xml_tools.SAT_FORM_PREFIX+'node'] 303 node = session_data['node'] = data[xml_tools.SAT_FORM_PREFIX+'node']
304 304
305 client = self.host.getClient(profile) 305 client = self.host.getClient(profile)
306 if not client:
307 raise exceptions.ProfileUnknownError
308 306
309 # we request execute node's command 307 # we request execute node's command
310 iq_elt = compat.IQ(client.xmlstream, 'set') 308 iq_elt = compat.IQ(client.xmlstream, 'set')
311 iq_elt['to'] = entity.full() 309 iq_elt['to'] = entity.full()
312 command_elt = iq_elt.addElement("command", NS_COMMANDS) 310 command_elt = iq_elt.addElement("command", NS_COMMANDS)
358 # we should have the answer here 356 # we should have the answer here
359 try: 357 try:
360 x_elt = command_elt.elements(data_form.NS_X_DATA,'x').next() 358 x_elt = command_elt.elements(data_form.NS_X_DATA,'x').next()
361 answer_form = data_form.Form.fromElement(x_elt) 359 answer_form = data_form.Form.fromElement(x_elt)
362 show = answer_form['show'] 360 show = answer_form['show']
363 except KeyError, StopIteration: 361 except (KeyError, StopIteration):
364 raise AdHocError(XEP_0050.ERROR.BAD_PAYLOAD) 362 raise AdHocError(XEP_0050.ERROR.BAD_PAYLOAD)
365 if show not in SHOWS: 363 if show not in SHOWS:
366 raise AdHocError(XEP_0050.ERROR.BAD_PAYLOAD) 364 raise AdHocError(XEP_0050.ERROR.BAD_PAYLOAD)
367 if show == "disconnect": 365 if show == "disconnect":
368 self.host.disconnect(profile) 366 self.host.disconnect(profile)