[Zodb-checkins] SVN: ZODB/trunk/ Merge rev 31010 from 3.4 branch.

Tim Peters tim.one at comcast.net
Tue Jul 5 13:47:40 EDT 2005


Log message for revision 31011:
  Merge rev 31010 from 3.4 branch.
  
  Collector 1831.
  
  The BTree minKey() and maxKey() methods gave a misleading message if no key
  satisfying the constraints existed in a non-empty tree.
  

Changed:
  U   ZODB/trunk/NEWS.txt
  U   ZODB/trunk/src/BTrees/BTreeTemplate.c
  U   ZODB/trunk/src/BTrees/BucketTemplate.c
  U   ZODB/trunk/src/BTrees/tests/testBTrees.py

-=-
Modified: ZODB/trunk/NEWS.txt
===================================================================
--- ZODB/trunk/NEWS.txt	2005-07-05 17:25:52 UTC (rev 31010)
+++ ZODB/trunk/NEWS.txt	2005-07-05 17:47:40 UTC (rev 31011)
@@ -62,10 +62,14 @@
   very valuable when you want to spot strange transaction sizes via Zope's
   'Undo' tab".
 
-BTrees interface
-----------------
+BTrees
+------
 
-- (3.5a4S) Collector 1829.  Clarified that the ``minKey()`` and ``maxKey()``
+- (3.5a4) Collector 1831.  The BTree ``minKey()`` and ``maxKey()`` methods
+  gave a misleading message if no key satisfying the constraints existed in a
+  non-empty tree.
+
+- (3.5a4) Collector 1829.  Clarified that the ``minKey()`` and ``maxKey()``
   methods raise an exception if no key exists satsifying the constraints.
 
 
@@ -76,6 +80,7 @@
 Following are dates of internal releases (to support ongoing Zope 2
 development) since ZODB 3.4's last public release:
 
+- 3.4.1a4 DD-MMM-2005
 - 3.4.1a3 02-Jul-2005
 - 3.4.1a2 29-Jun-2005
 - 3.4.1a1 27-Jun-2005
@@ -130,9 +135,13 @@
 
 - The implementation of ``undoLog()`` was wrong in several ways; repaired.
 
-BTrees interface
-----------------
+BTrees
+------
 
+- (3.4.1a4) Collector 1831.  The BTree ``minKey()`` and ``maxKey()`` methods
+  gave a misleading message if no key satisfying the constraints existed in a
+  non-empty tree.
+
 - (3.4.1a3) Collector 1829.  Clarified that the ``minKey()`` and ``maxKey()``
   methods raise an exception if no key exists satsifying the constraints.
 

Modified: ZODB/trunk/src/BTrees/BTreeTemplate.c
===================================================================
--- ZODB/trunk/src/BTrees/BTreeTemplate.c	2005-07-05 17:25:52 UTC (rev 31010)
+++ ZODB/trunk/src/BTrees/BTreeTemplate.c	2005-07-05 17:47:40 UTC (rev 31011)
@@ -1341,6 +1341,7 @@
   PyObject *key=0;
   Bucket *bucket = NULL;
   int offset, rc;
+  int empty_tree = 1;
 
   UNLESS (PyArg_ParseTuple(args, "|O", &key)) return NULL;
 
@@ -1355,6 +1356,7 @@
       if ((rc = BTree_findRangeEnd(self, key, min, 0, &bucket, &offset)) <= 0)
         {
           if (rc < 0) goto err;
+          empty_tree = 0;
           goto empty;
         }
       PER_UNUSE(self);
@@ -1392,8 +1394,9 @@
   return key;
 
  empty:
-  PyErr_SetString(PyExc_ValueError, "empty tree");
-
+  PyErr_SetString(PyExc_ValueError,
+  		  empty_tree ? "empty tree" :
+			       "no key satisfies the conditions");
  err:
   PER_UNUSE(self);
   if (bucket)

Modified: ZODB/trunk/src/BTrees/BucketTemplate.c
===================================================================
--- ZODB/trunk/src/BTrees/BucketTemplate.c	2005-07-05 17:25:52 UTC (rev 31010)
+++ ZODB/trunk/src/BTrees/BucketTemplate.c	2005-07-05 17:47:40 UTC (rev 31011)
@@ -683,6 +683,7 @@
 {
   PyObject *key=0;
   int rc, offset;
+  int empty_bucket = 1;
 
   if (args && ! PyArg_ParseTuple(args, "|O", &key)) return NULL;
 
@@ -696,6 +697,7 @@
       if ((rc = Bucket_findRangeEnd(self, key, min, 0, &offset)) <= 0)
         {
           if (rc < 0) return NULL;
+          empty_bucket = 0;
           goto empty;
         }
     }
@@ -708,7 +710,9 @@
   return key;
 
  empty:
-  PyErr_SetString(PyExc_ValueError, "empty bucket");
+  PyErr_SetString(PyExc_ValueError,
+		  empty_bucket ? "empty bucket" :
+				 "no key satisfies the conditions");
   PER_UNUSE(self);
   return NULL;
 }

Modified: ZODB/trunk/src/BTrees/tests/testBTrees.py
===================================================================
--- ZODB/trunk/src/BTrees/tests/testBTrees.py	2005-07-05 17:25:52 UTC (rev 31010)
+++ ZODB/trunk/src/BTrees/tests/testBTrees.py	2005-07-05 17:47:40 UTC (rev 31011)
@@ -302,6 +302,20 @@
         self.assertEqual(t.minKey(3), 3)
         self.assertEqual(t.minKey(9), 10)
 
+        try:
+            t.maxKey(t.minKey() - 1)
+        except ValueError, err:
+            self.assertEqual(str(err), "no key satisfies the conditions")
+        else:
+            self.fail("expected ValueError")
+
+        try:
+            t.minKey(t.maxKey() + 1)
+        except ValueError, err:
+            self.assertEqual(str(err), "no key satisfies the conditions")
+        else:
+            self.fail("expected ValueError")
+
     def testClear(self):
         r = range(100)
         for x in r:
@@ -672,6 +686,20 @@
         self.assert_(t.maxKey() in t)
         self.assert_(t.maxKey()+1 not in t)
 
+        try:
+            t.maxKey(t.minKey() - 1)
+        except ValueError, err:
+            self.assertEqual(str(err), "no key satisfies the conditions")
+        else:
+            self.fail("expected ValueError")
+
+        try:
+            t.minKey(t.maxKey() + 1)
+        except ValueError, err:
+            self.assertEqual(str(err), "no key satisfies the conditions")
+        else:
+            self.fail("expected ValueError")
+
     def testUpdate(self):
         d={}
         l=[]



More information about the Zodb-checkins mailing list