From cd7ff685fbfe9755b8ba88ed5fd86a8450e637c1 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 23 Feb 2015 19:30:41 +0100 Subject: XEP-0199: wrap functions with coroutine_wrapper and make ping() a coroutine --- slixmpp/plugins/xep_0199/ping.py | 11 ++++++++--- 1 file 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 -- cgit v1.2.3