summaryrefslogtreecommitdiff
path: root/examples/set_avatar.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-02-24 18:58:40 +0100
committermathieui <mathieui@mathieui.net>2015-02-24 22:47:15 +0100
commitc66a4d4097a249efc029b761d6150378a54bf702 (patch)
treeb25d5872f0ab8036c8b05b4207b03163f4bc7868 /examples/set_avatar.py
parente112e864756f1222a044ee28e3c13c5925618b0c (diff)
downloadslixmpp-c66a4d4097a249efc029b761d6150378a54bf702.tar.gz
slixmpp-c66a4d4097a249efc029b761d6150378a54bf702.tar.bz2
slixmpp-c66a4d4097a249efc029b761d6150378a54bf702.tar.xz
slixmpp-c66a4d4097a249efc029b761d6150378a54bf702.zip
Update the documentation and examples
- update most of the examples with slixmpp - change the help channels pointed out in the doc - add a page listing differences from slixmpp and how to use asyncio nicely with slixmpp - fix some in-code rst documentation
Diffstat (limited to 'examples/set_avatar.py')
-rwxr-xr-xexamples/set_avatar.py46
1 files changed, 23 insertions, 23 deletions
diff --git a/examples/set_avatar.py b/examples/set_avatar.py
index 9a050e5a..5805d18a 100755
--- a/examples/set_avatar.py
+++ b/examples/set_avatar.py
@@ -18,7 +18,7 @@ from argparse import ArgumentParser
import slixmpp
from slixmpp.exceptions import XMPPError
-
+from slixmpp import asyncio
class AvatarSetter(slixmpp.ClientXMPP):
@@ -33,6 +33,7 @@ class AvatarSetter(slixmpp.ClientXMPP):
self.filepath = filepath
+ @asyncio.coroutine
def start(self, event):
"""
Process the session_start event.
@@ -51,7 +52,7 @@ class AvatarSetter(slixmpp.ClientXMPP):
avatar_file = None
try:
- avatar_file = open(os.path.expanduser(self.filepath))
+ avatar_file = open(os.path.expanduser(self.filepath), 'rb')
except IOError:
print('Could not find file: %s' % self.filepath)
return self.disconnect()
@@ -65,32 +66,31 @@ class AvatarSetter(slixmpp.ClientXMPP):
avatar_file.close()
used_xep84 = False
- try:
- print('Publish XEP-0084 avatar data')
- self['xep_0084'].publish_avatar(avatar)
- used_xep84 = True
- except XMPPError:
+
+ print('Publish XEP-0084 avatar data')
+ result = yield from self['xep_0084'].publish_avatar(avatar, coroutine=True)
+ if isinstance(result, XMPPError):
print('Could not publish XEP-0084 avatar')
+ else:
+ used_xep84 = True
- try:
- print('Update vCard with avatar')
- self['xep_0153'].set_avatar(avatar=avatar, mtype=avatar_type)
- except XMPPError:
+ print('Update vCard with avatar')
+ result = yield from self['xep_0153'].set_avatar(avatar=avatar, mtype=avatar_type, coroutine=True)
+ if isinstance(result, XMPPError):
print('Could not set vCard avatar')
if used_xep84:
- try:
- print('Advertise XEP-0084 avatar metadata')
- self['xep_0084'].publish_avatar_metadata([
- {'id': avatar_id,
- 'type': avatar_type,
- 'bytes': avatar_bytes}
- # We could advertise multiple avatars to provide
- # options in image type, source (HTTP vs pubsub),
- # size, etc.
- # {'id': ....}
- ])
- except XMPPError:
+ print('Advertise XEP-0084 avatar metadata')
+ result = yield from self['xep_0084'].publish_avatar_metadata([
+ {'id': avatar_id,
+ 'type': avatar_type,
+ 'bytes': avatar_bytes}
+ # We could advertise multiple avatars to provide
+ # options in image type, source (HTTP vs pubsub),
+ # size, etc.
+ # {'id': ....}
+ ], coroutine=True)
+ if isinstance(result, XMPPError):
print('Could not publish XEP-0084 metadata')
print('Wait for presence updates to propagate...')