diff options
author | mathieui <mathieui@mathieui.net> | 2015-02-23 19:30:41 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2015-02-24 22:46:05 +0100 |
commit | cd7ff685fbfe9755b8ba88ed5fd86a8450e637c1 (patch) | |
tree | 08fc8a3e36df20c61e38f80b6237fbf38137983e | |
parent | 1e4944d47e8296fdaa792a8b3fc87ea99acc217c (diff) | |
download | slixmpp-cd7ff685fbfe9755b8ba88ed5fd86a8450e637c1.tar.gz slixmpp-cd7ff685fbfe9755b8ba88ed5fd86a8450e637c1.tar.bz2 slixmpp-cd7ff685fbfe9755b8ba88ed5fd86a8450e637c1.tar.xz slixmpp-cd7ff685fbfe9755b8ba88ed5fd86a8450e637c1.zip |
XEP-0199: wrap functions with coroutine_wrapper and make ping() a coroutine
-rw-r--r-- | slixmpp/plugins/xep_0199/ping.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/slixmpp/plugins/xep_0199/ping.py b/slixmpp/plugins/xep_0199/ping.py index 92962ebe..608bf8f8 100644 --- a/slixmpp/plugins/xep_0199/ping.py +++ b/slixmpp/plugins/xep_0199/ping.py @@ -11,6 +11,7 @@ import logging from slixmpp.jid import JID from slixmpp.stanza import Iq +from slixmpp import asyncio, coroutine_wrapper from slixmpp.exceptions import IqError, IqTimeout from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream.matcher import StanzaPath @@ -118,8 +119,9 @@ 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): + timeout_callback=None, coroutine=False): """Send a ping request. Arguments: @@ -139,11 +141,13 @@ class XEP_0199(BasePlugin): iq['from'] = ifrom iq.enable('ping') - return iq.send(timeout=timeout, callback=callback, + return iq.send(timeout=timeout, callback=callback, coroutine=coroutine, timeout_callback=timeout_callback) + @asyncio.coroutine def ping(self, jid=None, ifrom=None, timeout=None): """Send a ping request and calculate RTT. + This is a coroutine. Arguments: jid -- The JID that will receive the ping. @@ -169,7 +173,8 @@ class XEP_0199(BasePlugin): log.debug('Pinging %s' % jid) try: - self.send_ping(jid, ifrom=ifrom, timeout=timeout) + yield from self.send_ping(jid, ifrom=ifrom, timeout=timeout, + coroutine=True) except IqError as e: if own_host: rtt = time.time() - start |