summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza/iq.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-12-13 14:36:53 -0500
committerLance Stout <lancestout@gmail.com>2010-12-13 14:36:53 -0500
commitc16913c99929a6a5a57611ec8a1757e3e82d4a45 (patch)
treed92b98975b3dc012c734997e6fddc0ac9e2b82d8 /sleekxmpp/stanza/iq.py
parent12b61365adbbc910841475ea3cf8204f26ccd9c7 (diff)
parentf4451fe6b72f7cfb9680ead7a608d5ca1bc7e753 (diff)
downloadslixmpp-c16913c99929a6a5a57611ec8a1757e3e82d4a45.tar.gz
slixmpp-c16913c99929a6a5a57611ec8a1757e3e82d4a45.tar.bz2
slixmpp-c16913c99929a6a5a57611ec8a1757e3e82d4a45.tar.xz
slixmpp-c16913c99929a6a5a57611ec8a1757e3e82d4a45.zip
Merge branch 'develop' into roster
Conflicts: sleekxmpp/basexmpp.py
Diffstat (limited to 'sleekxmpp/stanza/iq.py')
-rw-r--r--sleekxmpp/stanza/iq.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py
index 150baa00..906e6648 100644
--- a/sleekxmpp/stanza/iq.py
+++ b/sleekxmpp/stanza/iq.py
@@ -9,7 +9,7 @@
from sleekxmpp.stanza import Error
from sleekxmpp.stanza.rootstanza import RootStanza
from sleekxmpp.xmlstream import StanzaBase, ET
-from sleekxmpp.xmlstream.handler import Waiter
+from sleekxmpp.xmlstream.handler import Waiter, Callback
from sleekxmpp.xmlstream.matcher import MatcherId
@@ -157,28 +157,44 @@ class Iq(RootStanza):
StanzaBase.reply(self)
return self
- def send(self, block=True, timeout=None):
+ def send(self, block=True, timeout=None, callback=None):
"""
Send an <iq> stanza over the XML stream.
The send call can optionally block until a response is received or
a timeout occurs. Be aware that using blocking in non-threaded event
- handlers can drastically impact performance.
+ handlers can drastically impact performance. Otherwise, a callback
+ handler can be provided that will be executed when the Iq stanza's
+ result reply is received. Be aware though that that the callback
+ handler will not be executed in its own thread.
+
+ Using both block and callback is not recommended, and only the
+ callback argument will be used in that case.
Overrides StanzaBase.send
Arguments:
- block -- Specify if the send call will block until a response
- is received, or a timeout occurs. Defaults to True.
- timeout -- The length of time (in seconds) to wait for a response
- before exiting the send call if blocking is used.
- Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
+ block -- Specify if the send call will block until a response
+ is received, or a timeout occurs. Defaults to True.
+ timeout -- The length of time (in seconds) to wait for a response
+ before exiting the send call if blocking is used.
+ Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
+ callback -- Optional reference to a stream handler function. Will
+ be executed when a reply stanza is received.
"""
if timeout is None:
timeout = self.stream.response_timeout
- if block and self['type'] in ('get', 'set'):
+ if callback is not None and self['type'] in ('get', 'set'):
+ handler = Callback('IqCallback_%s' % self['id'],
+ MatcherId(self['id']),
+ callback,
+ once=True)
+ self.stream.register_handler(handler)
+ StanzaBase.send(self)
+ return None
+ elif block and self['type'] in ('get', 'set'):
waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id']))
- self.stream.registerHandler(waitfor)
+ self.stream.register_handler(waitfor)
StanzaBase.send(self)
return waitfor.wait(timeout)
else: