summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-10-31 13:42:32 -0700
committerLance Stout <lancestout@gmail.com>2012-10-31 13:42:32 -0700
commit4b7ec4a32ac15dfa35b3282793a8317cfd32837b (patch)
tree626c0287a09b81ed5415de95f9adeb24ad42293a /sleekxmpp/stanza
parenta00eee1bbee83b2435b09be6c4175c3649fa797b (diff)
parent2229ad8d8e51b73a7900b118dfab5d7b449f17ce (diff)
downloadslixmpp-4b7ec4a32ac15dfa35b3282793a8317cfd32837b.tar.gz
slixmpp-4b7ec4a32ac15dfa35b3282793a8317cfd32837b.tar.bz2
slixmpp-4b7ec4a32ac15dfa35b3282793a8317cfd32837b.tar.xz
slixmpp-4b7ec4a32ac15dfa35b3282793a8317cfd32837b.zip
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp/stanza')
-rw-r--r--sleekxmpp/stanza/iq.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py
index f45b3c67..71c0444d 100644
--- a/sleekxmpp/stanza/iq.py
+++ b/sleekxmpp/stanza/iq.py
@@ -154,7 +154,7 @@ class Iq(RootStanza):
StanzaBase.reply(self, clear)
return self
- def send(self, block=True, timeout=None, callback=None, now=False):
+ def send(self, block=True, timeout=None, callback=None, now=False, timeout_callback=None):
"""
Send an <iq> stanza over the XML stream.
@@ -181,15 +181,32 @@ class Iq(RootStanza):
now -- Indicates if the send queue should be skipped and send
the stanza immediately. Used during stream
initialization. Defaults to False.
+ timeout_callback -- Optional reference to a stream handler function.
+ Will be executed when the timeout expires before a
+ response has been received with the originally-sent IQ
+ stanza. Only called if there is a callback parameter
+ (and therefore are in async mode).
"""
if timeout is None:
timeout = self.stream.response_timeout
if callback is not None and self['type'] in ('get', 'set'):
handler_name = 'IqCallback_%s' % self['id']
- handler = Callback(handler_name,
- MatcherId(self['id']),
- callback,
- once=True)
+ if timeout_callback:
+ self.callback = callback
+ self.timeout_callback = timeout_callback
+ self.stream.schedule('IqTimeout_%s' % self['id'],
+ timeout,
+ self._fire_timeout,
+ repeat=False)
+ handler = Callback(handler_name,
+ MatcherId(self['id']),
+ self._handle_result,
+ once=True)
+ else:
+ handler = Callback(handler_name,
+ MatcherId(self['id']),
+ callback,
+ once=True)
self.stream.register_handler(handler)
StanzaBase.send(self, now=now)
return handler_name
@@ -206,6 +223,16 @@ class Iq(RootStanza):
else:
return StanzaBase.send(self, now=now)
+ def _handle_result(self, iq):
+ # we got the IQ, so don't fire the timeout
+ self.stream.scheduler.remove('IqTimeout_%s' % self['id'])
+ self.callback(iq)
+
+ def _fire_timeout(self):
+ # don't fire the handler for the IQ, if it finally does come in
+ self.stream.remove_handler('IqCallback_%s' % self['id'])
+ self.timeout_callback(self)
+
def _set_stanza_values(self, values):
"""
Set multiple stanza interface values using a dictionary.