[open-ils-commits] r8402 - trunk/Open-ILS/src/python/oils
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Jan 17 13:23:16 EST 2008
Author: erickson
Date: 2008-01-17 12:57:34 -0500 (Thu, 17 Jan 2008)
New Revision: 8402
Modified:
trunk/Open-ILS/src/python/oils/event.py
Log:
added a to_ex method to turn the event into an exception and a runtime raise_and_parse method for 1-line event handling
Modified: trunk/Open-ILS/src/python/oils/event.py
===================================================================
--- trunk/Open-ILS/src/python/oils/event.py 2008-01-17 17:56:49 UTC (rev 8401)
+++ trunk/Open-ILS/src/python/oils/event.py 2008-01-17 17:57:34 UTC (rev 8402)
@@ -1,3 +1,4 @@
+import osrf.ex
class Event(object):
''' Generic ILS event object '''
@@ -2,2 +3,3 @@
+
def __init__(self, evt_hash={}):
@@ -20,6 +22,10 @@
# 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 @@
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
+
More information about the open-ils-commits
mailing list