Commit c1685965 authored by Tim Peters's avatar Tim Peters

Forward port from Zope 2.7 branch.

oid_repr():  Make it obvious which base is intended.  The output was
3-way ambiguous.
parent 4dafd7e9
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 What's new in ZODB3 3.3 beta 2
============================== ==============================
Release date: 13-Aug-2004 Release date: 13-Aug-2004
......
...@@ -145,7 +145,7 @@ commit the transaction. ...@@ -145,7 +145,7 @@ commit the transaction.
>>> tm2.get().commit() >>> tm2.get().commit()
Traceback (most recent call last): 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 The failed commit aborted the current transaction, so we can try
again. This example will demonstrate that we can commit a transaction again. This example will demonstrate that we can commit a transaction
...@@ -338,7 +338,7 @@ False ...@@ -338,7 +338,7 @@ False
>>> r1["b"]._p_activate() >>> r1["b"]._p_activate()
Traceback (most recent call last): 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 >>> oid in cn1._invalidated
True True
>>> ts.count >>> ts.count
......
...@@ -14,10 +14,11 @@ ...@@ -14,10 +14,11 @@
import sys import sys
import time import time
from persistent.TimeStamp import TimeStamp
from struct import pack, unpack from struct import pack, unpack
from types import StringType from types import StringType
from binascii import hexlify
from persistent.TimeStamp import TimeStamp
z64 = '\0'*8 z64 = '\0'*8
t32 = 1L << 32 t32 = 1L << 32
...@@ -64,7 +65,14 @@ def newTimeStamp(old=None, ...@@ -64,7 +65,14 @@ def newTimeStamp(old=None,
def oid_repr(oid): def oid_repr(oid):
if isinstance(oid, StringType) and len(oid) == 8: 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: else:
return repr(oid) return repr(oid)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment