mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
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.
This commit is contained in:
parent
55d031ef23
commit
14c6b4626f
2 changed files with 9 additions and 2 deletions
|
@ -358,7 +358,7 @@ def _checkflag(flag, file):
|
||||||
#flags = db.DB_CREATE | db.DB_TRUNCATE
|
#flags = db.DB_CREATE | db.DB_TRUNCATE
|
||||||
# we used db.DB_TRUNCATE flag for this before but BerkeleyDB
|
# we used db.DB_TRUNCATE flag for this before but BerkeleyDB
|
||||||
# 4.2.52 changed to disallowed truncate with txn environments.
|
# 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)
|
os.unlink(file)
|
||||||
else:
|
else:
|
||||||
raise error, "flags should be one of 'r', 'w', 'c' or 'n'"
|
raise error, "flags should be one of 'r', 'w', 'c' or 'n'"
|
||||||
|
|
|
@ -11,9 +11,10 @@ from test import test_support
|
||||||
from sets import Set
|
from sets import Set
|
||||||
|
|
||||||
class TestBSDDB(unittest.TestCase):
|
class TestBSDDB(unittest.TestCase):
|
||||||
|
openflag = 'c'
|
||||||
|
|
||||||
def setUp(self):
|
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='')
|
self.d = dict(q='Guido', w='van', e='Rossum', r='invented', t='Python', y='')
|
||||||
for k, v in self.d.iteritems():
|
for k, v in self.d.iteritems():
|
||||||
self.f[k] = v
|
self.f[k] = v
|
||||||
|
@ -267,6 +268,11 @@ class TestBTree_InMemory(TestBSDDB):
|
||||||
fname = None
|
fname = None
|
||||||
openmethod = [bsddb.btopen]
|
openmethod = [bsddb.btopen]
|
||||||
|
|
||||||
|
class TestBTree_InMemory_Truncate(TestBSDDB):
|
||||||
|
fname = None
|
||||||
|
openflag = 'n'
|
||||||
|
openmethod = [bsddb.btopen]
|
||||||
|
|
||||||
class TestHashTable(TestBSDDB):
|
class TestHashTable(TestBSDDB):
|
||||||
fname = test_support.TESTFN
|
fname = test_support.TESTFN
|
||||||
openmethod = [bsddb.hashopen]
|
openmethod = [bsddb.hashopen]
|
||||||
|
@ -285,6 +291,7 @@ def test_main(verbose=None):
|
||||||
TestHashTable,
|
TestHashTable,
|
||||||
TestBTree_InMemory,
|
TestBTree_InMemory,
|
||||||
TestHashTable_InMemory,
|
TestHashTable_InMemory,
|
||||||
|
TestBTree_InMemory_Truncate,
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue