summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-04-21 10:40:58 (GMT)
committerThomas Wouters <thomas@python.org>2006-04-21 10:40:58 (GMT)
commit49fd7fa4431da299196d74087df4a04f99f9c46f (patch)
tree35ace5fe78d3d52c7a9ab356ab9f6dbf8d4b71f4 /Lib/bsddb
parent9ada3d6e29d5165dadacbe6be07bcd35cfbef59d (diff)
downloadcpython-49fd7fa4431da299196d74087df4a04f99f9c46f.zip
cpython-49fd7fa4431da299196d74087df4a04f99f9c46f.tar.gz
cpython-49fd7fa4431da299196d74087df4a04f99f9c46f.tar.bz2
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described here (it's not a Py3K issue, just something Py3K discovers): http://mail.python.org/pipermail/python-dev/2006-April/064051.html Hye-Shik Chang promised to look for a fix, so no need to fix it here. The tests that are expected to break are: test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp test_codecencodings_kr test_codecencodings_tw test_codecs test_multibytecodec This merge fixes an actual test failure (test_weakref) in this branch, though, so I believe merging is the right thing to do anyway.
Diffstat (limited to 'Lib/bsddb')
-rw-r--r--Lib/bsddb/__init__.py18
-rw-r--r--Lib/bsddb/test/test_all.py1
-rw-r--r--Lib/bsddb/test/test_pickle.py75
3 files changed, 86 insertions, 8 deletions
diff --git a/Lib/bsddb/__init__.py b/Lib/bsddb/__init__.py
index d3ee773..c004c08 100644
--- a/Lib/bsddb/__init__.py
+++ b/Lib/bsddb/__init__.py
@@ -287,10 +287,9 @@ def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None,
cachesize=None, lorder=None, hflags=0):
flags = _checkflag(flag, file)
- e = _openDBEnv()
+ e = _openDBEnv(cachesize)
d = db.DB(e)
d.set_flags(hflags)
- if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
if ffactor is not None: d.set_h_ffactor(ffactor)
@@ -305,9 +304,8 @@ def btopen(file, flag='c', mode=0666,
pgsize=None, lorder=None):
flags = _checkflag(flag, file)
- e = _openDBEnv()
+ e = _openDBEnv(cachesize)
d = db.DB(e)
- if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
d.set_flags(btflags)
@@ -324,9 +322,8 @@ def rnopen(file, flag='c', mode=0666,
rlen=None, delim=None, source=None, pad=None):
flags = _checkflag(flag, file)
- e = _openDBEnv()
+ e = _openDBEnv(cachesize)
d = db.DB(e)
- if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
d.set_flags(rnflags)
@@ -339,8 +336,13 @@ def rnopen(file, flag='c', mode=0666,
#----------------------------------------------------------------------
-def _openDBEnv():
+def _openDBEnv(cachesize):
e = db.DBEnv()
+ if cachesize is not None:
+ if cachesize >= 20480:
+ e.set_cachesize(0, cachesize)
+ else:
+ raise error, "cachesize must be >= 20480"
e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL)
return e
@@ -358,7 +360,7 @@ def _checkflag(flag, file):
#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'"
diff --git a/Lib/bsddb/test/test_all.py b/Lib/bsddb/test/test_all.py
index 972cd06..abfaf47 100644
--- a/Lib/bsddb/test/test_all.py
+++ b/Lib/bsddb/test/test_all.py
@@ -65,6 +65,7 @@ def suite():
'test_join',
'test_lock',
'test_misc',
+ 'test_pickle',
'test_queue',
'test_recno',
'test_thread',
diff --git a/Lib/bsddb/test/test_pickle.py b/Lib/bsddb/test/test_pickle.py
new file mode 100644
index 0000000..3916e5c
--- /dev/null
+++ b/Lib/bsddb/test/test_pickle.py
@@ -0,0 +1,75 @@
+
+import sys, os, string
+import pickle
+try:
+ import cPickle
+except ImportError:
+ cPickle = None
+import unittest
+import glob
+
+try:
+ # For Pythons w/distutils pybsddb
+ from bsddb3 import db
+except ImportError, e:
+ # For Python 2.3
+ from bsddb import db
+
+
+#----------------------------------------------------------------------
+
+class pickleTestCase(unittest.TestCase):
+ """Verify that DBError can be pickled and unpickled"""
+ db_home = 'db_home'
+ db_name = 'test-dbobj.db'
+
+ def setUp(self):
+ homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
+ self.homeDir = homeDir
+ try: os.mkdir(homeDir)
+ except os.error: pass
+
+ def tearDown(self):
+ if hasattr(self, 'db'):
+ del self.db
+ if hasattr(self, 'env'):
+ del self.env
+ files = glob.glob(os.path.join(self.homeDir, '*'))
+ for file in files:
+ os.remove(file)
+
+ def _base_test_pickle_DBError(self, pickle):
+ self.env = db.DBEnv()
+ self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
+ self.db = db.DB(self.env)
+ self.db.open(self.db_name, db.DB_HASH, db.DB_CREATE)
+ self.db.put('spam', 'eggs')
+ assert self.db['spam'] == 'eggs'
+ try:
+ self.db.put('spam', 'ham', flags=db.DB_NOOVERWRITE)
+ except db.DBError, egg:
+ pickledEgg = pickle.dumps(egg)
+ #print repr(pickledEgg)
+ rottenEgg = pickle.loads(pickledEgg)
+ if rottenEgg.args != egg.args or type(rottenEgg) != type(egg):
+ raise Exception, (rottenEgg, '!=', egg)
+ else:
+ raise Exception, "where's my DBError exception?!?"
+
+ self.db.close()
+ self.env.close()
+
+ def test01_pickle_DBError(self):
+ self._base_test_pickle_DBError(pickle=pickle)
+
+ if cPickle:
+ def test02_cPickle_DBError(self):
+ self._base_test_pickle_DBError(pickle=cPickle)
+
+#----------------------------------------------------------------------
+
+def test_suite():
+ return unittest.makeSuite(pickleTestCase)
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')