Commit 4907d27c authored by Jesus Cea's avatar Jesus Cea

Update bsddb code to version 4.7.3pre2. This code should

be compatible with Python 3.0, also.

  http://www.jcea.es/programacion/pybsddb.htm#bsddb3-4.7.3
parent 82358691
...@@ -218,8 +218,13 @@ class DBShelf(MutableMapping): ...@@ -218,8 +218,13 @@ class DBShelf(MutableMapping):
def associate(self, secondaryDB, callback, flags=0): def associate(self, secondaryDB, callback, flags=0):
def _shelf_callback(priKey, priData, realCallback=callback): def _shelf_callback(priKey, priData, realCallback=callback):
# Safe in Python 2.x because expresion short circuit
if sys.version_info[0] < 3 or isinstance(priData, bytes) :
data = cPickle.loads(priData) data = cPickle.loads(priData)
else :
data = cPickle.loads(bytes(priData, "iso8859-1")) # 8 bits
return realCallback(priKey, data) return realCallback(priKey, data)
return self.db.associate(secondaryDB, _shelf_callback, flags) return self.db.associate(secondaryDB, _shelf_callback, flags)
...@@ -232,7 +237,7 @@ class DBShelf(MutableMapping): ...@@ -232,7 +237,7 @@ class DBShelf(MutableMapping):
data = apply(self.db.get, args, kw) data = apply(self.db.get, args, kw)
try: try:
return cPickle.loads(data) return cPickle.loads(data)
except (TypeError, cPickle.UnpicklingError): except (EOFError, TypeError, cPickle.UnpicklingError):
return data # we may be getting the default value, or None, return data # we may be getting the default value, or None,
# so it doesn't need unpickled. # so it doesn't need unpickled.
...@@ -350,7 +355,11 @@ class DBShelfCursor: ...@@ -350,7 +355,11 @@ class DBShelfCursor:
return None return None
else: else:
key, data = rec key, data = rec
# Safe in Python 2.x because expresion short circuit
if sys.version_info[0] < 3 or isinstance(data, bytes) :
return key, cPickle.loads(data) return key, cPickle.loads(data)
else :
return key, cPickle.loads(bytes(data, "iso8859-1")) # 8 bits
#---------------------------------------------- #----------------------------------------------
# Methods allowed to pass-through to self.dbc # Methods allowed to pass-through to self.dbc
......
This diff is collapsed.
...@@ -61,7 +61,7 @@ def DeadlockWrap(function, *_args, **_kwargs): ...@@ -61,7 +61,7 @@ def DeadlockWrap(function, *_args, **_kwargs):
""" """
sleeptime = _deadlock_MinSleepTime sleeptime = _deadlock_MinSleepTime
max_retries = _kwargs.get('max_retries', -1) max_retries = _kwargs.get('max_retries', -1)
if 'max_retries' in _kwargs: if _kwargs.has_key('max_retries'):
del _kwargs['max_retries'] del _kwargs['max_retries']
while True: while True:
try: try:
......
This diff is collapsed.
...@@ -7,19 +7,8 @@ import time ...@@ -7,19 +7,8 @@ import time
from pprint import pprint from pprint import pprint
import unittest import unittest
from test_all import verbose, have_threads, get_new_environment_path from test_all import db, dbshelve, test_support, verbose, have_threads, \
get_new_environment_path
try:
# For Pythons w/distutils pybsddb
from bsddb3 import db, dbshelve
except ImportError:
# For Python 2.3
from bsddb import db, dbshelve
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -152,7 +141,7 @@ class AssociateTestCase(unittest.TestCase): ...@@ -152,7 +141,7 @@ class AssociateTestCase(unittest.TestCase):
for key, value in musicdata.items(): for key, value in musicdata.items():
if type(self.keytype) == type(''): if type(self.keytype) == type(''):
key = "%02d" % key key = "%02d" % key
d.put(key, string.join(value, '|'), txn=txn) d.put(key, '|'.join(value), txn=txn)
def createDB(self, txn=None): def createDB(self, txn=None):
self.cur = None self.cur = None
...@@ -238,13 +227,13 @@ class AssociateTestCase(unittest.TestCase): ...@@ -238,13 +227,13 @@ class AssociateTestCase(unittest.TestCase):
rec = self.cur.first() rec = self.cur.first()
while rec is not None: while rec is not None:
if type(self.keytype) == type(''): if type(self.keytype) == type(''):
self.assert_(string.atoi(rec[0])) # for primary db, key is a number self.assert_(int(rec[0])) # for primary db, key is a number
else: else:
self.assert_(rec[0] and type(rec[0]) == type(0)) self.assert_(rec[0] and type(rec[0]) == type(0))
count = count + 1 count = count + 1
if verbose: if verbose:
print rec print rec
rec = self.cur.next() rec = getattr(self.cur, "next")()
self.assertEqual(count, len(musicdata)) # all items accounted for self.assertEqual(count, len(musicdata)) # all items accounted for
...@@ -270,7 +259,7 @@ class AssociateTestCase(unittest.TestCase): ...@@ -270,7 +259,7 @@ class AssociateTestCase(unittest.TestCase):
count = count + 1 count = count + 1
if verbose: if verbose:
print rec print rec
rec = self.cur.next() rec = getattr(self.cur, "next")()
# all items accounted for EXCEPT for 1 with "Blues" genre # all items accounted for EXCEPT for 1 with "Blues" genre
self.assertEqual(count, len(musicdata)-1) self.assertEqual(count, len(musicdata)-1)
...@@ -278,9 +267,11 @@ class AssociateTestCase(unittest.TestCase): ...@@ -278,9 +267,11 @@ class AssociateTestCase(unittest.TestCase):
def getGenre(self, priKey, priData): def getGenre(self, priKey, priData):
self.assertEqual(type(priData), type("")) self.assertEqual(type(priData), type(""))
genre = priData.split('|')[2]
if verbose: if verbose:
print 'getGenre key: %r data: %r' % (priKey, priData) print 'getGenre key: %r data: %r' % (priKey, priData)
genre = string.split(priData, '|')[2]
if genre == 'Blues': if genre == 'Blues':
return db.DB_DONOTINDEX return db.DB_DONOTINDEX
else: else:
...@@ -404,13 +395,13 @@ class ThreadedAssociateTestCase(AssociateTestCase): ...@@ -404,13 +395,13 @@ class ThreadedAssociateTestCase(AssociateTestCase):
for key, value in musicdata.items(): for key, value in musicdata.items():
if type(self.keytype) == type(''): if type(self.keytype) == type(''):
key = "%02d" % key key = "%02d" % key
d.put(key, string.join(value, '|')) d.put(key, '|'.join(value))
def writer2(self, d): def writer2(self, d):
for x in range(100, 600): for x in range(100, 600):
key = 'z%2d' % x key = 'z%2d' % x
value = [key] * 4 value = [key] * 4
d.put(key, string.join(value, '|')) d.put(key, '|'.join(value))
class ThreadedAssociateHashTestCase(ShelveAssociateTestCase): class ThreadedAssociateHashTestCase(ShelveAssociateTestCase):
......
...@@ -10,19 +10,8 @@ from pprint import pprint ...@@ -10,19 +10,8 @@ from pprint import pprint
import unittest import unittest
import time import time
try: from test_all import db, test_support, verbose, get_new_environment_path, \
# For Pythons w/distutils pybsddb get_new_database_path
from bsddb3 import db
except ImportError:
# For Python 2.3
from bsddb import db
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
from test_all import verbose, get_new_environment_path, get_new_database_path
DASH = '-' DASH = '-'
...@@ -150,7 +139,11 @@ class BasicTestCase(unittest.TestCase): ...@@ -150,7 +139,11 @@ class BasicTestCase(unittest.TestCase):
try: try:
d.delete('abcd') d.delete('abcd')
except db.DBNotFoundError, val: except db.DBNotFoundError, val:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.DB_NOTFOUND) self.assertEqual(val[0], db.DB_NOTFOUND)
else :
self.assertEqual(val.args[0], db.DB_NOTFOUND)
if verbose: print val if verbose: print val
else: else:
self.fail("expected exception") self.fail("expected exception")
...@@ -169,7 +162,11 @@ class BasicTestCase(unittest.TestCase): ...@@ -169,7 +162,11 @@ class BasicTestCase(unittest.TestCase):
try: try:
d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE) d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE)
except db.DBKeyExistError, val: except db.DBKeyExistError, val:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.DB_KEYEXIST) self.assertEqual(val[0], db.DB_KEYEXIST)
else :
self.assertEqual(val.args[0], db.DB_KEYEXIST)
if verbose: print val if verbose: print val
else: else:
self.fail("expected exception") self.fail("expected exception")
...@@ -255,8 +252,10 @@ class BasicTestCase(unittest.TestCase): ...@@ -255,8 +252,10 @@ class BasicTestCase(unittest.TestCase):
self.assertEqual(d['new record'], 'a replacement record') self.assertEqual(d['new record'], 'a replacement record')
self.assertEqual(d.has_key('0001'), 1) # We check also the positional parameter
self.assertEqual(d.has_key('spam'), 0) self.assertEqual(d.has_key('0001', None), 1)
# We check also the keyword parameter
self.assertEqual(d.has_key('spam', txn=None), 0)
items = d.items() items = d.items()
self.assertEqual(len(items), self._numKeys+1) self.assertEqual(len(items), self._numKeys+1)
...@@ -302,7 +301,11 @@ class BasicTestCase(unittest.TestCase): ...@@ -302,7 +301,11 @@ class BasicTestCase(unittest.TestCase):
rec = c.next() rec = c.next()
except db.DBNotFoundError, val: except db.DBNotFoundError, val:
if get_raises_error: if get_raises_error:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.DB_NOTFOUND) self.assertEqual(val[0], db.DB_NOTFOUND)
else :
self.assertEqual(val.args[0], db.DB_NOTFOUND)
if verbose: print val if verbose: print val
rec = None rec = None
else: else:
...@@ -323,7 +326,11 @@ class BasicTestCase(unittest.TestCase): ...@@ -323,7 +326,11 @@ class BasicTestCase(unittest.TestCase):
rec = c.prev() rec = c.prev()
except db.DBNotFoundError, val: except db.DBNotFoundError, val:
if get_raises_error: if get_raises_error:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.DB_NOTFOUND) self.assertEqual(val[0], db.DB_NOTFOUND)
else :
self.assertEqual(val.args[0], db.DB_NOTFOUND)
if verbose: print val if verbose: print val
rec = None rec = None
else: else:
...@@ -346,7 +353,11 @@ class BasicTestCase(unittest.TestCase): ...@@ -346,7 +353,11 @@ class BasicTestCase(unittest.TestCase):
try: try:
n = c.set('bad key') n = c.set('bad key')
except db.DBNotFoundError, val: except db.DBNotFoundError, val:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.DB_NOTFOUND) self.assertEqual(val[0], db.DB_NOTFOUND)
else :
self.assertEqual(val.args[0], db.DB_NOTFOUND)
if verbose: print val if verbose: print val
else: else:
if set_raises_error: if set_raises_error:
...@@ -360,7 +371,11 @@ class BasicTestCase(unittest.TestCase): ...@@ -360,7 +371,11 @@ class BasicTestCase(unittest.TestCase):
try: try:
n = c.get_both('0404', 'bad data') n = c.get_both('0404', 'bad data')
except db.DBNotFoundError, val: except db.DBNotFoundError, val:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.DB_NOTFOUND) self.assertEqual(val[0], db.DB_NOTFOUND)
else :
self.assertEqual(val.args[0], db.DB_NOTFOUND)
if verbose: print val if verbose: print val
else: else:
if get_raises_error: if get_raises_error:
...@@ -389,7 +404,11 @@ class BasicTestCase(unittest.TestCase): ...@@ -389,7 +404,11 @@ class BasicTestCase(unittest.TestCase):
rec = c.current() rec = c.current()
except db.DBKeyEmptyError, val: except db.DBKeyEmptyError, val:
if get_raises_error: if get_raises_error:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.DB_KEYEMPTY) self.assertEqual(val[0], db.DB_KEYEMPTY)
else :
self.assertEqual(val.args[0], db.DB_KEYEMPTY)
if verbose: print val if verbose: print val
else: else:
self.fail("unexpected DBKeyEmptyError") self.fail("unexpected DBKeyEmptyError")
...@@ -434,7 +453,11 @@ class BasicTestCase(unittest.TestCase): ...@@ -434,7 +453,11 @@ class BasicTestCase(unittest.TestCase):
# a bug may cause a NULL pointer dereference... # a bug may cause a NULL pointer dereference...
apply(getattr(c, method), args) apply(getattr(c, method), args)
except db.DBError, val: except db.DBError, val:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], 0) self.assertEqual(val[0], 0)
else :
self.assertEqual(val.args[0], 0)
if verbose: print val if verbose: print val
else: else:
self.fail("no exception raised when using a buggy cursor's" self.fail("no exception raised when using a buggy cursor's"
...@@ -803,8 +826,8 @@ class BasicDUPTestCase(BasicTestCase): ...@@ -803,8 +826,8 @@ class BasicDUPTestCase(BasicTestCase):
rec = c.set("dup1") rec = c.set("dup1")
self.assertEqual(rec, ('dup1', 'The')) self.assertEqual(rec, ('dup1', 'The'))
next = c.next() next_reg = c.next()
self.assertEqual(next, ('dup1', 'quick')) self.assertEqual(next_reg, ('dup1', 'quick'))
rec = c.set("dup1") rec = c.set("dup1")
count = c.count() count = c.count()
...@@ -919,7 +942,7 @@ class BasicMultiDBTestCase(BasicTestCase): ...@@ -919,7 +942,7 @@ class BasicMultiDBTestCase(BasicTestCase):
if verbose: if verbose:
print rec print rec
rec = c3.next() rec = c3.next()
self.assertEqual(count, 52) self.assertEqual(count, len(string.letters))
c1.close() c1.close()
......
...@@ -7,19 +7,10 @@ import test_all ...@@ -7,19 +7,10 @@ import test_all
from cStringIO import StringIO from cStringIO import StringIO
import unittest import unittest
try:
# For Pythons w/distutils pybsddb
from bsddb3 import db, dbshelve
except ImportError:
# For Python 2.3
from bsddb import db, dbshelve
from test_all import get_new_environment_path, get_new_database_path from test_all import db, dbshelve, test_support, \
get_new_environment_path, get_new_database_path
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
lexical_cmp = cmp lexical_cmp = cmp
...@@ -37,7 +28,25 @@ _expected_lowercase_test_data = ['', 'a', 'aaa', 'b', 'c', 'CC', 'cccce', 'ccccf ...@@ -37,7 +28,25 @@ _expected_lowercase_test_data = ['', 'a', 'aaa', 'b', 'c', 'CC', 'cccce', 'ccccf
class ComparatorTests (unittest.TestCase): class ComparatorTests (unittest.TestCase):
def comparator_test_helper (self, comparator, expected_data): def comparator_test_helper (self, comparator, expected_data):
data = expected_data[:] data = expected_data[:]
data.sort (comparator)
import sys
if sys.version_info[0] < 3 :
if sys.version_info[:3] < (2, 4, 0):
data.sort(comparator)
else :
data.sort(cmp=comparator)
else : # Insertion Sort. Please, improve
data2 = []
for i in data :
for j, k in enumerate(data2) :
r = comparator(k, i)
if r == 1 :
data2.insert(j, i)
break
else :
data2.append(i)
data = data2
self.failUnless (data == expected_data, self.failUnless (data == expected_data,
"comparator `%s' is not right: %s vs. %s" "comparator `%s' is not right: %s vs. %s"
% (comparator, expected_data, data)) % (comparator, expected_data, data))
......
...@@ -6,16 +6,10 @@ regression test suite. ...@@ -6,16 +6,10 @@ regression test suite.
import os, string import os, string
import unittest import unittest
from test_all import verbose, get_new_database_path from test_all import db, hashopen, btopen, rnopen, verbose, \
get_new_database_path
try:
# For Pythons w/distutils pybsddb
from bsddb3 import db, hashopen, btopen, rnopen
except ImportError:
# For Python 2.3
from bsddb import db, hashopen, btopen, rnopen
class CompatibilityTestCase(unittest.TestCase): class CompatibilityTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.filename = get_new_database_path() self.filename = get_new_database_path()
...@@ -34,7 +28,7 @@ class CompatibilityTestCase(unittest.TestCase): ...@@ -34,7 +28,7 @@ class CompatibilityTestCase(unittest.TestCase):
self.do_bthash_test(hashopen, 'hashopen') self.do_bthash_test(hashopen, 'hashopen')
def test03_rnopen(self): def test03_rnopen(self):
data = string.split("The quick brown fox jumped over the lazy dog.") data = "The quick brown fox jumped over the lazy dog.".split()
if verbose: if verbose:
print "\nTesting: rnopen" print "\nTesting: rnopen"
......
import unittest import unittest
import os, glob import os, glob
try: from test_all import db, test_support, get_new_environment_path, \
# For Pythons w/distutils pybsddb get_new_database_path
from bsddb3 import db
except ImportError:
# For Python 2.3
from bsddb import db
from test_all import get_new_environment_path, get_new_database_path
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
#---------------------------------------------------------------------- #----------------------------------------------------------------------
......
...@@ -2,19 +2,8 @@ ...@@ -2,19 +2,8 @@
import os, string import os, string
import unittest import unittest
try: from test_all import db, dbobj, test_support, get_new_environment_path, \
# For Pythons w/distutils pybsddb get_new_database_path
from bsddb3 import db, dbobj
except ImportError:
# For Python 2.3
from bsddb import db, dbobj
from test_all import get_new_environment_path, get_new_database_path
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -36,7 +25,7 @@ class dbobjTestCase(unittest.TestCase): ...@@ -36,7 +25,7 @@ class dbobjTestCase(unittest.TestCase):
class TestDBEnv(dbobj.DBEnv): pass class TestDBEnv(dbobj.DBEnv): pass
class TestDB(dbobj.DB): class TestDB(dbobj.DB):
def put(self, key, *args, **kwargs): def put(self, key, *args, **kwargs):
key = string.upper(key) key = key.upper()
# call our parent classes put method with an upper case key # call our parent classes put method with an upper case key
return apply(dbobj.DB.put, (self, key) + args, kwargs) return apply(dbobj.DB.put, (self, key) + args, kwargs)
self.env = TestDBEnv() self.env = TestDBEnv()
......
...@@ -4,22 +4,11 @@ TestCases for checking dbShelve objects. ...@@ -4,22 +4,11 @@ TestCases for checking dbShelve objects.
import os, string import os, string
import random import random
from types import *
import unittest import unittest
try:
# For Pythons w/distutils pybsddb
from bsddb3 import db, dbshelve
except ImportError:
# For Python 2.3
from bsddb import db, dbshelve
try: from test_all import db, dbshelve, test_support, verbose, \
from bsddb3 import test_support get_new_environment_path, get_new_database_path
except ImportError:
from test import test_support
from test_all import verbose, get_new_environment_path, get_new_database_path
...@@ -31,22 +20,38 @@ class DataClass: ...@@ -31,22 +20,38 @@ class DataClass:
def __init__(self): def __init__(self):
self.value = random.random() self.value = random.random()
def __cmp__(self, other): def __repr__(self) : # For Python 3.0 comparison
return "DataClass %f" %self.value
def __cmp__(self, other): # For Python 2.x comparison
return cmp(self.value, other) return cmp(self.value, other)
class DBShelveTestCase(unittest.TestCase): class DBShelveTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
import sys
if sys.version_info[0] >= 3 :
from test_all import do_proxy_db_py3k
self._flag_proxy_db_py3k = do_proxy_db_py3k(False)
self.filename = get_new_database_path() self.filename = get_new_database_path()
self.do_open() self.do_open()
def tearDown(self): def tearDown(self):
import sys
if sys.version_info[0] >= 3 :
from test_all import do_proxy_db_py3k
do_proxy_db_py3k(self._flag_proxy_db_py3k)
self.do_close() self.do_close()
test_support.unlink(self.filename) test_support.unlink(self.filename)
def mk(self, key): def mk(self, key):
"""Turn key into an appropriate key type for this db""" """Turn key into an appropriate key type for this db"""
# override in child class for RECNO # override in child class for RECNO
import sys
if sys.version_info[0] < 3 :
return key return key
else :
return bytes(key, "iso8859-1") # 8 bits
def populateDB(self, d): def populateDB(self, d):
for x in string.letters: for x in string.letters:
...@@ -112,9 +117,15 @@ class DBShelveTestCase(unittest.TestCase): ...@@ -112,9 +117,15 @@ class DBShelveTestCase(unittest.TestCase):
dbvalues = d.values() dbvalues = d.values()
self.assertEqual(len(dbvalues), len(d.keys())) self.assertEqual(len(dbvalues), len(d.keys()))
import sys
if sys.version_info[0] < 3 :
values.sort() values.sort()
dbvalues.sort() dbvalues.sort()
self.assertEqual(values, dbvalues) self.assertEqual(values, dbvalues)
else : # XXX: Convert all to strings. Please, improve
values.sort(key=lambda x : str(x))
dbvalues.sort(key=lambda x : str(x))
self.assertEqual(repr(values), repr(dbvalues))
items = d.items() items = d.items()
self.assertEqual(len(items), len(values)) self.assertEqual(len(items), len(values))
...@@ -154,7 +165,8 @@ class DBShelveTestCase(unittest.TestCase): ...@@ -154,7 +165,8 @@ class DBShelveTestCase(unittest.TestCase):
print rec print rec
key, value = rec key, value = rec
self.checkrec(key, value) self.checkrec(key, value)
rec = c.next() # Hack to avoid conversion by 2to3 tool
rec = getattr(c, "next")()
del c del c
self.assertEqual(count, len(d)) self.assertEqual(count, len(d))
...@@ -190,21 +202,33 @@ class DBShelveTestCase(unittest.TestCase): ...@@ -190,21 +202,33 @@ class DBShelveTestCase(unittest.TestCase):
def checkrec(self, key, value): def checkrec(self, key, value):
# override this in a subclass if the key type is different # override this in a subclass if the key type is different
import sys
if sys.version_info[0] >= 3 :
if isinstance(key, bytes) :
key = key.decode("iso8859-1") # 8 bits
x = key[1] x = key[1]
if key[0] == 'S': if key[0] == 'S':
self.assertEqual(type(value), StringType) self.assertEqual(type(value), str)
self.assertEqual(value, 10 * x) self.assertEqual(value, 10 * x)
elif key[0] == 'I': elif key[0] == 'I':
self.assertEqual(type(value), IntType) self.assertEqual(type(value), int)
self.assertEqual(value, ord(x)) self.assertEqual(value, ord(x))
elif key[0] == 'L': elif key[0] == 'L':
self.assertEqual(type(value), ListType) self.assertEqual(type(value), list)
self.assertEqual(value, [x] * 10) self.assertEqual(value, [x] * 10)
elif key[0] == 'O': elif key[0] == 'O':
import sys
if sys.version_info[0] < 3 :
from types import InstanceType
self.assertEqual(type(value), InstanceType) self.assertEqual(type(value), InstanceType)
else :
self.assertEqual(type(value), DataClass)
self.assertEqual(value.S, 10 * x) self.assertEqual(value.S, 10 * x)
self.assertEqual(value.I, ord(x)) self.assertEqual(value.I, ord(x))
self.assertEqual(value.L, [x] * 10) self.assertEqual(value.L, [x] * 10)
...@@ -266,6 +290,10 @@ class BasicEnvShelveTestCase(DBShelveTestCase): ...@@ -266,6 +290,10 @@ class BasicEnvShelveTestCase(DBShelveTestCase):
DBShelveTestCase.setUp(self) DBShelveTestCase.setUp(self)
def tearDown(self): def tearDown(self):
import sys
if sys.version_info[0] >= 3 :
from test_all import do_proxy_db_py3k
do_proxy_db_py3k(self._flag_proxy_db_py3k)
self.do_close() self.do_close()
test_support.rmtree(self.homeDir) test_support.rmtree(self.homeDir)
......
...@@ -28,20 +28,8 @@ except ImportError: ...@@ -28,20 +28,8 @@ except ImportError:
import pickle import pickle
import unittest import unittest
from test_all import verbose, get_new_environment_path, get_new_database_path from test_all import db, dbtables, test_support, verbose, \
get_new_environment_path, get_new_database_path
try:
# For Pythons w/distutils pybsddb
from bsddb3 import db, dbtables
except ImportError:
# For Python 2.3
from bsddb import db, dbtables
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -49,12 +37,21 @@ class TableDBTestCase(unittest.TestCase): ...@@ -49,12 +37,21 @@ class TableDBTestCase(unittest.TestCase):
db_name = 'test-table.db' db_name = 'test-table.db'
def setUp(self): def setUp(self):
import sys
if sys.version_info[0] >= 3 :
from test_all import do_proxy_db_py3k
self._flag_proxy_db_py3k = do_proxy_db_py3k(False)
self.testHomeDir = get_new_environment_path() self.testHomeDir = get_new_environment_path()
self.tdb = dbtables.bsdTableDB( self.tdb = dbtables.bsdTableDB(
filename='tabletest.db', dbhome=self.testHomeDir, create=1) filename='tabletest.db', dbhome=self.testHomeDir, create=1)
def tearDown(self): def tearDown(self):
self.tdb.close() self.tdb.close()
import sys
if sys.version_info[0] >= 3 :
from test_all import do_proxy_db_py3k
do_proxy_db_py3k(self._flag_proxy_db_py3k)
test_support.rmtree(self.testHomeDir) test_support.rmtree(self.testHomeDir)
def test01(self): def test01(self):
...@@ -65,7 +62,12 @@ class TableDBTestCase(unittest.TestCase): ...@@ -65,7 +62,12 @@ class TableDBTestCase(unittest.TestCase):
except dbtables.TableDBError: except dbtables.TableDBError:
pass pass
self.tdb.CreateTable(tabname, [colname]) self.tdb.CreateTable(tabname, [colname])
import sys
if sys.version_info[0] < 3 :
self.tdb.Insert(tabname, {colname: pickle.dumps(3.14159, 1)}) self.tdb.Insert(tabname, {colname: pickle.dumps(3.14159, 1)})
else :
self.tdb.Insert(tabname, {colname: pickle.dumps(3.14159,
1).decode("iso8859-1")}) # 8 bits
if verbose: if verbose:
self.tdb._db_print() self.tdb._db_print()
...@@ -73,7 +75,11 @@ class TableDBTestCase(unittest.TestCase): ...@@ -73,7 +75,11 @@ class TableDBTestCase(unittest.TestCase):
values = self.tdb.Select( values = self.tdb.Select(
tabname, [colname], conditions={colname: None}) tabname, [colname], conditions={colname: None})
import sys
if sys.version_info[0] < 3 :
colval = pickle.loads(values[0][colname]) colval = pickle.loads(values[0][colname])
else :
colval = pickle.loads(bytes(values[0][colname], "iso8859-1"))
self.assert_(colval > 3.141) self.assert_(colval > 3.141)
self.assert_(colval < 3.142) self.assert_(colval < 3.142)
...@@ -83,11 +89,23 @@ class TableDBTestCase(unittest.TestCase): ...@@ -83,11 +89,23 @@ class TableDBTestCase(unittest.TestCase):
col0 = 'coolness factor' col0 = 'coolness factor'
col1 = 'but can it fly?' col1 = 'but can it fly?'
col2 = 'Species' col2 = 'Species'
import sys
if sys.version_info[0] < 3 :
testinfo = [ testinfo = [
{col0: pickle.dumps(8, 1), col1: 'no', col2: 'Penguin'}, {col0: pickle.dumps(8, 1), col1: 'no', col2: 'Penguin'},
{col0: pickle.dumps(-1, 1), col1: 'no', col2: 'Turkey'}, {col0: pickle.dumps(-1, 1), col1: 'no', col2: 'Turkey'},
{col0: pickle.dumps(9, 1), col1: 'yes', col2: 'SR-71A Blackbird'} {col0: pickle.dumps(9, 1), col1: 'yes', col2: 'SR-71A Blackbird'}
] ]
else :
testinfo = [
{col0: pickle.dumps(8, 1).decode("iso8859-1"),
col1: 'no', col2: 'Penguin'},
{col0: pickle.dumps(-1, 1).decode("iso8859-1"),
col1: 'no', col2: 'Turkey'},
{col0: pickle.dumps(9, 1).decode("iso8859-1"),
col1: 'yes', col2: 'SR-71A Blackbird'}
]
try: try:
self.tdb.Drop(tabname) self.tdb.Drop(tabname)
...@@ -97,8 +115,14 @@ class TableDBTestCase(unittest.TestCase): ...@@ -97,8 +115,14 @@ class TableDBTestCase(unittest.TestCase):
for row in testinfo : for row in testinfo :
self.tdb.Insert(tabname, row) self.tdb.Insert(tabname, row)
import sys
if sys.version_info[0] < 3 :
values = self.tdb.Select(tabname, [col2], values = self.tdb.Select(tabname, [col2],
conditions={col0: lambda x: pickle.loads(x) >= 8}) conditions={col0: lambda x: pickle.loads(x) >= 8})
else :
values = self.tdb.Select(tabname, [col2],
conditions={col0: lambda x:
pickle.loads(bytes(x, "iso8859-1")) >= 8})
self.assertEqual(len(values), 2) self.assertEqual(len(values), 2)
if values[0]['Species'] == 'Penguin' : if values[0]['Species'] == 'Penguin' :
......
...@@ -4,19 +4,8 @@ ...@@ -4,19 +4,8 @@
import os import os
import unittest import unittest
try: from test_all import db, test_support, get_new_environment_path, \
# For Pythons w/distutils pybsddb get_new_database_path
from bsddb3 import db
except ImportError:
# For Python 2.3
from bsddb import db
from test_all import get_new_environment_path, get_new_database_path
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
try : try :
a=set() a=set()
...@@ -79,12 +68,16 @@ class DBTxn_distributed(unittest.TestCase): ...@@ -79,12 +68,16 @@ class DBTxn_distributed(unittest.TestCase):
def test01_distributed_transactions(self) : def test01_distributed_transactions(self) :
txns=set() txns=set()
adapt = lambda x : x
import sys
if sys.version_info[0] >= 3 :
adapt = lambda x : bytes(x, "ascii")
# Create transactions, "prepare" them, and # Create transactions, "prepare" them, and
# let them be garbage collected. # let them be garbage collected.
for i in xrange(self.num_txns) : for i in xrange(self.num_txns) :
txn=self.dbenv.txn_begin() txn = self.dbenv.txn_begin()
gid="%%%dd" %db.DB_XIDDATASIZE gid = "%%%dd" %db.DB_XIDDATASIZE
gid=gid %i gid = adapt(gid %i)
self.db.put(i, gid, txn=txn, flags=db.DB_APPEND) self.db.put(i, gid, txn=txn, flags=db.DB_APPEND)
txns.add(gid) txns.add(gid)
txn.prepare(gid) txn.prepare(gid)
......
...@@ -5,19 +5,7 @@ is closed before its DB objects. ...@@ -5,19 +5,7 @@ is closed before its DB objects.
import os import os
import unittest import unittest
try: from test_all import db, test_support, verbose, get_new_environment_path, get_new_database_path
# For Pythons w/distutils pybsddb
from bsddb3 import db
except ImportError:
# For Python 2.3
from bsddb import db
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
from test_all import verbose, get_new_environment_path, get_new_database_path
# We're going to get warnings in this module about trying to close the db when # We're going to get warnings in this module about trying to close the db when
# its env is already closed. Let's just ignore those. # its env is already closed. Let's just ignore those.
......
...@@ -5,14 +5,7 @@ TestCases for checking set_get_returns_none. ...@@ -5,14 +5,7 @@ TestCases for checking set_get_returns_none.
import os, string import os, string
import unittest import unittest
try: from test_all import db, verbose, get_new_database_path
# For Pythons w/distutils pybsddb
from bsddb3 import db
except ImportError:
# For Python 2.3
from bsddb import db
from test_all import verbose, get_new_database_path
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -39,8 +32,8 @@ class GetReturnsNoneTestCase(unittest.TestCase): ...@@ -39,8 +32,8 @@ class GetReturnsNoneTestCase(unittest.TestCase):
data = d.get('bad key') data = d.get('bad key')
self.assertEqual(data, None) self.assertEqual(data, None)
data = d.get('a') data = d.get(string.letters[0])
self.assertEqual(data, 'a'*40) self.assertEqual(data, string.letters[0]*40)
count = 0 count = 0
c = d.cursor() c = d.cursor()
...@@ -50,7 +43,7 @@ class GetReturnsNoneTestCase(unittest.TestCase): ...@@ -50,7 +43,7 @@ class GetReturnsNoneTestCase(unittest.TestCase):
rec = c.next() rec = c.next()
self.assertEqual(rec, None) self.assertEqual(rec, None)
self.assertEqual(count, 52) self.assertEqual(count, len(string.letters))
c.close() c.close()
d.close() d.close()
...@@ -67,8 +60,8 @@ class GetReturnsNoneTestCase(unittest.TestCase): ...@@ -67,8 +60,8 @@ class GetReturnsNoneTestCase(unittest.TestCase):
self.assertRaises(db.DBNotFoundError, d.get, 'bad key') self.assertRaises(db.DBNotFoundError, d.get, 'bad key')
self.assertRaises(KeyError, d.get, 'bad key') self.assertRaises(KeyError, d.get, 'bad key')
data = d.get('a') data = d.get(string.letters[0])
self.assertEqual(data, 'a'*40) self.assertEqual(data, string.letters[0]*40)
count = 0 count = 0
exceptionHappened = 0 exceptionHappened = 0
...@@ -84,7 +77,7 @@ class GetReturnsNoneTestCase(unittest.TestCase): ...@@ -84,7 +77,7 @@ class GetReturnsNoneTestCase(unittest.TestCase):
self.assertNotEqual(rec, None) self.assertNotEqual(rec, None)
self.assert_(exceptionHappened) self.assert_(exceptionHappened)
self.assertEqual(count, 52) self.assertEqual(count, len(string.letters))
c.close() c.close()
d.close() d.close()
......
...@@ -4,22 +4,9 @@ ...@@ -4,22 +4,9 @@
import os import os
import unittest import unittest
from test_all import verbose
try:
# For Pythons w/distutils pybsddb
from bsddb3 import db, dbshelve
except ImportError:
# For Python 2.3
from bsddb import db, dbshelve
from test_all import get_new_environment_path, get_new_database_path
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
from test_all import db, dbshelve, test_support, verbose, \
get_new_environment_path, get_new_database_path
#---------------------------------------------------------------------- #----------------------------------------------------------------------
......
...@@ -5,23 +5,16 @@ TestCases for testing the locking sub-system. ...@@ -5,23 +5,16 @@ TestCases for testing the locking sub-system.
import time import time
import unittest import unittest
from test_all import verbose, have_threads, get_new_environment_path, get_new_database_path from test_all import db, test_support, verbose, have_threads, \
get_new_environment_path, get_new_database_path
if have_threads : if have_threads :
from threading import Thread, currentThread from threading import Thread
import sys
try: if sys.version_info[0] < 3 :
# For Pythons w/distutils pybsddb from threading import currentThread
from bsddb3 import db else :
except ImportError: from threading import current_thread as currentThread
# For Python 2.3
from bsddb import db
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -87,7 +80,11 @@ class LockingTestCase(unittest.TestCase): ...@@ -87,7 +80,11 @@ class LockingTestCase(unittest.TestCase):
args=(db.DB_LOCK_WRITE,))) args=(db.DB_LOCK_WRITE,)))
for t in threads: for t in threads:
import sys
if sys.version_info[0] < 3 :
t.setDaemon(True) t.setDaemon(True)
else :
t.daemon = True
t.start() t.start()
for t in threads: for t in threads:
t.join() t.join()
...@@ -111,7 +108,11 @@ class LockingTestCase(unittest.TestCase): ...@@ -111,7 +108,11 @@ class LockingTestCase(unittest.TestCase):
deadlock_detection.end=False deadlock_detection.end=False
deadlock_detection.count=0 deadlock_detection.count=0
t=Thread(target=deadlock_detection) t=Thread(target=deadlock_detection)
import sys
if sys.version_info[0] < 3 :
t.setDaemon(True) t.setDaemon(True)
else :
t.daemon = True
t.start() t.start()
self.env.set_timeout(100000, db.DB_SET_LOCK_TIMEOUT) self.env.set_timeout(100000, db.DB_SET_LOCK_TIMEOUT)
anID = self.env.lock_id() anID = self.env.lock_id()
...@@ -134,7 +135,12 @@ class LockingTestCase(unittest.TestCase): ...@@ -134,7 +135,12 @@ class LockingTestCase(unittest.TestCase):
self.assertTrue(deadlock_detection.count>0) self.assertTrue(deadlock_detection.count>0)
def theThread(self, lockType): def theThread(self, lockType):
import sys
if sys.version_info[0] < 3 :
name = currentThread().getName() name = currentThread().getName()
else :
name = currentThread().name
if lockType == db.DB_LOCK_WRITE: if lockType == db.DB_LOCK_WRITE:
lt = "write" lt = "write"
else: else:
......
...@@ -4,19 +4,7 @@ ...@@ -4,19 +4,7 @@
import os import os
import unittest import unittest
try: from test_all import db, dbshelve, hashopen, test_support, get_new_environment_path, get_new_database_path
# For Pythons w/distutils pybsddb
from bsddb3 import db, dbshelve, hashopen
except ImportError:
# For Python 2.3
from bsddb import db, dbshelve, hashopen
from test_all import get_new_environment_path, get_new_database_path
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -39,7 +27,11 @@ class MiscTestCase(unittest.TestCase): ...@@ -39,7 +27,11 @@ class MiscTestCase(unittest.TestCase):
# check for crash fixed when db_home is used before open() # check for crash fixed when db_home is used before open()
self.assert_(env.db_home is None) self.assert_(env.db_home is None)
env.open(self.homeDir, db.DB_CREATE) env.open(self.homeDir, db.DB_CREATE)
import sys
if sys.version_info[0] < 3 :
self.assertEqual(self.homeDir, env.db_home) self.assertEqual(self.homeDir, env.db_home)
else :
self.assertEqual(bytes(self.homeDir, "ascii"), env.db_home)
def test03_repr_closed_db(self): def test03_repr_closed_db(self):
db = hashopen(self.filename) db = hashopen(self.filename)
......
...@@ -7,20 +7,7 @@ except ImportError: ...@@ -7,20 +7,7 @@ except ImportError:
cPickle = None cPickle = None
import unittest import unittest
try: from test_all import db, test_support, get_new_environment_path, get_new_database_path
# For Pythons w/distutils pybsddb
from bsddb3 import db
except ImportError, e:
# For Python 2.3
from bsddb import db
from test_all import get_new_environment_path, get_new_database_path
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
#---------------------------------------------------------------------- #----------------------------------------------------------------------
......
...@@ -6,15 +6,7 @@ import os, string ...@@ -6,15 +6,7 @@ import os, string
from pprint import pprint from pprint import pprint
import unittest import unittest
try: from test_all import db, verbose, get_new_database_path
# For Pythons w/distutils pybsddb
from bsddb3 import db
except ImportError:
# For Python 2.3
from bsddb import db
from test_all import verbose, get_new_database_path
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -47,14 +39,14 @@ class SimpleQueueTestCase(unittest.TestCase): ...@@ -47,14 +39,14 @@ class SimpleQueueTestCase(unittest.TestCase):
for x in string.letters: for x in string.letters:
d.append(x * 40) d.append(x * 40)
self.assertEqual(len(d), 52) self.assertEqual(len(d), len(string.letters))
d.put(100, "some more data") d.put(100, "some more data")
d.put(101, "and some more ") d.put(101, "and some more ")
d.put(75, "out of order") d.put(75, "out of order")
d.put(1, "replacement data") d.put(1, "replacement data")
self.assertEqual(len(d), 55) self.assertEqual(len(d), len(string.letters)+3)
if verbose: if verbose:
print "before close" + '-' * 30 print "before close" + '-' * 30
...@@ -69,7 +61,11 @@ class SimpleQueueTestCase(unittest.TestCase): ...@@ -69,7 +61,11 @@ class SimpleQueueTestCase(unittest.TestCase):
print "after open" + '-' * 30 print "after open" + '-' * 30
pprint(d.stat()) pprint(d.stat())
d.append("one more") # Test "txn" as a positional parameter
d.append("one more", None)
# Test "txn" as a keyword parameter
d.append("another one", txn=None)
c = d.cursor() c = d.cursor()
if verbose: if verbose:
...@@ -119,14 +115,14 @@ class SimpleQueueTestCase(unittest.TestCase): ...@@ -119,14 +115,14 @@ class SimpleQueueTestCase(unittest.TestCase):
for x in string.letters: for x in string.letters:
d.append(x * 40) d.append(x * 40)
self.assertEqual(len(d), 52) self.assertEqual(len(d), len(string.letters))
d.put(100, "some more data") d.put(100, "some more data")
d.put(101, "and some more ") d.put(101, "and some more ")
d.put(75, "out of order") d.put(75, "out of order")
d.put(1, "replacement data") d.put(1, "replacement data")
self.assertEqual(len(d), 55) self.assertEqual(len(d), len(string.letters)+3)
if verbose: if verbose:
print "before close" + '-' * 30 print "before close" + '-' * 30
......
...@@ -6,19 +6,7 @@ import errno ...@@ -6,19 +6,7 @@ import errno
from pprint import pprint from pprint import pprint
import unittest import unittest
from test_all import verbose, get_new_environment_path, get_new_database_path from test_all import db, test_support, verbose, get_new_environment_path, get_new_database_path
try:
# For Pythons w/distutils pybsddb
from bsddb3 import db
except ImportError:
# For Python 2.3
from bsddb import db
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
...@@ -72,7 +60,11 @@ class SimpleRecnoTestCase(unittest.TestCase): ...@@ -72,7 +60,11 @@ class SimpleRecnoTestCase(unittest.TestCase):
try: try:
data = d[0] # This should raise a KeyError!?!?! data = d[0] # This should raise a KeyError!?!?!
except db.DBInvalidArgError, val: except db.DBInvalidArgError, val:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.EINVAL) self.assertEqual(val[0], db.EINVAL)
else :
self.assertEqual(val.args[0], db.EINVAL)
if verbose: print val if verbose: print val
else: else:
self.fail("expected exception") self.fail("expected exception")
...@@ -277,7 +269,11 @@ class SimpleRecnoTestCase(unittest.TestCase): ...@@ -277,7 +269,11 @@ class SimpleRecnoTestCase(unittest.TestCase):
try: # this one will fail try: # this one will fail
d.append('bad' * 20) d.append('bad' * 20)
except db.DBInvalidArgError, val: except db.DBInvalidArgError, val:
import sys
if sys.version_info[0] < 3 :
self.assertEqual(val[0], db.EINVAL) self.assertEqual(val[0], db.EINVAL)
else :
self.assertEqual(val.args[0], db.EINVAL)
if verbose: print val if verbose: print val
else: else:
self.fail("expected exception") self.fail("expected exception")
......
...@@ -5,21 +5,9 @@ import os ...@@ -5,21 +5,9 @@ import os
import time import time
import unittest import unittest
try: from test_all import db, test_support, have_threads, verbose, \
# For Pythons w/distutils pybsddb get_new_environment_path, get_new_database_path
from bsddb3 import db
except ImportError:
# For Python 2.3
from bsddb import db
from test_all import have_threads, get_new_environment_path, get_new_database_path
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
from test_all import verbose
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -254,9 +242,14 @@ class DBBaseReplication(DBReplicationManager): ...@@ -254,9 +242,14 @@ class DBBaseReplication(DBReplicationManager):
from threading import Thread from threading import Thread
t_m=Thread(target=thread_master) t_m=Thread(target=thread_master)
t_m.setDaemon(True)
t_c=Thread(target=thread_client) t_c=Thread(target=thread_client)
import sys
if sys.version_info[0] < 3 :
t_m.setDaemon(True)
t_c.setDaemon(True) t_c.setDaemon(True)
else :
t_m.daemon = True
t_c.daemon = True
self.t_m = t_m self.t_m = t_m
self.t_c = t_c self.t_c = t_c
...@@ -400,7 +393,11 @@ class DBBaseReplication(DBReplicationManager): ...@@ -400,7 +393,11 @@ class DBBaseReplication(DBReplicationManager):
from threading import Thread from threading import Thread
election_status[0] = True election_status[0] = True
t=Thread(target=elect) t=Thread(target=elect)
import sys
if sys.version_info[0] < 3 :
t.setDaemon(True) t.setDaemon(True)
else :
t.daemon = True
t.start() t.start()
self.thread_do = thread_do self.thread_do = thread_do
......
import unittest import unittest
import os import os
try: from test_all import db, test_support, get_new_environment_path, get_new_database_path
# For Pythons w/distutils pybsddb
from bsddb3 import db
except ImportError:
from bsddb import db
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
from test_all import get_new_environment_path, get_new_database_path
class DBSequenceTest(unittest.TestCase): class DBSequenceTest(unittest.TestCase):
......
...@@ -16,23 +16,16 @@ except NameError: ...@@ -16,23 +16,16 @@ except NameError:
pass pass
import unittest import unittest
from test_all import verbose, have_threads, get_new_environment_path, get_new_database_path from test_all import db, dbutils, test_support, verbose, have_threads, \
get_new_environment_path, get_new_database_path
if have_threads : if have_threads :
from threading import Thread, currentThread from threading import Thread
import sys
if sys.version_info[0] < 3 :
try: from threading import currentThread
# For Pythons w/distutils pybsddb else :
from bsddb3 import db, dbutils from threading import current_thread as currentThread
except ImportError:
# For Python 2.3
from bsddb import db, dbutils
try:
from bsddb3 import test_support
except ImportError:
from test import test_support
#---------------------------------------------------------------------- #----------------------------------------------------------------------
...@@ -106,7 +99,11 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase): ...@@ -106,7 +99,11 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
args = (self.d, x), args = (self.d, x),
name = 'reader %d' % x, name = 'reader %d' % x,
)#verbose = verbose) )#verbose = verbose)
import sys
if sys.version_info[0] < 3 :
rt.setDaemon(True) rt.setDaemon(True)
else :
rt.daemon = True
readers.append(rt) readers.append(rt)
writers=[] writers=[]
...@@ -121,7 +118,11 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase): ...@@ -121,7 +118,11 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
writers.append(wt) writers.append(wt)
for t in writers: for t in writers:
import sys
if sys.version_info[0] < 3 :
t.setDaemon(True) t.setDaemon(True)
else :
t.daemon = True
t.start() t.start()
for t in writers: for t in writers:
...@@ -130,7 +131,12 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase): ...@@ -130,7 +131,12 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
t.join() t.join()
def writerThread(self, d, keys, readers): def writerThread(self, d, keys, readers):
import sys
if sys.version_info[0] < 3 :
name = currentThread().getName() name = currentThread().getName()
else :
name = currentThread().name
if verbose: if verbose:
print "%s: creating records %d - %d" % (name, start, stop) print "%s: creating records %d - %d" % (name, start, stop)
...@@ -155,7 +161,11 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase): ...@@ -155,7 +161,11 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
print "%s: thread finished" % name print "%s: thread finished" % name
def readerThread(self, d, readerNum): def readerThread(self, d, readerNum):
import sys
if sys.version_info[0] < 3 :
name = currentThread().getName() name = currentThread().getName()
else :
name = currentThread().name
for i in xrange(5) : for i in xrange(5) :
c = d.cursor() c = d.cursor()
...@@ -221,7 +231,11 @@ class SimpleThreadedBase(BaseThreadedTestCase): ...@@ -221,7 +231,11 @@ class SimpleThreadedBase(BaseThreadedTestCase):
args = (self.d, x), args = (self.d, x),
name = 'reader %d' % x, name = 'reader %d' % x,
)#verbose = verbose) )#verbose = verbose)
import sys
if sys.version_info[0] < 3 :
rt.setDaemon(True) rt.setDaemon(True)
else :
rt.daemon = True
readers.append(rt) readers.append(rt)
writers = [] writers = []
...@@ -236,7 +250,11 @@ class SimpleThreadedBase(BaseThreadedTestCase): ...@@ -236,7 +250,11 @@ class SimpleThreadedBase(BaseThreadedTestCase):
writers.append(wt) writers.append(wt)
for t in writers: for t in writers:
import sys
if sys.version_info[0] < 3 :
t.setDaemon(True) t.setDaemon(True)
else :
t.daemon = True
t.start() t.start()
for t in writers: for t in writers:
...@@ -245,7 +263,11 @@ class SimpleThreadedBase(BaseThreadedTestCase): ...@@ -245,7 +263,11 @@ class SimpleThreadedBase(BaseThreadedTestCase):
t.join() t.join()
def writerThread(self, d, keys, readers): def writerThread(self, d, keys, readers):
import sys
if sys.version_info[0] < 3 :
name = currentThread().getName() name = currentThread().getName()
else :
name = currentThread().name
if verbose: if verbose:
print "%s: creating records %d - %d" % (name, start, stop) print "%s: creating records %d - %d" % (name, start, stop)
...@@ -268,7 +290,11 @@ class SimpleThreadedBase(BaseThreadedTestCase): ...@@ -268,7 +290,11 @@ class SimpleThreadedBase(BaseThreadedTestCase):
print "%s: thread finished" % name print "%s: thread finished" % name
def readerThread(self, d, readerNum): def readerThread(self, d, readerNum):
import sys
if sys.version_info[0] < 3 :
name = currentThread().getName() name = currentThread().getName()
else :
name = currentThread().name
c = d.cursor() c = d.cursor()
count = 0 count = 0
...@@ -335,7 +361,11 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -335,7 +361,11 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
args = (self.d, x), args = (self.d, x),
name = 'reader %d' % x, name = 'reader %d' % x,
)#verbose = verbose) )#verbose = verbose)
import sys
if sys.version_info[0] < 3 :
rt.setDaemon(True) rt.setDaemon(True)
else :
rt.daemon = True
readers.append(rt) readers.append(rt)
writers = [] writers = []
...@@ -349,11 +379,19 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -349,11 +379,19 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
writers.append(wt) writers.append(wt)
dt = Thread(target = self.deadlockThread) dt = Thread(target = self.deadlockThread)
import sys
if sys.version_info[0] < 3 :
dt.setDaemon(True) dt.setDaemon(True)
else :
dt.daemon = True
dt.start() dt.start()
for t in writers: for t in writers:
import sys
if sys.version_info[0] < 3 :
t.setDaemon(True) t.setDaemon(True)
else :
t.daemon = True
t.start() t.start()
for t in writers: for t in writers:
...@@ -365,7 +403,12 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -365,7 +403,12 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
dt.join() dt.join()
def writerThread(self, d, keys, readers): def writerThread(self, d, keys, readers):
import sys
if sys.version_info[0] < 3 :
name = currentThread().getName() name = currentThread().getName()
else :
name = currentThread().name
count=len(keys)//len(readers) count=len(keys)//len(readers)
while len(keys): while len(keys):
try: try:
...@@ -388,7 +431,11 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -388,7 +431,11 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
print "%s: thread finished" % name print "%s: thread finished" % name
def readerThread(self, d, readerNum): def readerThread(self, d, readerNum):
import sys
if sys.version_info[0] < 3 :
name = currentThread().getName() name = currentThread().getName()
else :
name = currentThread().name
finished = False finished = False
while not finished: while not finished:
......
...@@ -488,8 +488,9 @@ Extension Modules ...@@ -488,8 +488,9 @@ Extension Modules
- Support for Windows 9x has been removed from the winsound module. - Support for Windows 9x has been removed from the winsound module.
- bsddb module updated to version 4.7.0. - bsddb module updated to version 4.7.3pre2.
http://www.jcea.es/programacion/pybsddb.htm#bsddb3-4.7.0 http://www.jcea.es/programacion/pybsddb.htm#bsddb3-4.7.3. This
code should be compatible with Python 3.0.
- Issue #2858: Fix potential memory corruption when - Issue #2858: Fix potential memory corruption when
bsddb.db.DBEnv.lock_get and other bsddb.db object constructors bsddb.db.DBEnv.lock_get and other bsddb.db object constructors
...@@ -2655,8 +2656,8 @@ Extension Modules ...@@ -2655,8 +2656,8 @@ Extension Modules
- fixed a bug with bsddb.DB.stat: the flags and txn keyword arguments - fixed a bug with bsddb.DB.stat: the flags and txn keyword arguments
were transposed. were transposed.
- Added support for linking the bsddb module against BerkeleyDB 4.5.x - Added support for linking the bsddb module against BerkeleyDB 4.5.x,
and 4.6.x. 4.6.x and 4.7.x.
- Bug #1633621: if curses.resizeterm() or curses.resize_term() is - Bug #1633621: if curses.resizeterm() or curses.resize_term() is
called, update _curses.LINES, _curses.COLS, curses.LINES and called, update _curses.LINES, _curses.COLS, curses.LINES and
......
This diff is collapsed.
...@@ -105,7 +105,7 @@ ...@@ -105,7 +105,7 @@
#error "eek! DBVER can't handle minor versions > 9" #error "eek! DBVER can't handle minor versions > 9"
#endif #endif
#define PY_BSDDB_VERSION "4.7.2devel9" #define PY_BSDDB_VERSION "4.7.3pre2"
/* Python object definitions */ /* Python object definitions */
...@@ -134,7 +134,7 @@ typedef struct { ...@@ -134,7 +134,7 @@ typedef struct {
PyObject* event_notifyCallback; PyObject* event_notifyCallback;
struct DBObject *children_dbs; struct DBObject *children_dbs;
struct DBTxnObject *children_txns; struct DBTxnObject *children_txns;
PyObject *private; PyObject *private_obj;
PyObject *rep_transport; PyObject *rep_transport;
PyObject *in_weakreflist; /* List of weak references */ PyObject *in_weakreflist; /* List of weak references */
} DBEnvObject; } DBEnvObject;
...@@ -159,7 +159,7 @@ typedef struct DBObject { ...@@ -159,7 +159,7 @@ typedef struct DBObject {
PyObject* associateCallback; PyObject* associateCallback;
PyObject* btCompareCallback; PyObject* btCompareCallback;
int primaryDBType; int primaryDBType;
PyObject *private; PyObject *private_obj;
PyObject *in_weakreflist; /* List of weak references */ PyObject *in_weakreflist; /* List of weak references */
} DBObject; } DBObject;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment