diff options
Diffstat (limited to 'sleekxmpp/plugins/xep_0199')
-rw-r--r-- | sleekxmpp/plugins/xep_0199/ping.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/sleekxmpp/plugins/xep_0199/ping.py b/sleekxmpp/plugins/xep_0199/ping.py index 0fa22f8a..b0304b09 100644 --- a/sleekxmpp/plugins/xep_0199/ping.py +++ b/sleekxmpp/plugins/xep_0199/ping.py @@ -11,6 +11,7 @@ import logging import sleekxmpp from sleekxmpp import Iq +from sleekxmpp.exceptions import IqError, IqTimeout from sleekxmpp.xmlstream import register_stanza_plugin from sleekxmpp.xmlstream.matcher import StanzaPath from sleekxmpp.xmlstream.handler import Callback @@ -89,8 +90,13 @@ class xep_0199(base_plugin): def scheduled_ping(): """Send ping request to the server.""" log.debug("Pinging...") - resp = self.send_ping(self.xmpp.boundjid.host, self.timeout) - if resp is None or resp is False: + try: + self.send_ping(self.xmpp.boundjid.host, self.timeout) + except IqError: + log.debug("Ping response was an error." + \ + "Requesting Reconnect.") + self.xmpp.reconnect() + except IqTimeout: log.debug("Did not recieve ping back in time." + \ "Requesting Reconnect.") self.xmpp.reconnect() @@ -142,9 +148,14 @@ class xep_0199(base_plugin): iq.enable('ping') start_time = time.clock() - resp = iq.send(block=block, - timeout=timeout, - callback=callback) + + try: + resp = iq.send(block=block, + timeout=timeout, + callback=callback) + except IqError as err: + resp = err.iq + end_time = time.clock() delay = end_time - start_time @@ -152,9 +163,6 @@ class xep_0199(base_plugin): if not block: return None - if not resp or resp['type'] == 'error': - return False - log.debug("Pong: %s %f" % (jid, delay)) return delay |