From 083f426b247b4095732d80229f4ca362ff3c92bb Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 2 Nov 2015 22:02:41 +0100 Subject: [PATCH] core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred. --- src/core/xmpp.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/xmpp.py b/src/core/xmpp.py index b563fbcb..604f9fb2 100644 --- a/src/core/xmpp.py +++ b/src/core/xmpp.py @@ -21,7 +21,7 @@ from sat.core.i18n import _ 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 @@ class SatXMPPClient(client.XMPPClient): """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 @@ class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): 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')