diff options
Diffstat (limited to 'sleekxmpp/stanza/iq.py')
-rw-r--r-- | sleekxmpp/stanza/iq.py | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py index 71c0444d..088de4c0 100644 --- a/sleekxmpp/stanza/iq.py +++ b/sleekxmpp/stanza/iq.py @@ -9,7 +9,7 @@ from sleekxmpp.stanza.rootstanza import RootStanza from sleekxmpp.xmlstream import StanzaBase, ET from sleekxmpp.xmlstream.handler import Waiter, Callback -from sleekxmpp.xmlstream.matcher import MatcherId +from sleekxmpp.xmlstream.matcher import MatchIDSender, MatcherId from sleekxmpp.exceptions import IqTimeout, IqError @@ -115,9 +115,13 @@ class Iq(RootStanza): """ query = self.xml.find("{%s}query" % value) if query is None and value: - self.clear() - query = ET.Element("{%s}query" % value) - self.xml.append(query) + plugin = self.plugin_tag_map.get('{%s}query' % value, None) + if plugin: + self.enable(plugin.plugin_attrib) + else: + self.clear() + query = ET.Element("{%s}query" % value) + self.xml.append(query) return self def get_query(self): @@ -182,36 +186,46 @@ class Iq(RootStanza): 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 + 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 self.stream.session_bind_event.is_set(): + matcher = MatchIDSender({ + 'id': self['id'], + 'self': self.stream.boundjid, + 'peer': self['to'] + }) + else: + matcher = MatcherId(self['id']) + if callback is not None and self['type'] in ('get', 'set'): handler_name = 'IqCallback_%s' % self['id'] if timeout_callback: self.callback = callback self.timeout_callback = timeout_callback - self.stream.schedule('IqTimeout_%s' % self['id'], - timeout, - self._fire_timeout, - repeat=False) + self.stream.schedule('IqTimeout_%s' % self['id'], + timeout, + self._fire_timeout, + repeat=False) handler = Callback(handler_name, - MatcherId(self['id']), + matcher, self._handle_result, once=True) else: handler = Callback(handler_name, - MatcherId(self['id']), + matcher, callback, once=True) self.stream.register_handler(handler) StanzaBase.send(self, now=now) return handler_name elif block and self['type'] in ('get', 'set'): - waitfor = Waiter('IqWait_%s' % self['id'], MatcherId(self['id'])) + waitfor = Waiter('IqWait_%s' % self['id'], matcher) self.stream.register_handler(waitfor) StanzaBase.send(self, now=now) result = waitfor.wait(timeout) |