# HG changeset patch # User Goffi # Date 1446498161 -3600 # Node ID 591c32dbfb0bd6af0ab39058dafad5222d952b1e # Parent 465d4d484e7c1518f8686dacda23a083ac0e5598 core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred. diff -r 465d4d484e7c -r 591c32dbfb0b src/core/xmpp.py --- a/src/core/xmpp.py Mon Nov 02 22:02:41 2015 +0100 +++ b/src/core/xmpp.py Mon Nov 02 22:02:41 2015 +0100 @@ -21,7 +21,7 @@ from sat.core.constants import Const as C from twisted.internet import task, defer from twisted.words.protocols.jabber import jid, xmlstream -from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel +from wokkel import client, disco, xmppim, generic, delay, iwokkel from sat.core.log import getLogger log = getLogger(__name__) from sat.core import exceptions @@ -52,6 +52,16 @@ """Return a deferred which fire when the client is connected""" return self.conn_deferred + def IQ(self, type_=u'set', timeout=None): + """shortcut to create an IQ element managing deferred + + @param type_(unicode): IQ type ('set' or 'get') + @param timeout(None, int): timeout in seconds + """ + iq_elt = xmlstream.IQ(self.xmlstream, type_) + iq_elt.timeout = timeout + return iq_elt + def _authd(self, xmlstream): if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): return @@ -485,7 +495,7 @@ self.xmlstream.namespace = "jabber:client" self.xmlstream.sendHeader() - iq = compat.IQ(self.xmlstream, 'set') + iq = xmlstream.IQ(self.xmlstream, 'set') iq["to"] = self.jabber_host query = iq.addElement(('jabber:iq:register', 'query')) _user = query.addElement('username')