comparison src/core/xmpp.py @ 1551:591c32dbfb0b

core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
author Goffi <goffi@goffi.org>
date Mon, 02 Nov 2015 22:02:41 +0100
parents 7d7e57a84792
children 001b62bed67c
comparison
equal deleted inserted replaced
1550:465d4d484e7c 1551:591c32dbfb0b
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from twisted.internet import task, defer 22 from twisted.internet import task, defer
23 from twisted.words.protocols.jabber import jid, xmlstream 23 from twisted.words.protocols.jabber import jid, xmlstream
24 from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel 24 from wokkel import client, disco, xmppim, generic, delay, iwokkel
25 from sat.core.log import getLogger 25 from sat.core.log import getLogger
26 log = getLogger(__name__) 26 log = getLogger(__name__)
27 from sat.core import exceptions 27 from sat.core import exceptions
28 from calendar import timegm 28 from calendar import timegm
29 from zope.interface import implements 29 from zope.interface import implements
49 self._progress_cb = {} # callback called when a progress is requested (key = progress id) 49 self._progress_cb = {} # callback called when a progress is requested (key = progress id)
50 50
51 def getConnectionDeferred(self): 51 def getConnectionDeferred(self):
52 """Return a deferred which fire when the client is connected""" 52 """Return a deferred which fire when the client is connected"""
53 return self.conn_deferred 53 return self.conn_deferred
54
55 def IQ(self, type_=u'set', timeout=None):
56 """shortcut to create an IQ element managing deferred
57
58 @param type_(unicode): IQ type ('set' or 'get')
59 @param timeout(None, int): timeout in seconds
60 """
61 iq_elt = xmlstream.IQ(self.xmlstream, type_)
62 iq_elt.timeout = timeout
63 return iq_elt
54 64
55 def _authd(self, xmlstream): 65 def _authd(self, xmlstream):
56 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): 66 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):
57 return 67 return
58 client.XMPPClient._authd(self, xmlstream) 68 client.XMPPClient._authd(self, xmlstream)
483 def connectionMade(self): 493 def connectionMade(self):
484 log.debug(_(u"Connection made with %s" % self.jabber_host)) 494 log.debug(_(u"Connection made with %s" % self.jabber_host))
485 self.xmlstream.namespace = "jabber:client" 495 self.xmlstream.namespace = "jabber:client"
486 self.xmlstream.sendHeader() 496 self.xmlstream.sendHeader()
487 497
488 iq = compat.IQ(self.xmlstream, 'set') 498 iq = xmlstream.IQ(self.xmlstream, 'set')
489 iq["to"] = self.jabber_host 499 iq["to"] = self.jabber_host
490 query = iq.addElement(('jabber:iq:register', 'query')) 500 query = iq.addElement(('jabber:iq:register', 'query'))
491 _user = query.addElement('username') 501 _user = query.addElement('username')
492 _user.addContent(self.user_login) 502 _user.addContent(self.user_login)
493 _pass = query.addElement('password') 503 _pass = query.addElement('password')