[Python-checkins] r45318 - in python/trunk/Lib: bsddb/__init__.py test/test_bsddb.py

gregory.p.smith python-checkins at python.org
Wed Apr 12 22:16:57 CEST 2006


Author: gregory.p.smith
Date: Wed Apr 12 22:16:56 2006
New Revision: 45318

Modified:
   python/trunk/Lib/bsddb/__init__.py
   python/trunk/Lib/test/test_bsddb.py
Log:
Closes bug #1149413

Using None for a filename with the 'n' flag when calling bsddb.btopen
would cause an error while checking if the file None existed.  error
not likely to be seen as anyone using None for a filename would likely
use the 'c' flag in the first place.



Modified: python/trunk/Lib/bsddb/__init__.py
==============================================================================
--- python/trunk/Lib/bsddb/__init__.py	(original)
+++ python/trunk/Lib/bsddb/__init__.py	Wed Apr 12 22:16:56 2006
@@ -358,7 +358,7 @@
         #flags = db.DB_CREATE | db.DB_TRUNCATE
         # we used db.DB_TRUNCATE flag for this before but BerkeleyDB
         # 4.2.52 changed to disallowed truncate with txn environments.
-        if os.path.isfile(file):
+        if file is not None and os.path.isfile(file):
             os.unlink(file)
     else:
         raise error, "flags should be one of 'r', 'w', 'c' or 'n'"

Modified: python/trunk/Lib/test/test_bsddb.py
==============================================================================
--- python/trunk/Lib/test/test_bsddb.py	(original)
+++ python/trunk/Lib/test/test_bsddb.py	Wed Apr 12 22:16:56 2006
@@ -11,9 +11,10 @@
 from sets import Set
 
 class TestBSDDB(unittest.TestCase):
+    openflag = 'c'
 
     def setUp(self):
-        self.f = self.openmethod[0](self.fname, 'c')
+        self.f = self.openmethod[0](self.fname, self.openflag)
         self.d = dict(q='Guido', w='van', e='Rossum', r='invented', t='Python', y='')
         for k, v in self.d.iteritems():
             self.f[k] = v
@@ -267,6 +268,11 @@
     fname = None
     openmethod = [bsddb.btopen]
 
+class TestBTree_InMemory_Truncate(TestBSDDB):
+    fname = None
+    openflag = 'n'
+    openmethod = [bsddb.btopen]
+
 class TestHashTable(TestBSDDB):
     fname = test_support.TESTFN
     openmethod = [bsddb.hashopen]
@@ -285,6 +291,7 @@
         TestHashTable,
         TestBTree_InMemory,
         TestHashTable_InMemory,
+        TestBTree_InMemory_Truncate,
     )
 
 if __name__ == "__main__":


More information about the Python-checkins mailing list