From 2b976ffce8d126f5ecfd232701cf0729f5cf16d6 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 17 Jan 2008 17:57:34 +0000 Subject: [PATCH] added a to_ex method to turn the event into an exception and a runtime raise_and_parse method for 1-line event handling git-svn-id: svn://svn.open-ils.org/ILS/trunk@8402 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/python/oils/event.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Open-ILS/src/python/oils/event.py b/Open-ILS/src/python/oils/event.py index e8f2481650..db64481d45 100644 --- a/Open-ILS/src/python/oils/event.py +++ b/Open-ILS/src/python/oils/event.py @@ -1,7 +1,9 @@ +import osrf.ex class Event(object): ''' Generic ILS event object ''' + def __init__(self, evt_hash={}): self.code = evt_hash.get('ilsevent') or -1 self.text_code = evt_hash.get('textcode') or '' @@ -20,6 +22,10 @@ class Event(object): # XXX eventually, add events file parsing... + def to_ex(self): + return EventException(unicode(self)) + + @staticmethod def parse_event(evt=None): ''' If the provided evt object is a dictionary object that looks @@ -30,3 +36,17 @@ class Event(object): return Event(evt) return None + + @staticmethod + def parse_and_raise(evt=None): + ''' Parses with parse_event. If the resulting event is a non-success + event, it is converted to an exception and raised ''' + evt = Event.parse_event(evt) + if evt and not evt.success: + raise evt.to_ex() + + +class EventException(osrf.ex.OSRFException): + ''' A throw-able exception wrapper for events ''' + pass + -- 2.11.0