diff options
Diffstat (limited to 'slixmpp')
-rw-r--r-- | slixmpp/plugins/xep_0012/last_activity.py | 9 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0030/disco.py | 17 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0049/private_storage.py | 13 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0050/adhoc.py | 3 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0054/vcard_temp.py | 14 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0060/pubsub.py | 130 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0077/register.py | 16 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0084/avatar.py | 32 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0092/version.py | 7 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0153/vcard_avatar.py | 72 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0163.py | 7 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0191/blocking.py | 19 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0199/ping.py | 7 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0202/time.py | 2 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0231/bob.py | 8 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0257/client_cert_management.py | 21 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0258/security_labels.py | 6 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0279/ipcheck.py | 6 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0280/carbons.py | 11 |
19 files changed, 152 insertions, 248 deletions
diff --git a/slixmpp/plugins/xep_0012/last_activity.py b/slixmpp/plugins/xep_0012/last_activity.py index 078c5411..6a7773c1 100644 --- a/slixmpp/plugins/xep_0012/last_activity.py +++ b/slixmpp/plugins/xep_0012/last_activity.py @@ -10,13 +10,12 @@ import logging from datetime import datetime, timedelta from slixmpp.plugins import BasePlugin, register_plugin -from slixmpp import Iq +from slixmpp import future_wrapper, Iq from slixmpp.exceptions import XMPPError from slixmpp.xmlstream import JID, register_stanza_plugin from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.plugins.xep_0012 import stanza, LastActivity -from slixmpp import coroutine_wrapper log = logging.getLogger(__name__) @@ -77,9 +76,9 @@ class XEP_0012(BasePlugin): def del_last_activity(self, jid): self.api['del_last_activity'](jid) - @coroutine_wrapper + @future_wrapper def get_last_activity(self, jid, local=False, ifrom=None, timeout=None, - callback=None, timeout_callback=None, coroutine=False): + callback=None, timeout_callback=None): if jid is not None and not isinstance(jid, JID): jid = JID(jid) @@ -100,7 +99,7 @@ class XEP_0012(BasePlugin): iq['to'] = jid iq['type'] = 'get' iq.enable('last_activity') - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine, + return iq.send(timeout=timeout, callback=callback, timeout_callback=timeout_callback) def _handle_get_last_activity(self, iq): diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index 7833dffd..c8c18ea7 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -10,7 +10,6 @@ import logging from slixmpp import Iq from slixmpp.plugins import BasePlugin -from slixmpp import coroutine_wrapper from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream import register_stanza_plugin, JID @@ -289,7 +288,6 @@ class XEP_0030(BasePlugin): 'cached': cached} return self.api['has_identity'](jid, node, ifrom, data) - @coroutine_wrapper def get_info(self, jid=None, node=None, local=None, cached=None, **kwargs): """ @@ -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), - callback=kwargs.get('callback', None), - coroutine=kwargs.get('coroutine', False), - 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): """ @@ -378,7 +375,6 @@ class XEP_0030(BasePlugin): info = info['disco_info'] self.api['set_info'](jid, node, None, info) - @coroutine_wrapper def get_items(self, jid=None, node=None, local=False, **kwargs): """ Retrieve the disco#items results from a given JID/node combination. @@ -427,10 +423,9 @@ class XEP_0030(BasePlugin): 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), - callback=kwargs.get('callback', None), - coroutine=kwargs.get('coroutine', False), - 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 32309069..a66c05d1 100644 --- a/slixmpp/plugins/xep_0049/private_storage.py +++ b/slixmpp/plugins/xep_0049/private_storage.py @@ -9,7 +9,6 @@ import logging from slixmpp import Iq -from slixmpp import coroutine_wrapper from slixmpp.plugins import BasePlugin from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath @@ -33,9 +32,8 @@ class XEP_0049(BasePlugin): def register(self, stanza): register_stanza_plugin(PrivateXML, stanza, iterable=True) - @coroutine_wrapper def store(self, data, ifrom=None, timeout=None, callback=None, - timeout_callback=None, coroutine=False): + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom @@ -46,15 +44,14 @@ class XEP_0049(BasePlugin): for elem in data: iq['private'].append(elem) - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine, + return iq.send(timeout=timeout, callback=callback, timeout_callback=timeout_callback) - @coroutine_wrapper def retrieve(self, name, ifrom=None, timeout=None, callback=None, - timeout_callback=None, coroutine=False): + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['from'] = ifrom iq['private'].enable(name) - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine, - timeout_callback=timeout_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 6be6997c..e6ef8333 100644 --- a/slixmpp/plugins/xep_0050/adhoc.py +++ b/slixmpp/plugins/xep_0050/adhoc.py @@ -18,7 +18,6 @@ from slixmpp.plugins import BasePlugin from slixmpp.plugins.xep_0050 import stanza from slixmpp.plugins.xep_0050 import Command from slixmpp.plugins.xep_0004 import Form -from slixmpp import coroutine_wrapper log = logging.getLogger(__name__) @@ -428,7 +427,6 @@ class XEP_0050(BasePlugin): # ================================================================= # Client side (command user) API - @coroutine_wrapper def get_commands(self, jid, **kwargs): """ Return a list of commands provided by a given JID. @@ -454,7 +452,6 @@ class XEP_0050(BasePlugin): node=Command.namespace, **kwargs) - @coroutine_wrapper def send_command(self, jid, node, ifrom=None, action='execute', payload=None, sessionid=None, flow=False, **kwargs): """ diff --git a/slixmpp/plugins/xep_0054/vcard_temp.py b/slixmpp/plugins/xep_0054/vcard_temp.py index 41849e60..85736b29 100644 --- a/slixmpp/plugins/xep_0054/vcard_temp.py +++ b/slixmpp/plugins/xep_0054/vcard_temp.py @@ -15,7 +15,7 @@ from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.plugins import BasePlugin from slixmpp.plugins.xep_0054 import VCardTemp, stanza -from slixmpp import coroutine_wrapper +from slixmpp import future_wrapper log = logging.getLogger(__name__) @@ -60,9 +60,9 @@ class XEP_0054(BasePlugin): def make_vcard(self): return VCardTemp() - @coroutine_wrapper + @future_wrapper def get_vcard(self, jid=None, ifrom=None, local=None, cached=False, - callback=None, timeout=None, coroutine=False): + callback=None, timeout=None): if local is None: if jid is not None and not isinstance(jid, JID): jid = JID(jid) @@ -101,11 +101,11 @@ class XEP_0054(BasePlugin): iq['type'] = 'get' iq.enable('vcard_temp') - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine) + return iq.send(callback=callback, timeout=timeout) - @coroutine_wrapper + @future_wrapper def publish_vcard(self, vcard=None, jid=None, ifrom=None, - callback=None, timeout=None, coroutine=False): + callback=None, timeout=None): self.api['set_vcard'](jid, None, ifrom, vcard) if self.xmpp.is_component: return @@ -115,7 +115,7 @@ class XEP_0054(BasePlugin): iq['from'] = ifrom iq['type'] = 'set' iq.append(vcard) - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine) + return iq.send(callback=callback, timeout=timeout) def _handle_get_vcard(self, iq): if iq['type'] == 'result': diff --git a/slixmpp/plugins/xep_0060/pubsub.py b/slixmpp/plugins/xep_0060/pubsub.py index bf5a615f..26258bc9 100644 --- a/slixmpp/plugins/xep_0060/pubsub.py +++ b/slixmpp/plugins/xep_0060/pubsub.py @@ -13,7 +13,6 @@ from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.plugins.base import BasePlugin from slixmpp.plugins.xep_0060 import stanza -from slixmpp import coroutine_wrapper log = logging.getLogger(__name__) @@ -152,9 +151,8 @@ class XEP_0060(BasePlugin): """ self.node_event_map[node] = event_name - @coroutine_wrapper def create_node(self, jid, node, config=None, ntype=None, ifrom=None, - timeout_callback=None, callback=None, timeout=None, coroutine=False): + timeout_callback=None, callback=None, timeout=None): """ Create and configure a new pubsub node. @@ -200,13 +198,11 @@ class XEP_0060(BasePlugin): config.add_field(var='pubsub#node_type', value=ntype) iq['pubsub']['configure'].append(config) - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def subscribe(self, jid, node, bare=True, subscribee=None, options=None, ifrom=None, timeout_callback=None, callback=None, - timeout=None, coroutine=False): + timeout=None): """ Subscribe to updates from a pubsub node. @@ -248,13 +244,11 @@ class XEP_0060(BasePlugin): iq['pubsub']['subscribe']['jid'] = subscribee if options is not None: iq['pubsub']['options'].append(options) - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def unsubscribe(self, jid, node, subid=None, bare=True, subscribee=None, ifrom=None, timeout_callback=None, callback=None, - timeout=None, coroutine=False): + timeout=None): """ Unubscribe from updates from a pubsub node. @@ -297,52 +291,42 @@ class XEP_0060(BasePlugin): iq['pubsub']['unsubscribe']['jid'] = subscribee iq['pubsub']['unsubscribe']['subid'] = subid - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def get_subscriptions(self, jid, node=None, ifrom=None, timeout_callback=None, callback=None, - timeout=None, coroutine=False): + timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') iq['pubsub']['subscriptions']['node'] = node - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper - def get_affiliations(self, jid, node=None, ifrom=None, timeout=None, - timeout_callback=None, callback=None, coroutine=False): + 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(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def get_subscription_options(self, jid, node=None, user_jid=None, ifrom=None, timeout_callback=None, - callback=None, timeout=None, coroutine=False): + 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(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def set_subscription_options(self, jid, node, user_jid, options, ifrom=None, timeout_callback=None, - callback=None, timeout=None, coroutine=False): + 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(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper - def get_node_config(self, jid, node=None, ifrom=None, coroutine=False, + 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 @@ -365,13 +349,11 @@ class XEP_0060(BasePlugin): iq['pubsub_owner']['default'] else: iq['pubsub_owner']['configure']['node'] = node - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def get_node_subscriptions(self, jid, node, ifrom=None, timeout_callback=None, callback=None, - timeout=None, coroutine=False): + timeout=None): """ Retrieve the subscriptions associated with a given node. @@ -387,12 +369,10 @@ class XEP_0060(BasePlugin): """ iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') iq['pubsub_owner']['subscriptions']['node'] = node - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def get_node_affiliations(self, jid, node, ifrom=None, timeout_callback=None, - callback=None, timeout=None, coroutine=False): + callback=None, timeout=None): """ Retrieve the affiliations associated with a given node. @@ -408,12 +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(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def delete_node(self, jid, node, ifrom=None, timeout_callback=None, callback=None, - timeout=None, coroutine=False): + timeout=None): """ Delete a a pubsub node. @@ -429,21 +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(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - def set_node_config(self, jid, node, config, ifrom=None, coroutine=False, + 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(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def publish(self, jid, node, id=None, payload=None, options=None, ifrom=None, timeout_callback=None, callback=None, - timeout=None, coroutine=False): + timeout=None): """ Add a new item to a node, or edit an existing item. @@ -478,11 +453,9 @@ class XEP_0060(BasePlugin): if payload is not None: iq['pubsub']['publish']['item']['payload'] = payload iq['pubsub']['publish_options'] = options - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper - def retract(self, jid, node, id, notify=None, ifrom=None, coroutine=False, + def retract(self, jid, node, id, notify=None, ifrom=None, timeout_callback=None, callback=None, timeout=None): """ Delete a single item from a node. @@ -492,30 +465,25 @@ class XEP_0060(BasePlugin): iq['pubsub']['retract']['node'] = node iq['pubsub']['retract']['notify'] = notify iq['pubsub']['retract']['item']['id'] = id - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def purge(self, jid, node, ifrom=None, timeout_callback=None, callback=None, - timeout=None, coroutine=False): + 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(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def get_nodes(self, *args, **kwargs): """ Discover the nodes provided by a Pubsub service, using disco. """ return self.xmpp['xep_0030'].get_items(*args, **kwargs) - @coroutine_wrapper - def get_item(self, jid, node, item_id, ifrom=None, timeout=None, - timeout_callback=None, callback=None, coroutine=False): + def get_item(self, jid, node, item_id, ifrom=None, + timeout_callback=None, callback=None, timeout=None): """ Retrieve the content of an individual item. """ @@ -524,13 +492,11 @@ class XEP_0060(BasePlugin): item['id'] = item_id iq['pubsub']['items']['node'] = node iq['pubsub']['items'].append(item) - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def get_items(self, jid, node, item_ids=None, max_items=None, iterator=False, ifrom=None, timeout_callback=None, - callback=None, timeout=None, coroutine=False): + callback=None, timeout=None): """ Request the contents of a node's items. @@ -553,26 +519,21 @@ class XEP_0060(BasePlugin): if iterator: return self.xmpp['xep_0059'].iterate(iq, 'pubsub') else: - return iq.send(callback=callback, timeout=timeout, - coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper def get_item_ids(self, jid, node, ifrom=None, timeout_callback=None, callback=None, - timeout=None, iterator=False, coroutine=False): + timeout=None, iterator=False): """ Retrieve the ItemIDs hosted by a given node, using disco. """ self.xmpp['xep_0030'].get_items(jid, node, ifrom=ifrom, callback=callback, timeout=timeout, iterator=iterator, - timeout_callback=timeout_callback, - coroutine=coroutine) + timeout_callback=timeout_callback) - @coroutine_wrapper def modify_affiliations(self, jid, node, affiliations=None, ifrom=None, timeout_callback=None, callback=None, - timeout=None, coroutine=False): + timeout=None): iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set') iq['pubsub_owner']['affiliations']['node'] = node @@ -585,13 +546,11 @@ class XEP_0060(BasePlugin): aff['affiliation'] = affiliation iq['pubsub_owner']['affiliations'].append(aff) - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback) - @coroutine_wrapper - def modify_subscriptions(self, jid, node, subscriptions=None, ifrom=None, - timeout_callback=None, callback=None, - timeout=None, coroutine=False): + 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 @@ -604,5 +563,4 @@ class XEP_0060(BasePlugin): sub['subscription'] = subscription iq['pubsub_owner']['subscriptions'].append(sub) - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine, - timeout_callback=timeout_callback) + 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 b4beac84..eb2e7443 100644 --- a/slixmpp/plugins/xep_0077/register.py +++ b/slixmpp/plugins/xep_0077/register.py @@ -9,7 +9,6 @@ import logging import ssl -from slixmpp import coroutine_wrapper from slixmpp.stanza import StreamFeatures, Iq from slixmpp.xmlstream import register_stanza_plugin, JID from slixmpp.plugins import BasePlugin @@ -82,29 +81,26 @@ class XEP_0077(BasePlugin): return True return False - @coroutine_wrapper def get_registration(self, jid=None, ifrom=None, - timeout=None, callback=None, coroutine=False): + timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['to'] = jid iq['from'] = ifrom iq.enable('register') - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) - @coroutine_wrapper def cancel_registration(self, jid=None, ifrom=None, - timeout=None, callback=None, coroutine=False): + timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['to'] = jid iq['from'] = ifrom iq['register']['remove'] = True - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) - @coroutine_wrapper def change_password(self, password, jid=None, ifrom=None, - timeout=None, callback=None, coroutine=False): + timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['to'] = jid @@ -115,4 +111,4 @@ class XEP_0077(BasePlugin): else: iq['register']['username'] = self.xmpp.boundjid.user iq['register']['password'] = password - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) diff --git a/slixmpp/plugins/xep_0084/avatar.py b/slixmpp/plugins/xep_0084/avatar.py index 9216bdf0..2bae765a 100644 --- a/slixmpp/plugins/xep_0084/avatar.py +++ b/slixmpp/plugins/xep_0084/avatar.py @@ -15,7 +15,6 @@ from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream import register_stanza_plugin, JID from slixmpp.plugins.xep_0084 import stanza, Data, MetaData -from slixmpp import coroutine_wrapper log = logging.getLogger(__name__) @@ -45,30 +44,26 @@ class XEP_0084(BasePlugin): def generate_id(self, data): return hashlib.sha1(data).hexdigest() - @coroutine_wrapper - def retrieve_avatar(self, jid, id, url=None, ifrom=None, callback=None, - timeout=None, coroutine=False): + def retrieve_avatar(self, jid, id, url=None, ifrom=None, + callback=None, timeout=None): return self.xmpp['xep_0060'].get_item(jid, Data.namespace, id, - ifrom=ifrom, callback=callback, - timeout=timeout, - coroutine=coroutine) + ifrom=ifrom, + callback=callback, + timeout=timeout) - @coroutine_wrapper def publish_avatar(self, data, ifrom=None, callback=None, - timeout=None, coroutine=False): + timeout=None): payload = Data() payload['value'] = data return self.xmpp['xep_0163'].publish(payload, id=self.generate_id(data), ifrom=ifrom, callback=callback, - timeout=timeout, - coroutine=coroutine) + timeout=timeout) - @coroutine_wrapper def publish_avatar_metadata(self, items=None, pointers=None, - ifrom=None, callback=None, timeout=None, - coroutine=False): + ifrom=None, + callback=None, timeout=None): metadata = MetaData() if items is None: items = [] @@ -88,11 +83,9 @@ class XEP_0084(BasePlugin): id=info['id'], ifrom=ifrom, callback=callback, - timeout=timeout, - coroutine=coroutine) + timeout=timeout) - @coroutine_wrapper - def stop(self, ifrom=None, callback=None, timeout=None, coroutine=False): + def stop(self, ifrom=None, callback=None, timeout=None): """ Clear existing avatar metadata information to stop notifications. @@ -109,5 +102,4 @@ class XEP_0084(BasePlugin): node=MetaData.namespace, ifrom=ifrom, callback=callback, - timeout=timeout, - coroutine=coroutine) + timeout=timeout) diff --git a/slixmpp/plugins/xep_0092/version.py b/slixmpp/plugins/xep_0092/version.py index 68c6a326..9dbdc4e6 100644 --- a/slixmpp/plugins/xep_0092/version.py +++ b/slixmpp/plugins/xep_0092/version.py @@ -15,7 +15,6 @@ from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.plugins import BasePlugin from slixmpp.plugins.xep_0092 import Version, stanza -from slixmpp import coroutine_wrapper log = logging.getLogger(__name__) @@ -71,9 +70,7 @@ class XEP_0092(BasePlugin): iq['software_version']['os'] = self.os iq.send() - @coroutine_wrapper - def get_version(self, jid, ifrom=None, timeout=None, callback=None, - coroutine=False): + def get_version(self, jid, ifrom=None, timeout=None, callback=None): """ Retrieve the software version of a remote agent. @@ -85,4 +82,4 @@ class XEP_0092(BasePlugin): iq['from'] = ifrom iq['type'] = 'get' iq['query'] = Version.namespace - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) diff --git a/slixmpp/plugins/xep_0153/vcard_avatar.py b/slixmpp/plugins/xep_0153/vcard_avatar.py index 6ff9f7ed..8cfe97fa 100644 --- a/slixmpp/plugins/xep_0153/vcard_avatar.py +++ b/slixmpp/plugins/xep_0153/vcard_avatar.py @@ -8,14 +8,13 @@ import hashlib import logging -import threading from slixmpp.stanza import Presence -from slixmpp.exceptions import XMPPError +from slixmpp.exceptions import XMPPError, IqTimeout from slixmpp.xmlstream import register_stanza_plugin from slixmpp.plugins.base import BasePlugin from slixmpp.plugins.xep_0153 import stanza, VCardTempUpdate -from slixmpp import asyncio, coroutine_wrapper +from slixmpp import asyncio, future_wrapper log = logging.getLogger(__name__) @@ -31,8 +30,6 @@ class XEP_0153(BasePlugin): def plugin_init(self): self._hashes = {} - self._allow_advertising = threading.Event() - register_stanza_plugin(Presence, VCardTempUpdate) self.xmpp.add_filter('out', self._update_presence) @@ -60,59 +57,60 @@ class XEP_0153(BasePlugin): self.xmpp.del_event_handler('presence_chat', self._recv_presence) self.xmpp.del_event_handler('presence_away', self._recv_presence) - @asyncio.coroutine - def _set_avatar_coroutine(self, jid, mtype, avatar): - vcard = yield from self.xmpp['xep_0054'].get_vcard(jid, cached=True, coroutine=True) - vcard = vcard['vcard_temp'] - vcard['PHOTO']['TYPE'] = mtype - vcard['PHOTO']['BINVAL'] = avatar - - result = yield from self.xmpp['xep_0054'].publish_vcard(jid=jid, vcard=vcard) - - self.api['reset_hash'](jid) - self.xmpp.roster[jid].send_last_presence() - - return result - - @coroutine_wrapper + @future_wrapper def set_avatar(self, jid=None, avatar=None, mtype=None, timeout=None, - callback=None, coroutine=False): + callback=None): if jid is None: jid = self.xmpp.boundjid.bare - if coroutine: - return self._set_avatar_coroutine(jid, mtype, avatar) - else: - def custom_callback(result): - vcard = result['vcard_temp'] - vcard['PHOTO']['TYPE'] = mtype - vcard['PHOTO']['BINVAL'] = avatar + future = asyncio.Future() + + def propagate_timeout_exception(fut): + try: + fut.done() + except IqTimeout as e: + future.set_exception(e) + + def custom_callback(result): + vcard = result['vcard_temp'] + vcard['PHOTO']['TYPE'] = mtype + vcard['PHOTO']['BINVAL'] = avatar - self.xmpp['xep_0054'].publish_vcard(jid=jid, vcard=vcard, callback=callback) + new_future = self.xmpp['xep_0054'].publish_vcard(jid=jid, + vcard=vcard, + timeout=timeout, + callback=next_callback) + new_future.add_done_callback(propagate_timeout_exception) + def next_callback(result): + if result['type'] == 'error': + future.set_exception(result) + else: self.api['reset_hash'](jid) self.xmpp.roster[jid].send_last_presence() - callback(result) - self.xmpp['xep_0054'].get_vcard(jid, cached=True, callback=custom_callback) + future.set_result(result) + + first_future = self.xmpp['xep_0054'].get_vcard(jid, cached=False, timeout=timeout, + callback=custom_callback) + first_future.add_done_callback(propagate_timeout_exception) + return future @asyncio.coroutine def _start(self, event): try: - vcard = yield from self.xmpp['xep_0054'].get_vcard(self.xmpp.boundjid.bare, - coroutine=True) + vcard = yield from self.xmpp['xep_0054'].get_vcard(self.xmpp.boundjid.bare) data = vcard['vcard_temp']['PHOTO']['BINVAL'] if not data: new_hash = '' else: new_hash = hashlib.sha1(data).hexdigest() self.api['set_hash'](self.xmpp.boundjid, args=new_hash) - self._allow_advertising.set() except XMPPError: - log.debug('Could not retrieve vCard for %s' % self.xmpp.boundjid.bare) + log.debug('Could not retrieve vCard for %s', self.xmpp.boundjid.bare) def _end(self, event): - self._allow_advertising.clear() + pass def _update_presence(self, stanza): if not isinstance(stanza, Presence): @@ -136,7 +134,7 @@ class XEP_0153(BasePlugin): def callback(iq): if iq['type'] == 'error': - log.debug('Could not retrieve vCard for %s' % jid) + log.debug('Could not retrieve vCard for %s', jid) return data = iq['vcard_temp']['PHOTO']['BINVAL'] if not data: diff --git a/slixmpp/plugins/xep_0163.py b/slixmpp/plugins/xep_0163.py index 35f79f0d..e974a808 100644 --- a/slixmpp/plugins/xep_0163.py +++ b/slixmpp/plugins/xep_0163.py @@ -10,7 +10,6 @@ import logging from slixmpp.xmlstream import register_stanza_plugin from slixmpp.plugins.base import BasePlugin, register_plugin -from slixmpp import coroutine_wrapper log = logging.getLogger(__name__) @@ -83,9 +82,8 @@ class XEP_0163(BasePlugin): feature='%s+notify' % namespace) self.xmpp['xep_0115'].update_caps(jid) - @coroutine_wrapper def publish(self, stanza, node=None, id=None, options=None, ifrom=None, - timeout_callback=None, callback=None, timeout=None, coroutine=False): + timeout_callback=None, callback=None, timeout=None): """ Publish a PEP update. @@ -115,8 +113,7 @@ class XEP_0163(BasePlugin): options=options, ifrom=ifrom, callback=callback, timeout=timeout, - timeout_callback=timeout_callback, - coroutine=coroutine) + timeout_callback=timeout_callback) register_plugin(XEP_0163) diff --git a/slixmpp/plugins/xep_0191/blocking.py b/slixmpp/plugins/xep_0191/blocking.py index 9a6971a8..22610d78 100644 --- a/slixmpp/plugins/xep_0191/blocking.py +++ b/slixmpp/plugins/xep_0191/blocking.py @@ -9,7 +9,6 @@ import logging from slixmpp import Iq -from slixmpp import coroutine_wrapper from slixmpp.plugins import BasePlugin from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath @@ -46,18 +45,14 @@ class XEP_0191(BasePlugin): self.xmpp.remove_handler('Blocked Contact') self.xmpp.remove_handler('Unblocked Contact') - @coroutine_wrapper - def get_blocked(self, ifrom=None, timeout=None, callback=None, - coroutine=False): + def get_blocked(self, ifrom=None, timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['from'] = ifrom iq.enable('blocklist') - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) - @coroutine_wrapper - def block(self, jids, ifrom=None, timeout=None, callback=None, - coroutine=False): + def block(self, jids, ifrom=None, timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom @@ -66,11 +61,9 @@ class XEP_0191(BasePlugin): jids = [jids] iq['block']['items'] = jids - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) - @coroutine_wrapper - def unblock(self, jids=None, ifrom=None, timeout=None, callback=None, - coroutine=False): + def unblock(self, jids=None, ifrom=None, timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom @@ -81,7 +74,7 @@ class XEP_0191(BasePlugin): jids = [jids] iq['unblock']['items'] = jids - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) def _handle_blocked(self, iq): self.xmpp.event('blocked', iq) diff --git a/slixmpp/plugins/xep_0199/ping.py b/slixmpp/plugins/xep_0199/ping.py index 608bf8f8..bb2ceb38 100644 --- a/slixmpp/plugins/xep_0199/ping.py +++ b/slixmpp/plugins/xep_0199/ping.py @@ -11,7 +11,7 @@ import logging from slixmpp.jid import JID from slixmpp.stanza import Iq -from slixmpp import asyncio, coroutine_wrapper +from slixmpp import asyncio from slixmpp.exceptions import IqError, IqTimeout from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream.matcher import StanzaPath @@ -119,9 +119,8 @@ class XEP_0199(BasePlugin): log.debug("Pinged by %s", iq['from']) iq.reply().send() - @coroutine_wrapper def send_ping(self, jid, ifrom=None, timeout=None, callback=None, - timeout_callback=None, coroutine=False): + timeout_callback=None): """Send a ping request. Arguments: @@ -141,7 +140,7 @@ class XEP_0199(BasePlugin): iq['from'] = ifrom iq.enable('ping') - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine, + return iq.send(timeout=timeout, callback=callback, timeout_callback=timeout_callback) @asyncio.coroutine diff --git a/slixmpp/plugins/xep_0202/time.py b/slixmpp/plugins/xep_0202/time.py index 2c025f4a..fbf6b4f0 100644 --- a/slixmpp/plugins/xep_0202/time.py +++ b/slixmpp/plugins/xep_0202/time.py @@ -9,7 +9,6 @@ import logging from slixmpp.stanza.iq import Iq -from slixmpp import coroutine_wrapper from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath @@ -77,7 +76,6 @@ class XEP_0202(BasePlugin): iq['entity_time']['time'] = self.local_time(iq['to']) iq.send() - @coroutine_wrapper def get_entity_time(self, to, ifrom=None, **iqargs): """ Request the time from another entity. diff --git a/slixmpp/plugins/xep_0231/bob.py b/slixmpp/plugins/xep_0231/bob.py index 69e89373..b26eeede 100644 --- a/slixmpp/plugins/xep_0231/bob.py +++ b/slixmpp/plugins/xep_0231/bob.py @@ -10,7 +10,7 @@ import logging import hashlib -from slixmpp import coroutine_wrapper +from slixmpp import future_wrapper from slixmpp.stanza import Iq, Message, Presence from slixmpp.exceptions import XMPPError from slixmpp.xmlstream.handler import Callback @@ -82,9 +82,9 @@ class XEP_0231(BasePlugin): return cid - @coroutine_wrapper + @future_wrapper def get_bob(self, jid=None, cid=None, cached=True, ifrom=None, - timeout=None, callback=None, coroutine=False): + timeout=None, callback=None): if cached: data = self.api['get_bob'](None, None, ifrom, args=cid) if data is not None: @@ -99,7 +99,7 @@ class XEP_0231(BasePlugin): iq['from'] = ifrom iq['type'] = 'get' iq['bob']['cid'] = cid - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) def del_bob(self, cid): self.api['del_bob'](args=cid) diff --git a/slixmpp/plugins/xep_0257/client_cert_management.py b/slixmpp/plugins/xep_0257/client_cert_management.py index 552d5e9f..729197e0 100644 --- a/slixmpp/plugins/xep_0257/client_cert_management.py +++ b/slixmpp/plugins/xep_0257/client_cert_management.py @@ -10,7 +10,6 @@ import logging from slixmpp import Iq from slixmpp.plugins import BasePlugin -from slixmpp import coroutine_wrapper from slixmpp.xmlstream import register_stanza_plugin from slixmpp.plugins.xep_0257 import stanza, Certs from slixmpp.plugins.xep_0257 import AppendCert, DisableCert, RevokeCert @@ -32,39 +31,35 @@ class XEP_0257(BasePlugin): register_stanza_plugin(Iq, DisableCert) register_stanza_plugin(Iq, RevokeCert) - @coroutine_wrapper - def get_certs(self, ifrom=None, timeout=None, callback=None, coroutine=False): + def get_certs(self, ifrom=None, timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['from'] = ifrom iq.enable('sasl_certs') - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) - @coroutine_wrapper def add_cert(self, name, cert, allow_management=True, ifrom=None, - timeout=None, callback=None, coroutine=False): + timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom iq['sasl_cert_append']['name'] = name iq['sasl_cert_append']['x509cert'] = cert iq['sasl_cert_append']['cert_management'] = allow_management - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) - @coroutine_wrapper - def disable_cert(self, name, ifrom=None, coroutine=False, + def disable_cert(self, name, ifrom=None, timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom iq['sasl_cert_disable']['name'] = name - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) - @coroutine_wrapper - def revoke_cert(self, name, ifrom=None, coroutine=False, + def revoke_cert(self, name, ifrom=None, timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom iq['sasl_cert_revoke']['name'] = name - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(timeout=timeout, callback=callback) diff --git a/slixmpp/plugins/xep_0258/security_labels.py b/slixmpp/plugins/xep_0258/security_labels.py index 56916147..2fb048c7 100644 --- a/slixmpp/plugins/xep_0258/security_labels.py +++ b/slixmpp/plugins/xep_0258/security_labels.py @@ -9,7 +9,6 @@ import logging from slixmpp import Iq, Message -from slixmpp import coroutine_wrapper from slixmpp.plugins import BasePlugin from slixmpp.xmlstream import register_stanza_plugin from slixmpp.plugins.xep_0258 import stanza, SecurityLabel, Catalog @@ -35,12 +34,11 @@ class XEP_0258(BasePlugin): def session_bind(self, jid): self.xmpp['xep_0030'].add_feature(SecurityLabel.namespace) - @coroutine_wrapper - def get_catalog(self, jid, ifrom=None, coroutine=False, + def get_catalog(self, jid, ifrom=None, callback=None, timeout=None): iq = self.xmpp.Iq() iq['to'] = jid iq['from'] = ifrom iq['type'] = 'get' iq.enable('security_label_catalog') - return iq.send(callback=callback, timeout=timeout, coroutine=coroutine) + return iq.send(callback=callback, timeout=timeout) diff --git a/slixmpp/plugins/xep_0279/ipcheck.py b/slixmpp/plugins/xep_0279/ipcheck.py index fb748f2d..b0c0a6ca 100644 --- a/slixmpp/plugins/xep_0279/ipcheck.py +++ b/slixmpp/plugins/xep_0279/ipcheck.py @@ -10,7 +10,6 @@ import logging from slixmpp import Iq -from slixmpp import coroutine_wrapper from slixmpp.plugins import BasePlugin from slixmpp.xmlstream import register_stanza_plugin from slixmpp.plugins.xep_0279 import stanza, IPCheck @@ -32,10 +31,9 @@ class XEP_0279(BasePlugin): def plugin_end(self): self.xmpp['xep_0030'].del_feature(feature='urn:xmpp:sic:0') - @coroutine_wrapper - def check_ip(self, ifrom=None, timeout=None, callback=None, coroutine=False): + def check_ip(self, ifrom=None, block=True, timeout=None, callback=None): iq = self.xmpp.Iq() iq['type'] = 'get' iq['from'] = ifrom iq.enable('ip_check') - return iq.send(timeout=timeout, callback=callback, coroutine=coroutine) + return iq.send(block=block, timeout=timeout, callback=callback) diff --git a/slixmpp/plugins/xep_0280/carbons.py b/slixmpp/plugins/xep_0280/carbons.py index 4548a31e..a64ccbfd 100644 --- a/slixmpp/plugins/xep_0280/carbons.py +++ b/slixmpp/plugins/xep_0280/carbons.py @@ -9,7 +9,6 @@ import logging import slixmpp -from slixmpp import coroutine_wrapper from slixmpp.stanza import Message, Iq from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath @@ -67,22 +66,20 @@ class XEP_0280(BasePlugin): def _handle_carbon_sent(self, msg): self.xmpp.event('carbon_sent', msg) - @coroutine_wrapper def enable(self, ifrom=None, timeout=None, callback=None, - timeout_callback=None, coroutine=False): + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom iq.enable('carbon_enable') return iq.send(timeout_callback=timeout_callback, timeout=timeout, - callback=callback, coroutine=coroutine) + callback=callback) - @coroutine_wrapper def disable(self, ifrom=None, timeout=None, callback=None, - timeout_callback=None, coroutine=False): + timeout_callback=None): iq = self.xmpp.Iq() iq['type'] = 'set' iq['from'] = ifrom iq.enable('carbon_disable') return iq.send(timeout_callback=timeout_callback, timeout=timeout, - callback=callback, coroutine=coroutine) + callback=callback) |