[Zodb-checkins] CVS: Zope2/lib/python/ZODB - POSException.py:1.7

Jim Fulton jim@digicool.com
Thu, 12 Apr 2001 16:47:00 -0400 (EDT)


Update of /cvs-repository/Zope2/lib/python/ZODB
In directory korak:/tmp/cvs-serv32217

Modified Files:
	POSException.py 
Log Message:
Provided specialised string representations for UndoErrors.



--- Updated File POSException.py in package Zope2/lib/python/ZODB --
--- POSException.py	2001/02/08 22:25:59	1.6
+++ POSException.py	2001/04/12 20:47:00	1.7
@@ -87,6 +87,9 @@
 $Id$'''
 __version__='$Revision$'[11:-2]
 
+from string import join
+StringType=type('')
+DictType=type({})
 
 class POSError(Exception):
     """Persistent object system error
@@ -117,6 +120,26 @@
 class UndoError(POSError):
     """An attempt was made to undo a non-undoable transaction.
     """
+    def __init__(self, *reason):
+        if len(reason) == 1: reason=reason[0]
+        self.__reason=reason
+
+    def __repr__(self):
+        reason=self.__reason
+        if type(reason) is not DictType:
+            if reason: return str(reason)
+            return "non-undoable transaction"
+        r=[]
+        for oid, reason in reason.items():
+            if reason:
+                r.append("Couldn't undo change to %s because %s"
+                         % (`oid`, reason))
+            else:
+                r.append("Couldn't undo change to %s" % (`oid`))
+
+        return join(r,'\n')
+
+    __str__=__repr__
 
 class StorageError(POSError):
     pass