diff options
author | mathieui <mathieui@mathieui.net> | 2015-02-24 18:58:40 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2015-02-24 22:47:15 +0100 |
commit | c66a4d4097a249efc029b761d6150378a54bf702 (patch) | |
tree | b25d5872f0ab8036c8b05b4207b03163f4bc7868 /examples/roster_browser.py | |
parent | e112e864756f1222a044ee28e3c13c5925618b0c (diff) | |
download | slixmpp-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/roster_browser.py')
-rwxr-xr-x | examples/roster_browser.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/examples/roster_browser.py b/examples/roster_browser.py index 74d2839a..4d07de11 100755 --- a/examples/roster_browser.py +++ b/examples/roster_browser.py @@ -11,11 +11,11 @@ import logging from getpass import getpass -import threading from argparse import ArgumentParser import slixmpp from slixmpp.exceptions import IqError, IqTimeout +from slixmpp.xmlstream.asyncio import asyncio class RosterBrowser(slixmpp.ClientXMPP): @@ -36,8 +36,9 @@ class RosterBrowser(slixmpp.ClientXMPP): self.add_event_handler("changed_status", self.wait_for_presences) self.received = set() - self.presences_received = threading.Event() + self.presences_received = asyncio.Event() + @asyncio.coroutine def start(self, event): """ Process the session_start event. @@ -51,8 +52,12 @@ class RosterBrowser(slixmpp.ClientXMPP): event does not provide any additional data. """ + future = asyncio.Future() + def callback(result): + future.set_result(None) try: - self.get_roster() + self.get_roster(callback=callback) + yield from future except IqError as err: print('Error: %' % err.iq['error']['condition']) except IqTimeout: @@ -61,7 +66,7 @@ class RosterBrowser(slixmpp.ClientXMPP): print('Waiting for presence updates...\n') - self.presences_received.wait(5) + yield from asyncio.sleep(10) print('Roster for %s' % self.boundjid.bare) groups = self.client_roster.groups() |