From ab03ad54aaca1725b943abf16585fa4ef6f08897 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 30 Jul 2014 17:52:59 +0200 Subject: Fix the iq.send() function, and a bunch of places where it is called This is a big-and-dirty commit with a bunch of cleanup, maybe breaking a few things, and not fixing all iq.send() calls yet. --- slixmpp/plugins/xep_0013/offline.py | 66 ++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 38 deletions(-) (limited to 'slixmpp/plugins/xep_0013') diff --git a/slixmpp/plugins/xep_0013/offline.py b/slixmpp/plugins/xep_0013/offline.py index d6b500d3..51840e7b 100644 --- a/slixmpp/plugins/xep_0013/offline.py +++ b/slixmpp/plugins/xep_0013/offline.py @@ -48,7 +48,8 @@ class XEP_0013(BasePlugin): local=False, **kwargs) - def view(self, nodes, ifrom=None, block=True, timeout=None, callback=None): + def view(self, nodes, ifrom=None, timeout=None, callback=None, + timeout_callback=None): if not isinstance(nodes, (list, set)): nodes = [nodes] @@ -67,23 +68,16 @@ class XEP_0013(BasePlugin): StanzaPath('message/offline')) self.xmpp.register_handler(collector) - if not block and callback is not None: - def wrapped_cb(iq): - results = collector.stop() - if iq['type'] == 'result': - iq['offline']['results'] = results - callback(iq) - return iq.send(block=block, timeout=timeout, callback=wrapped_cb) - else: - try: - resp = iq.send(block=block, timeout=timeout, callback=callback) - resp['offline']['results'] = collector.stop() - return resp - except XMPPError as e: - collector.stop() - raise e - - def remove(self, nodes, ifrom=None, block=True, timeout=None, callback=None): + def wrapped_cb(iq): + results = collector.stop() + if iq['type'] == 'result': + iq['offline']['results'] = results + callback(iq) + iq.send(timeout=timeout, callback=wrapped_cb, + timeout_callback=timeout_callback) + + def remove(self, nodes, ifrom=None, timeout=None, callback=None, + timeout_callback=None): if not isinstance(nodes, (list, set)): nodes = [nodes] @@ -97,9 +91,11 @@ class XEP_0013(BasePlugin): item['action'] = 'remove' offline.append(item) - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def fetch(self, ifrom=None, block=True, timeout=None, callback=None): + def fetch(self, ifrom=None, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom @@ -110,25 +106,19 @@ class XEP_0013(BasePlugin): StanzaPath('message/offline')) self.xmpp.register_handler(collector) - if not block and callback is not None: - def wrapped_cb(iq): - results = collector.stop() - if iq['type'] == 'result': - iq['offline']['results'] = results - callback(iq) - return iq.send(block=block, timeout=timeout, callback=wrapped_cb) - else: - try: - resp = iq.send(block=block, timeout=timeout, callback=callback) - resp['offline']['results'] = collector.stop() - return resp - except XMPPError as e: - collector.stop() - raise e - - def purge(self, ifrom=None, block=True, timeout=None, callback=None): + def wrapped_cb(iq): + results = collector.stop() + if iq['type'] == 'result': + iq['offline']['results'] = results + callback(iq) + iq.send(timeout=timeout, callback=wrapped_cb, + timeout_callback=timeout_callback) + + def purge(self, ifrom=None, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom iq['offline']['purge'] = True - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) -- cgit v1.2.3