Mercurial > libervia-backend
changeset 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 (2015-11-02) |
parents | 465d4d484e7c |
children | e0bde0d0b321 |
files | src/core/xmpp.py |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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')