[Zodb-checkins] CVS: Zope/lib/python/ZODB - BaseStorage.py:1.34 POSException.py:1.20 Transaction.py:1.49 utils.py:1.17

Shane Hathaway shane at zope.com
Tue Jun 10 12:46:32 EDT 2003


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv509

Modified Files:
	BaseStorage.py POSException.py Transaction.py utils.py 
Log Message:
Merged shane-oid-length-branch.

ZODB now makes no assumptions about the length of OIDs (although
storages can make such assumptions if they need to.)  Added an
oid_repr utility function to print both 8-byte OIDs and other OIDs in
a reasonable way.



=== Zope/lib/python/ZODB/BaseStorage.py 1.33 => 1.34 ===
--- Zope/lib/python/ZODB/BaseStorage.py:1.33	Tue Feb  4 12:17:29 2003
+++ Zope/lib/python/ZODB/BaseStorage.py	Tue Jun 10 11:46:31 2003
@@ -303,7 +303,7 @@
             self.tpc_begin(transaction, tid, transaction.status)
             for r in transaction:
                 oid=r.oid
-                if verbose: print `oid`, r.version, len(r.data)
+                if verbose: print oid_repr(oid), r.version, len(r.data)
                 if restoring:
                     self.restore(oid, r.serial, r.data, r.version,
                                  r.data_txn, transaction)


=== Zope/lib/python/ZODB/POSException.py 1.19 => 1.20 ===
--- Zope/lib/python/ZODB/POSException.py:1.19	Wed Jan 15 18:00:05 2003
+++ Zope/lib/python/ZODB/POSException.py	Tue Jun 10 11:46:31 2003
@@ -16,16 +16,11 @@
 $Id$"""
 
 from types import StringType, DictType
-import ZODB.utils
-
-def _fmt_oid(oid):
-    if oid:
-        return "%016x" % ZODB.utils.u64(oid)
-    return oid
+from ZODB.utils import oid_repr, serial_repr
 
 def _fmt_undo(oid, reason):
     s = reason and (": %s" % reason) or ""
-    return "Undo error %s%s" % (_fmt_oid(oid), s)
+    return "Undo error %s%s" % (oid_repr(oid), s)
 
 class POSError(StandardError):
     """Persistent object system error."""
@@ -34,7 +29,7 @@
     """Key not found in database."""
 
     def __str__(self):
-        return _fmt_oid(self.args[0])
+        return oid_repr(self.args[0])
 
 class TransactionError(POSError):
     """An error occured due to normal transaction processing."""
@@ -85,12 +80,12 @@
     def __str__(self):
         extras = []
         if self.oid:
-            extras.append("oid %s" % _fmt_oid(self.oid))
+            extras.append("oid %s" % oid_repr(self.oid))
         if self.class_name:
             extras.append("class %s" % self.class_name)
         if self.serials:
             extras.append("serial was %s, now %s" %
-                          tuple(map(_fmt_oid, self.serials)))
+                          tuple(map(serial_repr, self.serials)))
         if extras:
             return "%s (%s)" % (self.message, ", ".join(extras))
         else:
@@ -150,8 +145,8 @@
         self.missing = Boid
 
     def __str__(self):
-        return "from %s to %s" % (_fmt_oid(self.referer),
-                                  _fmt_oid(self.missing))
+        return "from %s to %s" % (oid_repr(self.referer),
+                                  oid_repr(self.missing))
 
 class VersionError(POSError):
     """An error in handling versions occurred."""


=== Zope/lib/python/ZODB/Transaction.py 1.48 => 1.49 ===
--- Zope/lib/python/ZODB/Transaction.py:1.48	Thu Mar  6 19:11:10 2003
+++ Zope/lib/python/ZODB/Transaction.py	Tue Jun 10 11:46:31 2003
@@ -17,10 +17,10 @@
 """
 
 import time, sys, struct, POSException
-from struct import pack
 from string import split, strip, join
 from zLOG import LOG, ERROR, PANIC, INFO, BLATHER, WARNING
 from POSException import ConflictError
+from utils import oid_repr
 
 # Flag indicating whether certain errors have occurred.
 hosed=0
@@ -138,7 +138,7 @@
                         t, v, tb = sys.exc_info()
                     else:
                         self.log("Failed to abort object %s" %
-                                 repr(o._p_oid), error=sys.exc_info())
+                                 oid_repr(o._p_oid), error=sys.exc_info())
 
             # tpc_begin() was never called, so tpc_abort() should not be
             # called.
@@ -390,7 +390,7 @@
                     j.abort(o, self)
             except:
                 # nothing to do but log the error
-                self.log("Failed to abort object %s" % repr(o._p_oid),
+                self.log("Failed to abort object %s" % oid_repr(o._p_oid),
                          error=sys.exc_info())
 
         # Abort the two-phase commit.  It's only necessary to abort the


=== Zope/lib/python/ZODB/utils.py 1.16 => 1.17 ===
--- Zope/lib/python/ZODB/utils.py:1.16	Tue Jan 14 13:00:32 2003
+++ Zope/lib/python/ZODB/utils.py	Tue Jun 10 11:46:31 2003
@@ -16,6 +16,7 @@
 import TimeStamp, time
 
 from struct import pack, unpack
+from types import StringType
 
 z64 = '\0'*8
 t32 = 1L << 32
@@ -86,3 +87,13 @@
     if old is not None:
         return ts.laterThan(old)
     return ts
+
+
+def oid_repr(oid):
+    if isinstance(oid, StringType) and len(oid) == 8:
+        return '%016x' % U64(oid)
+    else:
+        return repr(oid)
+
+serial_repr = oid_repr
+




More information about the Zodb-checkins mailing list