diff options
author | Lance Stout <lancestout@gmail.com> | 2011-08-17 21:30:47 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2011-08-17 21:30:47 -0700 |
commit | 004eabf80959ebcaeddf2e15065bd4f50ad10974 (patch) | |
tree | e62c243c6b1a539a0fa71030011eb88762068b6b /sleekxmpp/plugins/xep_0199 | |
parent | 62230fc970f86b11bc74ee448e30cbe93f477e72 (diff) | |
download | slixmpp-004eabf80959ebcaeddf2e15065bd4f50ad10974.tar.gz slixmpp-004eabf80959ebcaeddf2e15065bd4f50ad10974.tar.bz2 slixmpp-004eabf80959ebcaeddf2e15065bd4f50ad10974.tar.xz slixmpp-004eabf80959ebcaeddf2e15065bd4f50ad10974.zip |
Update plugins that use Iq stanzas to work with new exceptions.
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 |