[Zodb-checkins] SVN: ZODB/branches/3.3/ Forward port from Zope 2.7 branch.

Tim Peters tim.one at comcast.net
Tue Aug 17 15:46:09 EDT 2004


Log message for revision 27167:
  Forward port from Zope 2.7 branch.
  
  oid_repr():  Make it obvious which base is intended.  The output was
  3-way ambiguous.
  


Changed:
  U   ZODB/branches/3.3/NEWS.txt
  U   ZODB/branches/3.3/src/ZODB/tests/testmvcc.py
  U   ZODB/branches/3.3/src/ZODB/utils.py


-=-
Modified: ZODB/branches/3.3/NEWS.txt
===================================================================
--- ZODB/branches/3.3/NEWS.txt	2004-08-17 13:46:50 UTC (rev 27166)
+++ ZODB/branches/3.3/NEWS.txt	2004-08-17 19:46:09 UTC (rev 27167)
@@ -1,3 +1,18 @@
+What's new in ZODB3 3.3 ?
+=========================
+Release date: DD-MMM-YYYY
+
+Tools
+--------
+
+ZODB.utils.oid_repr() changed to add a leading "0x", and to strip leading
+zeroes.  This is used, e.g., in the detail of a POSKeyError exception, to
+identify the missing oid.  Before, the output was ambiguous.  For example,
+oid 17 was displayed as 0000000000000011.  As a Python integer, that's
+octal 9.  Or was it meant to be decimal 11?  Or was it meant to be hex?
+Now it displays as 0x11.
+
+
 What's new in ZODB3 3.3 beta 2
 ==============================
 Release date: 13-Aug-2004

Modified: ZODB/branches/3.3/src/ZODB/tests/testmvcc.py
===================================================================
--- ZODB/branches/3.3/src/ZODB/tests/testmvcc.py	2004-08-17 13:46:50 UTC (rev 27166)
+++ ZODB/branches/3.3/src/ZODB/tests/testmvcc.py	2004-08-17 19:46:09 UTC (rev 27167)
@@ -145,7 +145,7 @@
 >>> tm2.get().commit()
 Traceback (most recent call last):
  ...
-ConflictError: database conflict error (oid 0000000000000001, class ZODB.tests.MinPO.MinPO)
+ConflictError: database conflict error (oid 0x01, class ZODB.tests.MinPO.MinPO)
 
 The failed commit aborted the current transaction, so we can try
 again.  This example will demonstrate that we can commit a transaction
@@ -338,7 +338,7 @@
 >>> r1["b"]._p_activate()
 Traceback (most recent call last):
  ...
-ReadConflictError: database read conflict error (oid 0000000000000002, class ZODB.tests.MinPO.MinPO)
+ReadConflictError: database read conflict error (oid 0x02, class ZODB.tests.MinPO.MinPO)
 >>> oid in cn1._invalidated
 True
 >>> ts.count

Modified: ZODB/branches/3.3/src/ZODB/utils.py
===================================================================
--- ZODB/branches/3.3/src/ZODB/utils.py	2004-08-17 13:46:50 UTC (rev 27166)
+++ ZODB/branches/3.3/src/ZODB/utils.py	2004-08-17 19:46:09 UTC (rev 27167)
@@ -14,11 +14,12 @@
 
 import sys
 import time
-from persistent.TimeStamp import TimeStamp
-
 from struct import pack, unpack
 from types import StringType
+from binascii import hexlify
 
+from persistent.TimeStamp import TimeStamp
+
 z64 = '\0'*8
 t32 = 1L << 32
 
@@ -64,7 +65,14 @@
 
 def oid_repr(oid):
     if isinstance(oid, StringType) and len(oid) == 8:
-        return '%016x' % U64(oid)
+        # Convert to hex and strip leading zeroes.
+        as_hex = hexlify(oid).lstrip('0')
+        # Ensure two characters per input byte.
+        if len(as_hex) & 1:
+            as_hex = '0' + as_hex
+        elif as_hex == '':
+            as_hex = '00'
+        return '0x' + as_hex
     else:
         return repr(oid)
 



More information about the Zodb-checkins mailing list