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/clientxmpp.py | 37 +++----- slixmpp/features/feature_bind/bind.py | 2 +- slixmpp/features/feature_session/session.py | 2 +- slixmpp/plugins/xep_0012/last_activity.py | 9 +- slixmpp/plugins/xep_0013/offline.py | 66 ++++++-------- slixmpp/plugins/xep_0016/privacy.py | 55 ++++++++---- slixmpp/plugins/xep_0030/disco.py | 22 ++--- slixmpp/plugins/xep_0049/private_storage.py | 12 ++- slixmpp/plugins/xep_0050/adhoc.py | 51 +++-------- slixmpp/plugins/xep_0060/pubsub.py | 135 +++++++++++++--------------- slixmpp/plugins/xep_0077/register.py | 2 +- slixmpp/plugins/xep_0078/legacyauth.py | 4 +- slixmpp/plugins/xep_0107/user_mood.py | 34 +++---- slixmpp/plugins/xep_0108/user_activity.py | 34 +++---- slixmpp/plugins/xep_0115/caps.py | 17 +--- slixmpp/plugins/xep_0163.py | 18 ++-- slixmpp/plugins/xep_0172/user_nick.py | 31 +++---- slixmpp/plugins/xep_0196/user_gaming.py | 34 ++++--- slixmpp/plugins/xep_0199/ping.py | 11 ++- slixmpp/plugins/xep_0223.py | 34 +++---- slixmpp/stanza/iq.py | 58 ++++-------- slixmpp/xmlstream/stanzabase.py | 2 +- 22 files changed, 271 insertions(+), 399 deletions(-) diff --git a/slixmpp/clientxmpp.py b/slixmpp/clientxmpp.py index fa36ad56..add7f437 100644 --- a/slixmpp/clientxmpp.py +++ b/slixmpp/clientxmpp.py @@ -221,19 +221,11 @@ class ClientXMPP(BaseXMPP): """ return self.client_roster.remove(jid) - def get_roster(self, block=True, timeout=None, callback=None): + def get_roster(self, callback=None, timeout=None, timeout_callback=None): """Request the roster from the server. - :param block: Specify if the roster request will block until a - response is received, or a timeout occurs. - Defaults to ``True``. - :param timeout: The length of time (in seconds) to wait for a response - before continuing if blocking is used. - Defaults to - :attr:`~slixmpp.xmlstream.xmlstream.XMLStream.response_timeout`. - :param callback: Optional reference to a stream handler function. Will + :param callback: Reference to a stream handler function. Will be executed when the roster is received. - Implies ``block=False``. """ iq = self.Iq() iq['type'] = 'get' @@ -241,23 +233,16 @@ class ClientXMPP(BaseXMPP): if 'rosterver' in self.features: iq['roster']['ver'] = self.client_roster.version + if callback is None: + callback = lambda resp: self.event('roster_update', resp) + else: + orig_cb = callback + def wrapped(resp): + self.event('roster_update', resp) + orig_cb(resp) + callback = wrapped - if not block or callback is not None: - block = False - if callback is None: - callback = lambda resp: self.event('roster_update', resp) - else: - orig_cb = callback - def wrapped(resp): - self.event('roster_update', resp) - orig_cb(resp) - callback = wrapped - - response = iq.send(block, timeout, callback) - - if block: - self.event('roster_update', response) - return response + iq.send(callback, timeout, timeout_callback) def _reset_connection_state(self, event=None): #TODO: Use stream state here diff --git a/slixmpp/features/feature_bind/bind.py b/slixmpp/features/feature_bind/bind.py index d41bbc3f..25c99948 100644 --- a/slixmpp/features/feature_bind/bind.py +++ b/slixmpp/features/feature_bind/bind.py @@ -49,7 +49,7 @@ class FeatureBind(BasePlugin): if self.xmpp.requested_jid.resource: iq['bind']['resource'] = self.xmpp.requested_jid.resource - iq.send(block=False, callback=self._on_bind_response) + iq.send(callback=self._on_bind_response) def _on_bind_response(self, response): self.xmpp.boundjid = JID(response['bind']['jid'], cache_lock=True) diff --git a/slixmpp/features/feature_session/session.py b/slixmpp/features/feature_session/session.py index e57405db..0635455a 100644 --- a/slixmpp/features/feature_session/session.py +++ b/slixmpp/features/feature_session/session.py @@ -44,7 +44,7 @@ class FeatureSession(BasePlugin): iq = self.xmpp.Iq() iq['type'] = 'set' iq.enable('session') - iq.send(block=False, callback=self._on_start_session_response) + iq.send(callback=self._on_start_session_response) def _on_start_session_response(self, response): self.xmpp.features.add('session') diff --git a/slixmpp/plugins/xep_0012/last_activity.py b/slixmpp/plugins/xep_0012/last_activity.py index 2fef9ca8..36d21b29 100644 --- a/slixmpp/plugins/xep_0012/last_activity.py +++ b/slixmpp/plugins/xep_0012/last_activity.py @@ -76,8 +76,8 @@ class XEP_0012(BasePlugin): def del_last_activity(self, jid): self.api['del_last_activity'](jid) - def get_last_activity(self, jid, local=False, ifrom=None, block=True, - timeout=None, callback=None): + def get_last_activity(self, jid, local=False, ifrom=None, timeout=None, + callback=None, timeout_callback=None): if jid is not None and not isinstance(jid, JID): jid = JID(jid) @@ -98,9 +98,8 @@ class XEP_0012(BasePlugin): iq['to'] = jid iq['type'] = 'get' iq.enable('last_activity') - return iq.send(timeout=timeout, - block=block, - callback=callback) + return iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) def _handle_get_last_activity(self, iq): log.debug("Received last activity query from " + \ 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) diff --git a/slixmpp/plugins/xep_0016/privacy.py b/slixmpp/plugins/xep_0016/privacy.py index 25d55048..e07ac633 100644 --- a/slixmpp/plugins/xep_0016/privacy.py +++ b/slixmpp/plugins/xep_0016/privacy.py @@ -29,55 +29,70 @@ class XEP_0016(BasePlugin): def session_bind(self, jid): self.xmpp['xep_0030'].add_feature(Privacy.namespace) - def get_privacy_lists(self, block=True, timeout=None, callback=None): + def get_privacy_lists(self, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq.enable('privacy') - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def get_list(self, name, block=True, timeout=None, callback=None): + def get_list(self, name, timeout=None, callback=None, timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['privacy']['list']['name'] = name - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def get_active(self, block=True, timeout=None, callback=None): + def get_active(self, timeout=None, callback=None, timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['privacy'].enable('active') - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def get_default(self, block=True, timeout=None, callback=None): + def get_default(self, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['privacy'].enable('default') - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def activate(self, name, block=True, timeout=None, callback=None): + def activate(self, name, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['privacy']['active']['name'] = name - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def deactivate(self, block=True, timeout=None, callback=None): + def deactivate(self, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['privacy'].enable('active') - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def make_default(self, name, block=True, timeout=None, callback=None): + def make_default(self, name, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['privacy']['default']['name'] = name - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def remove_default(self, block=True, timeout=None, callback=None): + def remove_default(self, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['privacy'].enable('default') - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def edit_list(self, name, rules, block=True, timeout=None, callback=None): + def edit_list(self, name, rules, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['privacy']['list']['name'] = name @@ -103,8 +118,10 @@ class XEP_0016(BasePlugin): presence_out=rule.get('presence_out', rule.get('presence-out', None))) - def remove_list(self, name, block=True, timeout=None, callback=None): + def remove_list(self, name, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['privacy']['list']['name'] = name - return iq.send(block=block, timeout=timeout, callback=callback) + iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index 12837958..3fb005a9 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -317,10 +317,8 @@ class XEP_0030(BasePlugin): be skipped, even if a result has already been cached. Defaults to false. ifrom -- Specifiy the sender's JID. - block -- If true, block and wait for the stanzas' reply. - timeout -- The time in seconds to block while waiting for - a reply. If None, then wait indefinitely. The - timeout value is only used when block=True. + timeout -- The time in seconds to wait for reply, before + calling timeout_callback callback -- Optional callback to execute when a reply is received instead of blocking and waiting for the reply. @@ -364,10 +362,9 @@ class XEP_0030(BasePlugin): iq['to'] = jid iq['type'] = 'get' iq['disco_info']['node'] = node if node else '' - return iq.send(timeout=kwargs.get('timeout', None), - block=kwargs.get('block', True), - callback=kwargs.get('callback', None), - timeout_callback=kwargs.get('timeout_callback', None)) + iq.send(timeout=kwargs.get('timeout', None), + callback=kwargs.get('callback', None), + timeout_callback=kwargs.get('timeout_callback', None)) def set_info(self, jid=None, node=None, info=None): """ @@ -399,7 +396,6 @@ class XEP_0030(BasePlugin): Otherwise, a disco stanza must be sent to the remove JID to retrieve the items. ifrom -- Specifiy the sender's JID. - block -- If true, block and wait for the stanzas' reply. timeout -- The time in seconds to block while waiting for a reply. If None, then wait indefinitely. callback -- Optional callback to execute when a reply is @@ -424,12 +420,12 @@ class XEP_0030(BasePlugin): iq['type'] = 'get' iq['disco_items']['node'] = node if node else '' if kwargs.get('iterator', False) and self.xmpp['xep_0059']: + raise NotImplementedError("XEP 0059 has not yet been fixed") return self.xmpp['xep_0059'].iterate(iq, 'disco_items') else: - return iq.send(timeout=kwargs.get('timeout', None), - block=kwargs.get('block', True), - callback=kwargs.get('callback', None), - timeout_callback=kwargs.get('timeout_callback', None)) + iq.send(timeout=kwargs.get('timeout', None), + callback=kwargs.get('callback', None), + timeout_callback=kwargs.get('timeout_callback', None)) def set_items(self, jid=None, node=None, **kwargs): """ diff --git a/slixmpp/plugins/xep_0049/private_storage.py b/slixmpp/plugins/xep_0049/private_storage.py index 99a04fe9..a66c05d1 100644 --- a/slixmpp/plugins/xep_0049/private_storage.py +++ b/slixmpp/plugins/xep_0049/private_storage.py @@ -32,7 +32,8 @@ class XEP_0049(BasePlugin): def register(self, stanza): register_stanza_plugin(PrivateXML, stanza, iterable=True) - def store(self, data, ifrom=None, block=True, timeout=None, callback=None): + def store(self, data, ifrom=None, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom @@ -43,11 +44,14 @@ class XEP_0049(BasePlugin): for elem in data: iq['private'].append(elem) - return iq.send(block=block, timeout=timeout, callback=callback) + return iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) - def retrieve(self, name, ifrom=None, block=True, timeout=None, callback=None): + def retrieve(self, name, ifrom=None, timeout=None, callback=None, + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['from'] = ifrom iq['private'].enable(name) - return iq.send(block=block, timeout=timeout, callback=callback) + return iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) diff --git a/slixmpp/plugins/xep_0050/adhoc.py b/slixmpp/plugins/xep_0050/adhoc.py index 01d36489..a948f74f 100644 --- a/slixmpp/plugins/xep_0050/adhoc.py +++ b/slixmpp/plugins/xep_0050/adhoc.py @@ -104,17 +104,13 @@ class XEP_0050(BasePlugin): register_stanza_plugin(Command, Form) self.xmpp.add_event_handler('command_execute', - self._handle_command_start, - threaded=self.threaded) + self._handle_command_start) self.xmpp.add_event_handler('command_next', - self._handle_command_next, - threaded=self.threaded) + self._handle_command_next) self.xmpp.add_event_handler('command_cancel', - self._handle_command_cancel, - threaded=self.threaded) + self._handle_command_cancel) self.xmpp.add_event_handler('command_complete', - self._handle_command_complete, - threaded=self.threaded) + self._handle_command_complete) def plugin_end(self): self.xmpp.del_event_handler('command_execute', @@ -450,7 +446,6 @@ class XEP_0050(BasePlugin): Otherwise, a disco stanza must be sent to the remove JID to retrieve the items. ifrom -- Specifiy the sender's JID. - block -- If true, block and wait for the stanzas' reply. timeout -- The time in seconds to block while waiting for a reply. If None, then wait indefinitely. callback -- Optional callback to execute when a reply is @@ -483,9 +478,6 @@ class XEP_0050(BasePlugin): command workflow methods contained in the session instead of returning the response stanza itself. Defaults to False. - 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 @@ -510,22 +502,12 @@ class XEP_0050(BasePlugin): if not flow: return iq.send(**kwargs) else: - if kwargs.get('block', True): - try: - result = iq.send(**kwargs) - except IqError as err: - result = err.iq - self._handle_command_result(result) - else: - iq.send(block=False, callback=self._handle_command_result) + iq.send(callback=self._handle_command_result) - def start_command(self, jid, node, session, ifrom=None, block=False): + def start_command(self, jid, node, session, ifrom=None): """ Initiate executing a command provided by a remote agent. - The default workflow provided is non-blocking, but a blocking - version may be used with block=True. - The provided session dictionary should contain: next -- A handler for processing the command result. error -- A handler for processing any error stanzas @@ -536,13 +518,10 @@ class XEP_0050(BasePlugin): node -- The node for the desired command. session -- A dictionary of relevant session data. ifrom -- Optionally specify the sender's JID. - block -- If True, block execution until a result - is received. Defaults to False. """ session['jid'] = jid session['node'] = node session['timestamp'] = time.time() - session['block'] = block if 'payload' not in session: session['payload'] = None @@ -562,14 +541,7 @@ class XEP_0050(BasePlugin): sessionid = 'client:pending_' + iq['id'] session['id'] = sessionid self.sessions[sessionid] = session - if session['block']: - try: - result = iq.send(block=True) - except IqError as err: - result = err.iq - self._handle_command_result(result) - else: - iq.send(block=False, callback=self._handle_command_result) + iq.send(callback=self._handle_command_result) def continue_command(self, session, direction='next'): """ @@ -588,8 +560,7 @@ class XEP_0050(BasePlugin): action=direction, payload=session.get('payload', None), sessionid=session['id'], - flow=True, - block=session['block']) + flow=True) def cancel_command(self, session): """ @@ -608,8 +579,7 @@ class XEP_0050(BasePlugin): action='cancel', payload=session.get('payload', None), sessionid=session['id'], - flow=True, - block=session['block']) + flow=True) def complete_command(self, session): """ @@ -628,8 +598,7 @@ class XEP_0050(BasePlugin): action='complete', payload=session.get('payload', None), sessionid=session['id'], - flow=True, - block=session['block']) + flow=True) def terminate_command(self, session): """ diff --git a/slixmpp/plugins/xep_0060/pubsub.py b/slixmpp/plugins/xep_0060/pubsub.py index 223b014f..26258bc9 100644 --- a/slixmpp/plugins/xep_0060/pubsub.py +++ b/slixmpp/plugins/xep_0060/pubsub.py @@ -152,7 +152,7 @@ class XEP_0060(BasePlugin): self.node_event_map[node] = event_name def create_node(self, jid, node, config=None, ntype=None, ifrom=None, - block=True, callback=None, timeout=None): + timeout_callback=None, callback=None, timeout=None): """ Create and configure a new pubsub node. @@ -174,8 +174,6 @@ class XEP_0060(BasePlugin): ntype -- The type of node to create. Servers typically default to using 'leaf' if no type is provided. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -200,10 +198,11 @@ class XEP_0060(BasePlugin): config.add_field(var='pubsub#node_type', value=ntype) iq['pubsub']['configure'].append(config) - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) def subscribe(self, jid, node, bare=True, subscribee=None, options=None, - ifrom=None, block=True, callback=None, timeout=None): + ifrom=None, timeout_callback=None, callback=None, + timeout=None): """ Subscribe to updates from a pubsub node. @@ -220,8 +219,6 @@ class XEP_0060(BasePlugin): subscribee -- The JID that is subscribing to the node. options -- ifrom -- Specify the sender's JID. - 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. @@ -247,10 +244,11 @@ class XEP_0060(BasePlugin): iq['pubsub']['subscribe']['jid'] = subscribee if options is not None: iq['pubsub']['options'].append(options) - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) def unsubscribe(self, jid, node, subid=None, bare=True, subscribee=None, - ifrom=None, block=True, callback=None, timeout=None): + ifrom=None, timeout_callback=None, callback=None, + timeout=None): """ Unubscribe from updates from a pubsub node. @@ -269,8 +267,6 @@ class XEP_0060(BasePlugin): Defaults to True for a bare JID. subscribee -- The JID that is subscribing to the node. ifrom -- Specify the sender's JID. - 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. @@ -295,42 +291,43 @@ class XEP_0060(BasePlugin): iq['pubsub']['unsubscribe']['jid'] = subscribee iq['pubsub']['unsubscribe']['subid'] = subid - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def get_subscriptions(self, jid, node=None, ifrom=None, block=True, - callback=None, timeout=None): + def get_subscriptions(self, jid, node=None, ifrom=None, + timeout_callback=None, callback=None, + timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') iq['pubsub']['subscriptions']['node'] = node - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def get_affiliations(self, jid, node=None, ifrom=None, block=True, - callback=None, timeout=None): + def get_affiliations(self, jid, node=None, ifrom=None, + timeout_callback=None, callback=None, timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') iq['pubsub']['affiliations']['node'] = node - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) def get_subscription_options(self, jid, node=None, user_jid=None, - ifrom=None, block=True, callback=None, - timeout=None): + ifrom=None, timeout_callback=None, + callback=None, timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') if user_jid is None: iq['pubsub']['default']['node'] = node else: iq['pubsub']['options']['node'] = node iq['pubsub']['options']['jid'] = user_jid - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) def set_subscription_options(self, jid, node, user_jid, options, - ifrom=None, block=True, callback=None, - timeout=None): + ifrom=None, timeout_callback=None, + callback=None, timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') iq['pubsub']['options']['node'] = node iq['pubsub']['options']['jid'] = user_jid iq['pubsub']['options'].append(options) - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def get_node_config(self, jid, node=None, ifrom=None, block=True, - callback=None, timeout=None): + def get_node_config(self, jid, node=None, ifrom=None, + timeout_callback=None, callback=None, timeout=None): """ Retrieve the configuration for a node, or the pubsub service's default configuration for new nodes. @@ -341,8 +338,6 @@ class XEP_0060(BasePlugin): the default configuration for new nodes will be requested. Defaults to None. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -354,10 +349,11 @@ class XEP_0060(BasePlugin): iq['pubsub_owner']['default'] else: iq['pubsub_owner']['configure']['node'] = node - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def get_node_subscriptions(self, jid, node, ifrom=None, block=True, - callback=None, timeout=None): + def get_node_subscriptions(self, jid, node, ifrom=None, + timeout_callback=None, callback=None, + timeout=None): """ Retrieve the subscriptions associated with a given node. @@ -365,8 +361,6 @@ class XEP_0060(BasePlugin): jid -- The JID of the pubsub service. node -- The node to retrieve subscriptions from. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -375,9 +369,9 @@ class XEP_0060(BasePlugin): """ iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') iq['pubsub_owner']['subscriptions']['node'] = node - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def get_node_affiliations(self, jid, node, ifrom=None, block=True, + def get_node_affiliations(self, jid, node, ifrom=None, timeout_callback=None, callback=None, timeout=None): """ Retrieve the affiliations associated with a given node. @@ -386,8 +380,6 @@ class XEP_0060(BasePlugin): jid -- The JID of the pubsub service. node -- The node to retrieve affiliations from. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -396,10 +388,10 @@ class XEP_0060(BasePlugin): """ iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') iq['pubsub_owner']['affiliations']['node'] = node - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def delete_node(self, jid, node, ifrom=None, block=True, - callback=None, timeout=None): + def delete_node(self, jid, node, ifrom=None, timeout_callback=None, callback=None, + timeout=None): """ Delete a a pubsub node. @@ -407,8 +399,6 @@ class XEP_0060(BasePlugin): jid -- The JID of the pubsub service. node -- The node to delete. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -417,17 +407,18 @@ class XEP_0060(BasePlugin): """ iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set') iq['pubsub_owner']['delete']['node'] = node - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def set_node_config(self, jid, node, config, ifrom=None, block=True, - callback=None, timeout=None): + def set_node_config(self, jid, node, config, ifrom=None, + timeout_callback=None, callback=None, timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set') iq['pubsub_owner']['configure']['node'] = node iq['pubsub_owner']['configure'].append(config) - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) def publish(self, jid, node, id=None, payload=None, options=None, - ifrom=None, block=True, callback=None, timeout=None): + ifrom=None, timeout_callback=None, callback=None, + timeout=None): """ Add a new item to a node, or edit an existing item. @@ -449,8 +440,6 @@ class XEP_0060(BasePlugin): payload -- The item content to publish. options -- A form of publish options. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -464,10 +453,10 @@ class XEP_0060(BasePlugin): if payload is not None: iq['pubsub']['publish']['item']['payload'] = payload iq['pubsub']['publish_options'] = options - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def retract(self, jid, node, id, notify=None, ifrom=None, block=True, - callback=None, timeout=None): + def retract(self, jid, node, id, notify=None, ifrom=None, + timeout_callback=None, callback=None, timeout=None): """ Delete a single item from a node. """ @@ -476,16 +465,16 @@ class XEP_0060(BasePlugin): iq['pubsub']['retract']['node'] = node iq['pubsub']['retract']['notify'] = notify iq['pubsub']['retract']['item']['id'] = id - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def purge(self, jid, node, ifrom=None, block=True, callback=None, + def purge(self, jid, node, ifrom=None, timeout_callback=None, callback=None, timeout=None): """ Remove all items from a node. """ iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set') iq['pubsub_owner']['purge']['node'] = node - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) def get_nodes(self, *args, **kwargs): """ @@ -493,8 +482,8 @@ class XEP_0060(BasePlugin): """ return self.xmpp['xep_0030'].get_items(*args, **kwargs) - def get_item(self, jid, node, item_id, ifrom=None, block=True, - callback=None, timeout=None): + def get_item(self, jid, node, item_id, ifrom=None, + timeout_callback=None, callback=None, timeout=None): """ Retrieve the content of an individual item. """ @@ -503,10 +492,10 @@ class XEP_0060(BasePlugin): item['id'] = item_id iq['pubsub']['items']['node'] = node iq['pubsub']['items'].append(item) - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) def get_items(self, jid, node, item_ids=None, max_items=None, - iterator=False, ifrom=None, block=False, + iterator=False, ifrom=None, timeout_callback=None, callback=None, timeout=None): """ Request the contents of a node's items. @@ -530,22 +519,21 @@ class XEP_0060(BasePlugin): if iterator: return self.xmpp['xep_0059'].iterate(iq, 'pubsub') else: - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def get_item_ids(self, jid, node, ifrom=None, block=True, - callback=None, timeout=None, iterator=False): + def get_item_ids(self, jid, node, ifrom=None, timeout_callback=None, callback=None, + timeout=None, iterator=False): """ Retrieve the ItemIDs hosted by a given node, using disco. """ - return self.xmpp['xep_0030'].get_items(jid, node, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout, - iterator=iterator) + self.xmpp['xep_0030'].get_items(jid, node, ifrom=ifrom, + callback=callback, timeout=timeout, + iterator=iterator, + timeout_callback=timeout_callback) def modify_affiliations(self, jid, node, affiliations=None, ifrom=None, - block=True, callback=None, timeout=None): + timeout_callback=None, callback=None, + timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set') iq['pubsub_owner']['affiliations']['node'] = node @@ -558,10 +546,11 @@ class XEP_0060(BasePlugin): aff['affiliation'] = affiliation iq['pubsub_owner']['affiliations'].append(aff) - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def modify_subscriptions(self, jid, node, subscriptions=None, ifrom=None, - block=True, callback=None, timeout=None): + def modify_subscriptions(self, jid, node, subscriptions=None, + ifrom=None, timeout_callback=None, + callback=None, timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set') iq['pubsub_owner']['subscriptions']['node'] = node @@ -574,4 +563,4 @@ class XEP_0060(BasePlugin): sub['subscription'] = subscription iq['pubsub_owner']['subscriptions'].append(sub) - return iq.send(block=block, callback=callback, timeout=timeout) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) diff --git a/slixmpp/plugins/xep_0077/register.py b/slixmpp/plugins/xep_0077/register.py index 7c6d99a0..133f025a 100644 --- a/slixmpp/plugins/xep_0077/register.py +++ b/slixmpp/plugins/xep_0077/register.py @@ -89,7 +89,7 @@ class XEP_0077(BasePlugin): iq['from'] = ifrom iq.enable('register') return iq.send(block=block, timeout=timeout, - callback=callback, now=True) + callback=callback) def cancel_registration(self, jid=None, ifrom=None, block=True, timeout=None, callback=None): diff --git a/slixmpp/plugins/xep_0078/legacyauth.py b/slixmpp/plugins/xep_0078/legacyauth.py index eac1b57e..9c49d346 100644 --- a/slixmpp/plugins/xep_0078/legacyauth.py +++ b/slixmpp/plugins/xep_0078/legacyauth.py @@ -79,7 +79,7 @@ class XEP_0078(BasePlugin): iq['auth']['username'] = self.xmpp.requested_jid.user try: - resp = iq.send(now=True) + resp = iq.send() except IqError as err: log.info("Authentication failed: %s", err.iq['error']['condition']) self.xmpp.event('failed_auth') @@ -120,7 +120,7 @@ class XEP_0078(BasePlugin): # Step 3: Send credentials try: - result = iq.send(now=True) + result = iq.send() except IqError as err: log.info("Authentication failed") self.xmpp.event("failed_auth") diff --git a/slixmpp/plugins/xep_0107/user_mood.py b/slixmpp/plugins/xep_0107/user_mood.py index 30ddd647..c56d15fa 100644 --- a/slixmpp/plugins/xep_0107/user_mood.py +++ b/slixmpp/plugins/xep_0107/user_mood.py @@ -40,8 +40,8 @@ class XEP_0107(BasePlugin): def session_bind(self, jid): self.xmpp['xep_0163'].register_pep('user_mood', UserMood) - def publish_mood(self, value=None, text=None, options=None, - ifrom=None, block=True, callback=None, timeout=None): + def publish_mood(self, value=None, text=None, options=None, ifrom=None, + callback=None, timeout=None, timeout_callback=None): """ Publish the user's current mood. @@ -51,8 +51,6 @@ class XEP_0107(BasePlugin): for the mood. options -- Optional form of publish options. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -62,22 +60,18 @@ class XEP_0107(BasePlugin): mood = UserMood() mood['value'] = value mood['text'] = text - return self.xmpp['xep_0163'].publish(mood, - node=UserMood.namespace, - options=options, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) - - def stop(self, ifrom=None, block=True, callback=None, timeout=None): + self.xmpp['xep_0163'].publish(mood, node=UserMood.namespace, + options=options, ifrom=ifrom, + callback=callback, timeout=timeout, + timeout_callback=timeout_callback) + + def stop(self, ifrom=None, callback=None, timeout=None, + timeout_callback=None): """ Clear existing user mood information to stop notifications. Arguments: ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -85,9 +79,7 @@ class XEP_0107(BasePlugin): be executed when a reply stanza is received. """ mood = UserMood() - return self.xmpp['xep_0163'].publish(mood, - node=UserMood.namespace, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + self.xmpp['xep_0163'].publish(mood, node=UserMood.namespace, + ifrom=ifrom, callback=callback, + timeout=timeout, + timeout_callback=timeout_callback) diff --git a/slixmpp/plugins/xep_0108/user_activity.py b/slixmpp/plugins/xep_0108/user_activity.py index 4e0bfbac..502dfae0 100644 --- a/slixmpp/plugins/xep_0108/user_activity.py +++ b/slixmpp/plugins/xep_0108/user_activity.py @@ -33,8 +33,9 @@ class XEP_0108(BasePlugin): def session_bind(self, jid): self.xmpp['xep_0163'].register_pep('user_activity', UserActivity) - def publish_activity(self, general, specific=None, text=None, options=None, - ifrom=None, block=True, callback=None, timeout=None): + def publish_activity(self, general, specific=None, text=None, + options=None, ifrom=None, callback=None, + timeout=None, timeout_callback=None): """ Publish the user's current activity. @@ -46,8 +47,6 @@ class XEP_0108(BasePlugin): for the activity. options -- Optional form of publish options. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -57,22 +56,19 @@ class XEP_0108(BasePlugin): activity = UserActivity() activity['value'] = (general, specific) activity['text'] = text - return self.xmpp['xep_0163'].publish(activity, - node=UserActivity.namespace, - options=options, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + self.xmpp['xep_0163'].publish(activity, node=UserActivity.namespace, + options=options, ifrom=ifrom, + callback=callback, + timeout=timeout, + timeout_callback=timeout_callback) - def stop(self, ifrom=None, block=True, callback=None, timeout=None): + def stop(self, ifrom=None, callback=None, timeout=None, + timeout_callback=None): """ Clear existing user activity information to stop notifications. Arguments: ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -80,9 +76,7 @@ class XEP_0108(BasePlugin): be executed when a reply stanza is received. """ activity = UserActivity() - return self.xmpp['xep_0163'].publish(activity, - node=UserActivity.namespace, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + self.xmpp['xep_0163'].publish(activity, node=UserActivity.namespace, + ifrom=ifrom, callback=callback, + timeout=timeout, + timeout_callback=timeout_callback) diff --git a/slixmpp/plugins/xep_0115/caps.py b/slixmpp/plugins/xep_0115/caps.py index c548de11..5974699c 100644 --- a/slixmpp/plugins/xep_0115/caps.py +++ b/slixmpp/plugins/xep_0115/caps.py @@ -9,7 +9,6 @@ import logging import hashlib import base64 -import threading from slixmpp import __version__ from slixmpp.stanza import StreamFeatures, Presence, Iq @@ -65,8 +64,7 @@ class XEP_0115(BasePlugin): self.xmpp.add_filter('out', self._filter_add_caps) - self.xmpp.add_event_handler('entity_caps', self._process_caps, - threaded=True) + self.xmpp.add_event_handler('entity_caps', self._process_caps) if not self.xmpp.is_component: self.xmpp.register_feature('caps', @@ -90,9 +88,6 @@ class XEP_0115(BasePlugin): disco.assign_verstring = self.assign_verstring disco.get_verstring = self.get_verstring - self._processing_lock = threading.Lock() - self._processing = set() - def plugin_end(self): self.xmpp['xep_0030'].del_feature(feature=stanza.Capabilities.namespace) self.xmpp.del_filter('out', self._filter_add_caps) @@ -164,13 +159,6 @@ class XEP_0115(BasePlugin): except XMPPError: return - # Only lookup the same caps once at a time. - with self._processing_lock: - if ver in self._processing: - log.debug('Already processing verstring %s' % ver) - return - self._processing.add(ver) - log.debug("New caps verification string: %s", ver) try: node = '%s#%s' % (pres['caps']['node'], ver) @@ -185,9 +173,6 @@ class XEP_0115(BasePlugin): except XMPPError: log.debug("Could not retrieve disco#info results for caps for %s", node) - with self._processing_lock: - self._processing.remove(ver) - def _validate_caps(self, caps, hash, check_verstring): # Check Identities full_ids = caps.get_identities(dedupe=False) diff --git a/slixmpp/plugins/xep_0163.py b/slixmpp/plugins/xep_0163.py index bd59e9ad..e974a808 100644 --- a/slixmpp/plugins/xep_0163.py +++ b/slixmpp/plugins/xep_0163.py @@ -83,7 +83,7 @@ class XEP_0163(BasePlugin): self.xmpp['xep_0115'].update_caps(jid) def publish(self, stanza, node=None, id=None, options=None, ifrom=None, - block=True, callback=None, timeout=None): + timeout_callback=None, callback=None, timeout=None): """ Publish a PEP update. @@ -97,8 +97,6 @@ class XEP_0163(BasePlugin): id -- Optionally specify the ID of the item. options -- A form of publish options. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -110,14 +108,12 @@ class XEP_0163(BasePlugin): if id is None: id = 'current' - return self.xmpp['xep_0060'].publish(ifrom, node, - id=id, - payload=stanza.xml, - options=options, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + return self.xmpp['xep_0060'].publish(ifrom, node, id=id, + payload=stanza.xml, + options=options, ifrom=ifrom, + callback=callback, + timeout=timeout, + timeout_callback=timeout_callback) register_plugin(XEP_0163) diff --git a/slixmpp/plugins/xep_0172/user_nick.py b/slixmpp/plugins/xep_0172/user_nick.py index 4ca7c8af..b9f20b27 100644 --- a/slixmpp/plugins/xep_0172/user_nick.py +++ b/slixmpp/plugins/xep_0172/user_nick.py @@ -42,7 +42,7 @@ class XEP_0172(BasePlugin): def session_bind(self, jid): self.xmpp['xep_0163'].register_pep('user_nick', UserNick) - def publish_nick(self, nick=None, options=None, ifrom=None, block=True, + def publish_nick(self, nick=None, options=None, ifrom=None, timeout_callback=None, callback=None, timeout=None): """ Publish the user's current nick. @@ -51,8 +51,6 @@ class XEP_0172(BasePlugin): nick -- The user nickname to publish. options -- Optional form of publish options. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -61,22 +59,17 @@ class XEP_0172(BasePlugin): """ nickname = UserNick() nickname['nick'] = nick - return self.xmpp['xep_0163'].publish(nickname, - node=UserNick.namespace, - options=options, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) - - def stop(self, ifrom=None, block=True, callback=None, timeout=None): + self.xmpp['xep_0163'].publish(nickname, node=UserNick.namespace, + options=options, ifrom=ifrom, + callback=callback, timeout=timeout, + timeout_callback=timeout_callback) + + def stop(self, ifrom=None, timeout_callback=None, callback=None, timeout=None): """ Clear existing user nick information to stop notifications. Arguments: ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -84,9 +77,7 @@ class XEP_0172(BasePlugin): be executed when a reply stanza is received. """ nick = UserNick() - return self.xmpp['xep_0163'].publish(nick, - node=UserNick.namespace, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + return self.xmpp['xep_0163'].publish(nick, node=UserNick.namespace, + ifrom=ifrom, callback=callback, + timeout=timeout, + timeout_callback=timeout_callback) diff --git a/slixmpp/plugins/xep_0196/user_gaming.py b/slixmpp/plugins/xep_0196/user_gaming.py index cf940ce9..f0dee99f 100644 --- a/slixmpp/plugins/xep_0196/user_gaming.py +++ b/slixmpp/plugins/xep_0196/user_gaming.py @@ -33,9 +33,11 @@ class XEP_0196(BasePlugin): def session_bind(self, jid): self.xmpp['xep_0163'].register_pep('user_gaming', UserGaming) - def publish_gaming(self, name=None, level=None, server_name=None, uri=None, - character_name=None, character_profile=None, server_address=None, - options=None, ifrom=None, block=True, callback=None, timeout=None): + def publish_gaming(self, name=None, level=None, server_name=None, + uri=None, character_name=None, + character_profile=None, server_address=None, + options=None, ifrom=None, callback=None, + timeout=None, timeout_callback=None): """ Publish the user's current gaming status. @@ -50,8 +52,6 @@ class XEP_0196(BasePlugin): character_profile -- A URI for a profile of the user's character. options -- Optional form of publish options. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -67,21 +67,18 @@ class XEP_0196(BasePlugin): gaming['server_name'] = server_name gaming['server_address'] = server_address return self.xmpp['xep_0163'].publish(gaming, - node=UserGaming.namespace, - options=options, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + node=UserGaming.namespace, + options=options, ifrom=ifrom, + callback=callback, timeout=timeout, + timeout_callback=timeout_callback) - def stop(self, ifrom=None, block=True, callback=None, timeout=None): + def stop(self, ifrom=None, callback=None, timeout=None, + timeout_callback=None): """ Clear existing user gaming information to stop notifications. Arguments: ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -90,8 +87,7 @@ class XEP_0196(BasePlugin): """ gaming = UserGaming() return self.xmpp['xep_0163'].publish(gaming, - node=UserGaming.namespace, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + node=UserGaming.namespace, + ifrom=ifrom, callback=callback, + timeout=timeout, + timeout_callback=timeout_callback) diff --git a/slixmpp/plugins/xep_0199/ping.py b/slixmpp/plugins/xep_0199/ping.py index 5fdf79b5..a8171105 100644 --- a/slixmpp/plugins/xep_0199/ping.py +++ b/slixmpp/plugins/xep_0199/ping.py @@ -101,7 +101,7 @@ class XEP_0199(BasePlugin): repeat=True) def disable_keepalive(self, event=None): - self.xmpp.scheduler.remove('Ping keepalive') + self.xmpp.cancel_schedule('Ping keepalive') def _keepalive(self, event=None): log.debug("Keepalive ping...") @@ -119,15 +119,13 @@ class XEP_0199(BasePlugin): log.debug("Pinged by %s", iq['from']) iq.reply().send() - def send_ping(self, jid, ifrom=None, block=True, timeout=None, callback=None): + def send_ping(self, jid, ifrom=None, timeout=None, callback=None, + timeout_callback=None): """Send a ping request. Arguments: jid -- The JID that will receive the ping. ifrom -- Specifiy the sender JID. - block -- Indicate if execution should block until - a pong response is received. Defaults - to True. timeout -- Time in seconds to wait for a response. Defaults to self.timeout. callback -- Optional handler to execute when a pong @@ -143,7 +141,8 @@ class XEP_0199(BasePlugin): iq['from'] = ifrom iq.enable('ping') - return iq.send(block=block, timeout=timeout, callback=callback) + return iq.send(timeout=timeout, callback=callback, + timeout_callback=timeout_callback) def ping(self, jid=None, ifrom=None, timeout=None): """Send a ping request and calculate RTT. diff --git a/slixmpp/plugins/xep_0223.py b/slixmpp/plugins/xep_0223.py index a22e6d45..2461bb20 100644 --- a/slixmpp/plugins/xep_0223.py +++ b/slixmpp/plugins/xep_0223.py @@ -32,6 +32,7 @@ class XEP_0223(BasePlugin): """ Update a node's configuration to match the public storage profile. """ + # TODO: that cannot possibly work, why is this here? config = self.xmpp['xep_0004'].Form() config['type'] = 'submit' @@ -39,13 +40,12 @@ class XEP_0223(BasePlugin): config.add_field(var=field, value=value) return self.xmpp['xep_0060'].set_node_config(None, node, config, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + ifrom=ifrom, + callback=callback, + timeout=timeout) def store(self, stanza, node=None, id=None, ifrom=None, options=None, - block=True, callback=None, timeout=None): + callback=None, timeout=None, timeout_callback=None): """ Store private data via PEP. @@ -60,8 +60,6 @@ class XEP_0223(BasePlugin): options -- Publish options to use, which will be modified to fit the persistent storage option profile. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -82,15 +80,13 @@ class XEP_0223(BasePlugin): options.add_field(var=field) options['fields'][field]['value'] = value - return self.xmpp['xep_0163'].publish(stanza, node, - options=options, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + return self.xmpp['xep_0163'].publish(stanza, node, options=options, + ifrom=ifrom, callback=callback, + timeout=timeout, + timeout_callback=timeout_callback) def retrieve(self, node, id=None, item_ids=None, ifrom=None, - block=True, callback=None, timeout=None): + callback=None, timeout=None, timeout_callback=None): """ Retrieve private data via PEP. @@ -103,8 +99,6 @@ class XEP_0223(BasePlugin): item_ids -- Specify a group of IDs. If id is also specified, it will be included in item_ids. ifrom -- Specify the sender's JID. - 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 slixmpp.xmlstream.RESPONSE_TIMEOUT @@ -117,11 +111,9 @@ class XEP_0223(BasePlugin): item_ids.append(id) return self.xmpp['xep_0060'].get_items(None, node, - item_ids=item_ids, - ifrom=ifrom, - block=block, - callback=callback, - timeout=timeout) + item_ids=item_ids, ifrom=ifrom, + callback=callback, timeout=timeout, + timeout_callback=timeout_callback) register_plugin(XEP_0223) diff --git a/slixmpp/stanza/iq.py b/slixmpp/stanza/iq.py index 605e226a..d247fc0e 100644 --- a/slixmpp/stanza/iq.py +++ b/slixmpp/stanza/iq.py @@ -158,38 +158,26 @@ class Iq(RootStanza): StanzaBase.reply(self, clear) return self - def send(self, block=True, timeout=None, callback=None, now=False, timeout_callback=None): - """ - Send an 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. 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. + def send(self, callback=None, timeout=None, timeout_callback=None): + """Send an stanza over the XML stream. - Using both block and callback is not recommended, and only the - callback argument will be used in that case. + A callback handler can be provided that will be executed when the Iq + stanza's result reply is received. 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 slixmpp.xmlstream.RESPONSE_TIMEOUT - callback -- Optional reference to a stream handler function. Will - be executed when a reply stanza is received. - 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). + + callback -- Optional reference to a stream handler + function. Will be executed when a reply stanza is + received. + timeout -- The length of time (in seconds) to wait for a + response before the timeout_callback is called, + instead of the regular callback + 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. """ if self.stream.session_bind_event.is_set(): matcher = MatchIDSender({ @@ -219,24 +207,14 @@ class Iq(RootStanza): callback, once=True) self.stream.register_handler(handler) - StanzaBase.send(self, now=now) + StanzaBase.send(self) return handler_name - elif block and self['type'] in ('get', 'set'): - waitfor = Waiter('IqWait_%s' % self['id'], matcher) - self.stream.register_handler(waitfor) - StanzaBase.send(self, now=now) - result = waitfor.wait(timeout) - if not result: - raise IqTimeout(self) - if result['type'] == 'error': - raise IqError(result) - return result else: - return StanzaBase.send(self, now=now) + return StanzaBase.send(self) def _handle_result(self, iq): # we got the IQ, so don't fire the timeout - self.stream.scheduler.remove('IqTimeout_%s' % self['id']) + self.stream.cancel_schedule('IqTimeout_%s' % self['id']) self.callback(iq) def _fire_timeout(self): diff --git a/slixmpp/xmlstream/stanzabase.py b/slixmpp/xmlstream/stanzabase.py index 75555c34..8634250f 100644 --- a/slixmpp/xmlstream/stanzabase.py +++ b/slixmpp/xmlstream/stanzabase.py @@ -1573,7 +1573,7 @@ class StanzaBase(ElementBase): log.exception('Error handling {%s}%s stanza', self.namespace, self.name) - def send(self, now=False): + def send(self): """Queue the stanza to be sent on the XML stream. :param bool now: Indicates if the queue should be skipped and the -- cgit v1.2.3