core (client): add IQ method to easily create an IQ stanza with the current xmlstream, and manage result with a Deferred.
This commit is contained in:
parent
aca7307452
commit
083f426b24
1 changed files with 12 additions and 2 deletions
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue