mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
fixed indent errors
This commit is contained in:
parent
1bf34caa5b
commit
38c2f51f83
2 changed files with 43 additions and 41 deletions
|
@ -11,49 +11,49 @@ import time
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
class xep_0199(base.base_plugin):
|
class xep_0199(base.base_plugin):
|
||||||
"""XEP-0199 XMPP Ping"""
|
"""XEP-0199 XMPP Ping"""
|
||||||
|
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
self.description = "XMPP Ping"
|
self.description = "XMPP Ping"
|
||||||
self.xep = "0199"
|
self.xep = "0199"
|
||||||
self.xmpp.add_handler("<iq type='get' xmlns='%s'><ping xmlns='urn:xmpp:ping'/></iq>" % self.xmpp.default_ns, self.handler_ping, name='XMPP Ping')
|
self.xmpp.add_handler("<iq type='get' xmlns='%s'><ping xmlns='urn:xmpp:ping'/></iq>" % self.xmpp.default_ns, self.handler_ping, name='XMPP Ping')
|
||||||
self.running = False
|
self.running = False
|
||||||
if self.config.get('keepalive', True):
|
if self.config.get('keepalive', True):
|
||||||
self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True)
|
self.xmpp.add_event_handler('session_start', self.handler_pingserver, threaded=True)
|
||||||
|
|
||||||
def post_init(self):
|
def post_init(self):
|
||||||
base.base_plugin.post_init(self)
|
base.base_plugin.post_init(self)
|
||||||
self.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:ping')
|
self.xmpp.plugin['xep_0030'].add_feature('urn:xmpp:ping')
|
||||||
|
|
||||||
def handler_pingserver(self, xml):
|
def handler_pingserver(self, xml):
|
||||||
if not self.running:
|
if not self.running:
|
||||||
time.sleep(self.config.get('frequency', 300))
|
time.sleep(self.config.get('frequency', 300))
|
||||||
while self.sendPing(self.xmpp.server, self.config.get('timeout', 30)) is not False:
|
while self.sendPing(self.xmpp.server, self.config.get('timeout', 30)) is not False:
|
||||||
time.sleep(self.config.get('frequency', 300))
|
time.sleep(self.config.get('frequency', 300))
|
||||||
logging.debug("Did not recieve ping back in time. Requesting Reconnect.")
|
logging.debug("Did not recieve ping back in time. Requesting Reconnect.")
|
||||||
self.xmpp.disconnect(reconnect=True)
|
self.xmpp.disconnect(reconnect=True)
|
||||||
|
|
||||||
def handler_ping(self, xml):
|
def handler_ping(self, xml):
|
||||||
iq = self.xmpp.makeIqResult(xml.get('id', 'unknown'))
|
iq = self.xmpp.makeIqResult(xml.get('id', 'unknown'))
|
||||||
iq.attrib['to'] = xml.get('from', self.xmpp.boundjid.domain)
|
iq.attrib['to'] = xml.get('from', self.xmpp.boundjid.domain)
|
||||||
self.xmpp.send(iq)
|
self.xmpp.send(iq)
|
||||||
|
|
||||||
def sendPing(self, jid, timeout = 30):
|
def sendPing(self, jid, timeout = 30):
|
||||||
""" sendPing(jid, timeout)
|
""" sendPing(jid, timeout)
|
||||||
Sends a ping to the specified jid, returning the time (in seconds)
|
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.
|
to receive a reply, or None if no reply is received in timeout seconds.
|
||||||
"""
|
"""
|
||||||
id = self.xmpp.getNewId()
|
id = self.xmpp.getNewId()
|
||||||
iq = self.xmpp.makeIq(id)
|
iq = self.xmpp.makeIq(id)
|
||||||
iq.attrib['type'] = 'get'
|
iq.attrib['type'] = 'get'
|
||||||
iq.attrib['to'] = jid
|
iq.attrib['to'] = jid
|
||||||
ping = ET.Element('{urn:xmpp:ping}ping')
|
ping = ET.Element('{urn:xmpp:ping}ping')
|
||||||
iq.append(ping)
|
iq.append(ping)
|
||||||
startTime = time.clock()
|
startTime = time.clock()
|
||||||
#pingresult = self.xmpp.send(iq, self.xmpp.makeIq(id), timeout)
|
#pingresult = self.xmpp.send(iq, self.xmpp.makeIq(id), timeout)
|
||||||
pingresult = iq.send()
|
pingresult = iq.send()
|
||||||
endTime = time.clock()
|
endTime = time.clock()
|
||||||
if pingresult == False:
|
if pingresult == False:
|
||||||
#self.xmpp.disconnect(reconnect=True)
|
#self.xmpp.disconnect(reconnect=True)
|
||||||
return False
|
return False
|
||||||
return endTime - startTime
|
return endTime - startTime
|
||||||
|
|
|
@ -828,6 +828,8 @@ class XMLStream(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
func(*args)
|
func(*args)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def _event_runner(self):
|
def _event_runner(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue