4 ''' Generic ILS event object '''
7 def __init__(self, evt_hash={}):
8 self.code = evt_hash.get('ilsevent') or -1
9 self.text_code = evt_hash.get('textcode') or ''
10 self.desc = evt_hash.get('desc') or ''
11 self.payload = evt_hash.get('payload') or None
12 self.debug = evt_hash.get('stacktrace') or ''
13 self.servertime = evt_hash.get('servertime') or ''
16 if self.code == int(0):
20 return '%s: %s:%s -> %s' % (
21 self.__class__.__name__, self.code, self.text_code, self.desc)
23 # XXX eventually, add events file parsing...
26 return EventException(unicode(self))
30 def parse_event(evt=None):
31 ''' If the provided evt object is a dictionary object that looks
32 like an ILS event, construct an Event object and return it.
33 Returns None otherwise. '''
35 if isinstance(evt, dict) and 'ilsevent' in evt and 'textcode' in evt:
41 def parse_and_raise(evt=None):
42 ''' Parses with parse_event. If the resulting event is a non-success
43 event, it is converted to an exception and raised '''
44 evt = Event.parse_event(evt)
45 if evt and not evt.success:
49 class EventException(osrf.ex.OSRFException):
50 ''' A throw-able exception wrapper for events '''