Maintenance will be performed on,,, and on Tuesday 26 May 2020 starting at approximately 10am CDT. It is expected to take around 30 minutes and will involve a short period of downtime, around 5 minutes, towards the end of the maintenance period. Please address any questions, comments, or concerns to

Commit f667f482 authored by Alexander Pace's avatar Alexander Pace

Added more robust exception trapping for xml stream continuity

parent 1ed8bb68
Pipeline #46534 failed with stages
in 3 minutes and 51 seconds
......@@ -27,11 +27,13 @@ import uuid
import ssl
import pkg_resources
#from ligo.lvalert.utils.safe_netrc import NetrcParseError
from ligo.lvalert.utils import safe_netrc as _netrc
import sleekxmpp
# Experimental error trapping:
import functools
__all__ = ('LVAlertClient',)
log = logging.getLogger(__name__)
......@@ -79,6 +81,18 @@ def _get_login(username, password, netrc, interactive, server):
raise RuntimeError('Password not specified')
#-- The purpose of this function is to catch exceptions from
#-- external functions before they get caught in the xml stream
def catch_exception(f):
def func(*args, **kwargs):
return f(*args, **kwargs)
except Exception as e:
print 'Caught an exception in', f.__name__, ":"
return func
class LVAlertClient(sleekxmpp.ClientXMPP):
"""An XMPP client configured for LVAlert.
......@@ -165,9 +179,11 @@ class LVAlertClient(sleekxmpp.ClientXMPP):
self._callback = callback
self.add_event_handler('pubsub_publish', self._pubsub_publish)
def _pubsub_publish(self, msg):
if msg['type'] in ('chat', 'normal'):
def _pubsub_server(self):
......@@ -206,7 +222,7 @@ class LVAlertClient(sleekxmpp.ClientXMPP):
def publish(self, node, msg=None):
"""Publish a message to one or more pubsub nodes."""
xmlmsg = sleekxmpp.ET.fromstring("<pubsub xmlns=''>%s</pubsub>"
xmlmsg = sleekxmpp.ET.fromstring("<pubsub xmlns=''>%s</pubsub>"
% msg)
result = self['xep_0060'].publish(self._pubsub_server, node,
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment