summaryrefslogtreecommitdiff
path: root/examples/download_avatars.py
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-08-19 17:47:26 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-08-19 17:47:26 +0100
commit9f6fa6513946e78de6e77a7e924fedc84c89ad25 (patch)
tree079a4f43a51cb7b4242c87aaa41810a30be11644 /examples/download_avatars.py
parent35fa33e3c232377acf77805d858a4efec54180ca (diff)
downloadslixmpp-9f6fa6513946e78de6e77a7e924fedc84c89ad25.tar.gz
slixmpp-9f6fa6513946e78de6e77a7e924fedc84c89ad25.tar.bz2
slixmpp-9f6fa6513946e78de6e77a7e924fedc84c89ad25.tar.xz
slixmpp-9f6fa6513946e78de6e77a7e924fedc84c89ad25.zip
examples, tests: Replace all @asyncio.coroutines with proper async functions.
Diffstat (limited to 'examples/download_avatars.py')
-rwxr-xr-xexamples/download_avatars.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/examples/download_avatars.py b/examples/download_avatars.py
index 408c2146..02591e3e 100755
--- a/examples/download_avatars.py
+++ b/examples/download_avatars.py
@@ -47,8 +47,7 @@ class AvatarDownloader(slixmpp.ClientXMPP):
self.roster_received.set()
self.presences_received.clear()
- @asyncio.coroutine
- def start(self, event):
+ async def start(self, event):
"""
Process the session_start event.
@@ -65,16 +64,15 @@ class AvatarDownloader(slixmpp.ClientXMPP):
self.get_roster(callback=self.roster_received_cb)
print('Waiting for presence updates...\n')
- yield from self.roster_received.wait()
+ await self.roster_received.wait()
print('Roster received')
- yield from self.presences_received.wait()
+ await self.presences_received.wait()
self.disconnect()
- @asyncio.coroutine
- def on_vcard_avatar(self, pres):
+ async def on_vcard_avatar(self, pres):
print("Received vCard avatar update from %s" % pres['from'].bare)
try:
- result = yield from self['xep_0054'].get_vcard(pres['from'].bare, cached=True,
+ result = await self['xep_0054'].get_vcard(pres['from'].bare, cached=True,
timeout=5)
except XMPPError:
print("Error retrieving avatar for %s" % pres['from'])
@@ -89,14 +87,13 @@ class AvatarDownloader(slixmpp.ClientXMPP):
with open(filename, 'wb+') as img:
img.write(avatar['BINVAL'])
- @asyncio.coroutine
- def on_avatar(self, msg):
+ async def on_avatar(self, msg):
print("Received avatar update from %s" % msg['from'])
metadata = msg['pubsub_event']['items']['item']['avatar_metadata']
for info in metadata['items']:
if not info['url']:
try:
- result = yield from self['xep_0084'].retrieve_avatar(msg['from'].bare, info['id'],
+ result = await self['xep_0084'].retrieve_avatar(msg['from'].bare, info['id'],
timeout=5)
except XMPPError:
print("Error retrieving avatar for %s" % msg['from'])