[Checkins] SVN: Zope3/branches/3.3/ - 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:32 EDT 2006


Log message for revision 68700:
   - fix for issue 517: intid might generate long instead of int which conflicts with btrees
  

Changed:
  U   Zope3/branches/3.3/doc/CHANGES.txt
  U   Zope3/branches/3.3/src/zope/app/intid/__init__.py
  U   Zope3/branches/3.3/src/zope/app/intid/tests.py

-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2006-06-17 03:29:43 UTC (rev 68699)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2006-06-17 04:10:29 UTC (rev 68700)
@@ -10,6 +10,9 @@
 
     Bugfixes
 
+      - Fixed issue 517: Bug in intid that doesn't respect that BTrees can not
+        handle long.
+
       - Fixed issue 399: traversal of missing skins now give 404 / NotFound
         instead of 505 / ComponentLookupError
 

Modified: Zope3/branches/3.3/src/zope/app/intid/__init__.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/intid/__init__.py	2006-06-17 03:29:43 UTC (rev 68699)
+++ Zope3/branches/3.3/src/zope/app/intid/__init__.py	2006-06-17 04:10:29 UTC (rev 68700)
@@ -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/branches/3.3/src/zope/app/intid/tests.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/intid/tests.py	2006-06-17 03:29:43 UTC (rev 68699)
+++ Zope3/branches/3.3/src/zope/app/intid/tests.py	2006-06-17 04:10:29 UTC (rev 68700)
@@ -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 Checkins mailing list