From 3463bf46c65f091f42643bc3f777ac05620192b6 Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Thu, 10 Feb 2011 13:45:35 -0800 Subject: added option to return false on ping error, added ping example --- sleekxmpp/plugins/xep_0199.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sleekxmpp/plugins/xep_0199.py') diff --git a/sleekxmpp/plugins/xep_0199.py b/sleekxmpp/plugins/xep_0199.py index 16e79e26..e7ec5c46 100644 --- a/sleekxmpp/plugins/xep_0199.py +++ b/sleekxmpp/plugins/xep_0199.py @@ -42,7 +42,7 @@ class xep_0199(base.base_plugin): iq.attrib['to'] = xml.get('from', self.xmpp.boundjid.domain) self.xmpp.send(iq) - def sendPing(self, jid, timeout = 30): + def sendPing(self, jid, timeout = 30, errorfalse=False): """ sendPing(jid, timeout) Sends a ping to the specified jid, returning the time (in seconds) to receive a reply, or None if no reply is received in timeout seconds. @@ -57,7 +57,7 @@ class xep_0199(base.base_plugin): #pingresult = self.xmpp.send(iq, self.xmpp.makeIq(id), timeout) pingresult = iq.send() endTime = time.clock() - if pingresult == False: + if pingresult == False or (errorfalse and pingresult['type'] == 'error'): #self.xmpp.disconnect(reconnect=True) return False return endTime - startTime -- cgit v1.2.3 From c4b1212c44e0758c6361ca46c6c3a90e27ac876f Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 11 Feb 2011 00:30:45 -0500 Subject: Updated XEP-0199 plugin. Now has docs and uses the new plugin format. --- sleekxmpp/plugins/xep_0199.py | 63 ------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 sleekxmpp/plugins/xep_0199.py (limited to 'sleekxmpp/plugins/xep_0199.py') diff --git a/sleekxmpp/plugins/xep_0199.py b/sleekxmpp/plugins/xep_0199.py deleted file mode 100644 index e7ec5c46..00000000 --- a/sleekxmpp/plugins/xep_0199.py +++ /dev/null @@ -1,63 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2010 Nathanael C. Fritz - This file is part of SleekXMPP. - - See the file LICENSE for copying permission. -""" -from xml.etree import cElementTree as ET -from . import base -import time -import logging - - -log = logging.getLogger(__name__) - - -class xep_0199(base.base_plugin): - """XEP-0199 XMPP Ping""" - - def plugin_init(self): - self.description = "XMPP Ping" - self.xep = "0199" - self.xmpp.add_handler("" % self.xmpp.default_ns, self.handler_ping, name='XMPP Ping') - if self.config.get('keepalive', True): - self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True) - - def post_init(self): - base.base_plugin.post_init(self) - self.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:ping') - - def handler_pingserver(self, xml): - self.xmpp.schedule("xep-0119 ping", float(self.config.get('frequency', 300)), self.scheduled_ping, repeat=True) - - def scheduled_ping(self): - log.debug("pinging...") - if self.sendPing(self.xmpp.boundjid.host, self.config.get('timeout', 30)) is False: - log.debug("Did not recieve ping back in time. Requesting Reconnect.") - self.xmpp.reconnect() - - def handler_ping(self, xml): - iq = self.xmpp.makeIqResult(xml.get('id', 'unknown')) - iq.attrib['to'] = xml.get('from', self.xmpp.boundjid.domain) - self.xmpp.send(iq) - - def sendPing(self, jid, timeout = 30, errorfalse=False): - """ sendPing(jid, timeout) - Sends a ping to the specified jid, returning the time (in seconds) - to receive a reply, or None if no reply is received in timeout seconds. - """ - id = self.xmpp.getNewId() - iq = self.xmpp.makeIq(id) - iq.attrib['type'] = 'get' - iq.attrib['to'] = jid - ping = ET.Element('{urn:xmpp:ping}ping') - iq.append(ping) - startTime = time.clock() - #pingresult = self.xmpp.send(iq, self.xmpp.makeIq(id), timeout) - pingresult = iq.send() - endTime = time.clock() - if pingresult == False or (errorfalse and pingresult['type'] == 'error'): - #self.xmpp.disconnect(reconnect=True) - return False - return endTime - startTime -- cgit v1.2.3