Maintenance will be performed on git.ligo.org, chat.ligo.org, containers.ligo.org, and docs.ligo.org 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 uwm-help@cgca.uwm.edu.

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):
else:
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):
@functools.wraps(f)
def func(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception as e:
print 'Caught an exception in', f.__name__, ":"
print(e)
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)
@catch_exception
def _pubsub_publish(self, msg):
self._callback(msg['pubsub_event']['items']['node'],
msg['pubsub_event']['items']['item']['payload'].text)
if msg['type'] in ('chat', 'normal'):
self._callback(msg['pubsub_event']['items']['node'],
msg['pubsub_event']['items']['item']['payload'].text)
@property
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='http://jabber.org/protocol/pubsub#event'>%s</pubsub>"
xmlmsg = sleekxmpp.ET.fromstring("<pubsub xmlns='http://jabber.org/protocol/pubsub'>%s</pubsub>"
% msg)
try:
result = self['xep_0060'].publish(self._pubsub_server, node,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment