From 004eabf80959ebcaeddf2e15065bd4f50ad10974 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 17 Aug 2011 21:30:47 -0700 Subject: Update plugins that use Iq stanzas to work with new exceptions. --- sleekxmpp/plugins/xep_0199/ping.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'sleekxmpp/plugins/xep_0199/ping.py') 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 -- cgit v1.2.3