[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/intid/ - fix for
issue 517: intid might generate long instead of int which
conflicts with btrees
Christian Theune
cvs-admin at zope.org
Sat Jun 17 00:10:41 EDT 2006
Log message for revision 68701:
- fix for issue 517: intid might generate long instead of int which conflicts with btrees
Changed:
U Zope3/trunk/src/zope/app/intid/__init__.py
U Zope3/trunk/src/zope/app/intid/tests.py
-=-
Modified: Zope3/trunk/src/zope/app/intid/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/intid/__init__.py 2006-06-17 04:10:29 UTC (rev 68700)
+++ Zope3/trunk/src/zope/app/intid/__init__.py 2006-06-17 04:10:38 UTC (rev 68701)
@@ -47,7 +47,10 @@
"""
implements(IIntIds)
- _v_nextid = None
+ _v_nextid = None
+
+ # Used for testability of random function
+ __randint__ = random.randint
def __init__(self):
self.ids = OIBTree.OIBTree()
@@ -97,11 +100,16 @@
"""
while True:
if self._v_nextid is None:
- self._v_nextid = random.randint(0, 2**31)
+ self._v_nextid = self.__randint__(0, 2**31)
uid = self._v_nextid
self._v_nextid += 1
- if uid not in self.refs:
- return uid
+ try:
+ if uid not in self.refs:
+ return uid
+ except TypeError:
+ # uid was a long instead of int and btree complained
+ # we just try again
+ pass
self._v_nextid = None
def register(self, ob):
Modified: Zope3/trunk/src/zope/app/intid/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/intid/tests.py 2006-06-17 04:10:29 UTC (rev 68700)
+++ Zope3/trunk/src/zope/app/intid/tests.py 2006-06-17 04:10:38 UTC (rev 68701)
@@ -107,6 +107,25 @@
self.assertRaises(KeyError, u.getObject, uid)
self.assertRaises(KeyError, u.getId, obj)
+ def test_btree_long(self):
+ u = IntIds()
+
+ fake_randint_data = [2**31,20,2**31-1,2**31-2,10]
+
+ def fake_randint(min, max):
+ return fake_randint_data.pop(0)
+
+ u.__randint__ = fake_randint
+
+ # One int that is too large
+ uid1 = u._generateId()
+ self.assertEquals(20, uid1)
+
+ # Two ints that are too large
+ u._v_nextid = None
+ uid2 = u._generateId()
+ self.assertEquals(10, uid2)
+
def test_len_items(self):
u = IntIds()
obj = P()
More information about the Zope3-Checkins
mailing list