summaryrefslogtreecommitdiff
path: root/slixmpp/plugins/xep_0153/vcard_avatar.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-02-28 13:22:19 +0100
committermathieui <mathieui@mathieui.net>2015-02-28 19:02:49 +0100
commit997928de9140a4ac0a10a42883dbf18aca4aeec6 (patch)
tree4cd83ac161b4da491159412c95c84e9f0db41135 /slixmpp/plugins/xep_0153/vcard_avatar.py
parent83d00a5913e6b7ef71de602e793b3973866c7120 (diff)
downloadslixmpp-997928de9140a4ac0a10a42883dbf18aca4aeec6.tar.gz
slixmpp-997928de9140a4ac0a10a42883dbf18aca4aeec6.tar.bz2
slixmpp-997928de9140a4ac0a10a42883dbf18aca4aeec6.tar.xz
slixmpp-997928de9140a4ac0a10a42883dbf18aca4aeec6.zip
Revert or edit most previous XEP plugin changes
In a single commit, because it isn’t that interesting to detail each change. List of reverts: Revert "XEP-0030: allow get_info and get_items to return a coroutine" This reverts commit 506ca6991790cffb90c5b6e3b765237ccc136e1a. Revert "XEP-0060: wrap all iq-sending functions with coroutine_wrapper" This reverts commit e85fa4203e0ee7108d8d37f73913c21628e3d6fc. Revert "XEP-0163: wrap publish() with coroutine_wrapper" This reverts commit 69da1c1d7cf7a1c0dbbeeb83f528b4e5f5b5be0c. Revert "XEP-0084: wrap functions with coroutine_wrapper" This reverts commit ea5615f236bd80fb4217398977833ca790cbef71. Partially revert 3d243f7 (XEP-0054) - continue wrapping functions but with future_wrapper Partially revert 115fe95 (xep-0153) - use callbacks rather than coroutine callbacks, and propagate iqtimeouts in set_avatar. Revert "XEP-0049: wrap functions with coroutine_wrapper" This reverts commit e68135f59f9a224688679eb91e8063041d6f000b. Revert "XEP-0077: wrap functions with coroutine_wrapper" This reverts commit 1e4944d47e8296fdaa792a8b3fc87ea99acc217c. Partially revert cd7ff685 (XEP-0199) - remove the iq.send wrapping but keep ping() as a coroutine Revert "XEP-0257: wrap functions with coroutine_wrapper" This reverts commit 4da870fd191697d010e677eee32ef86439967353. Revert "XEP-0092: wrap get_version() with coroutine_wrapper" This reverts commit 6e35948276c36ea2696f0de64dc179a1073ee3a6. Revert "XEP-0191: wrap functions with coroutine_wrapper" This reverts commit 6e8235544cc1bdefea75a8d93e5e3a48a13552ba. Revert "XEP-0280: wrap functions with coroutine_wrapper" This reverts commit f795ac02e322445be13077463638924d1f22d313. Revert "XEP-0012: wrap get_last_activity() with coroutine_wrapper" This reverts commit 2ee05d9616d2959d19a7a87d21c58e6aae1db56e. Revert "XEP-0202: wrap get_entity_time() with coroutine_wrapper" This reverts commit 6fb3ecd414f24374f17811d7ad2fd01e4924e311. Revert "XEP-0231: wrap get_bob() with coroutine_wrapper" This reverts commit 17464b10a42d9b3c4daba763e06e53c429478abd. Revert "XEP-0258: wrap get_catalog() with coroutine_wrapper" This reverts commit 18a4978456a33e6ea38de1e07b1aa43bcc10d45f. Revert "XEP-0050: wrap send_command() and get_commands() with coroutine_wrapper" This reverts commit e034b31d6bc34f43578456e9c6527bc56dff78e3. Revert "XEP-0279: wrap check_ip() with coroutine_wrapper" This reverts commit e112e864756f1222a044ee28e3c13c5925618b0c.
Diffstat (limited to 'slixmpp/plugins/xep_0153/vcard_avatar.py')
-rw-r--r--slixmpp/plugins/xep_0153/vcard_avatar.py72
1 files changed, 35 insertions, 37 deletions
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: