[packages/python] - updated bsddb code to 5.3.0 from http://pypi.python.org/pypi/bsddb3/ to support DB 5.3 - release

baggins baggins at pld-linux.org
Thu Sep 6 18:01:51 CEST 2012


commit 70e6ca94edaa137222e08166e3a4e2ff24d790c1
Author: Jan Rękorajski <baggins at pld-linux.org>
Date:   Thu Sep 6 18:01:04 2012 +0200

    - updated bsddb code to 5.3.0 from http://pypi.python.org/pypi/bsddb3/
      to support DB 5.3
    - release 6

 python-db.patch | 5687 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 python.spec     |    2 +-
 2 files changed, 5672 insertions(+), 17 deletions(-)
---
diff --git a/python.spec b/python.spec
index de3e649..3ee3c0d 100644
--- a/python.spec
+++ b/python.spec
@@ -43,7 +43,7 @@ Summary(tr.UTF-8):	X arayüzlü, yüksek düzeyli, kabuk yorumlayıcı dili
 Summary(uk.UTF-8):	Мова програмування дуже високого рівня з X-інтерфейсом
 Name:		python
 Version:	%{py_ver}.3
-Release:	5
+Release:	6
 Epoch:		1
 License:	PSF
 Group:		Development/Languages/Python
diff --git a/python-db.patch b/python-db.patch
index 3104976..963a0f3 100644
--- a/python-db.patch
+++ b/python-db.patch
@@ -1,39 +1,5694 @@
---- Python-2.7/setup.py.orig	2010-07-11 20:29:09.142656610 +0200
-+++ Python-2.7/setup.py	2010-07-12 08:43:42.578657448 +0200
-@@ -765,7 +765,7 @@
+Index: b/setup.py
+===================================================================
+--- a/setup.py
++++ b/setup.py
+@@ -799,7 +799,7 @@
          # a release.  Most open source OSes come with one or more
          # versions of BerkeleyDB already installed.
  
 -        max_db_ver = (4, 8)
-+        max_db_ver = (5, 0)
++        max_db_ver = (5, 3)
          min_db_ver = (4, 1)
-         db_setup_debug = True   # verbose debug prints from this script?
+         db_setup_debug = False   # verbose debug prints from this script?
  
-@@ -787,8 +787,12 @@
+@@ -821,7 +821,11 @@
              return True
  
          def gen_db_minor_ver_nums(major):
 -            if major == 4:
 +            if major == 5:
-                 for x in range(max_db_ver[1]+1):
-+		    if allow_db_ver((5, x)):
++                for x in range(max_db_ver[1]+1):
++                    if allow_db_ver((5, x)):
 +                        yield x
 +            elif major == 4:
-+                for x in range(0, 9):
+                 for x in range(max_db_ver[1]+1):
                      if allow_db_ver((4, x)):
                          yield x
-             elif major == 3:
---- Python-2.7/Modules/_bsddb.c.orig	2010-05-09 16:46:46.000000000 +0200
-+++ Python-2.7/Modules/_bsddb.c	2010-07-13 19:30:54.530654934 +0200
-@@ -9765,8 +9765,10 @@
+diff -urN Python-2.7.3/Lib/bsddb/dbobj.py bsddb3-5.3.0/Lib/bsddb/dbobj.py
+--- Python-2.7.3/Lib/bsddb/dbobj.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/dbobj.py	2012-01-16 18:43:15.000000000 +0100
+@@ -30,12 +30,7 @@
+     import db
+ 
+ if sys.version_info < (2, 6) :
+-    try:
+-        from UserDict import DictMixin
+-    except ImportError:
+-        # DictMixin is new in Python 2.3
+-        class DictMixin: pass
+-    MutableMapping = DictMixin
++    from UserDict import DictMixin as MutableMapping
+ else :
+     import collections
+     MutableMapping = collections.MutableMapping
+@@ -196,6 +191,8 @@
+         return self._cobj.set_bt_compare(*args, **kwargs)
+     def set_cachesize(self, *args, **kwargs):
+         return self._cobj.set_cachesize(*args, **kwargs)
++    def set_dup_compare(self, *args, **kwargs) :
++        return self._cobj.set_dup_compare(*args, **kwargs)
+     def set_flags(self, *args, **kwargs):
+         return self._cobj.set_flags(*args, **kwargs)
+     def set_h_ffactor(self, *args, **kwargs):
+diff -urN Python-2.7.3/Lib/bsddb/dbshelve.py bsddb3-5.3.0/Lib/bsddb/dbshelve.py
+--- Python-2.7.3/Lib/bsddb/dbshelve.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/dbshelve.py	2012-01-16 19:24:34.000000000 +0100
+@@ -43,7 +43,7 @@
+     if sys.version_info < (2, 6) :
+         import cPickle
+     else :
+-        # When we drop support for python 2.3 and 2.4
++        # When we drop support for python 2.4
+         # we could use: (in 2.5 we need a __future__ statement)
+         #
+         #    with warnings.catch_warnings():
+@@ -51,7 +51,7 @@
+         #        ...
+         #
+         # We can not use "with" as is, because it would be invalid syntax
+-        # in python 2.3, 2.4 and (with no __future__) 2.5.
++        # in python 2.4 and (with no __future__) 2.5.
+         # Here we simulate "with" following PEP 343 :
+         import warnings
+         w = warnings.catch_warnings()
+@@ -65,32 +65,12 @@
+             w.__exit__()
+         del w
+ 
+-#At version 2.3 cPickle switched to using protocol instead of bin
+-if sys.version_info >= (2, 3):
+-    HIGHEST_PROTOCOL = cPickle.HIGHEST_PROTOCOL
+-# In python 2.3.*, "cPickle.dumps" accepts no
+-# named parameters. "pickle.dumps" accepts them,
+-# so this seems a bug.
+-    if sys.version_info < (2, 4):
+-        def _dumps(object, protocol):
+-            return cPickle.dumps(object, protocol)
+-    else :
+-        def _dumps(object, protocol):
+-            return cPickle.dumps(object, protocol=protocol)
+-
+-else:
+-    HIGHEST_PROTOCOL = None
+-    def _dumps(object, protocol):
+-        return cPickle.dumps(object, bin=protocol)
+-
++HIGHEST_PROTOCOL = cPickle.HIGHEST_PROTOCOL
++def _dumps(object, protocol):
++    return cPickle.dumps(object, protocol=protocol)
+ 
+ if sys.version_info < (2, 6) :
+-    try:
+-        from UserDict import DictMixin
+-    except ImportError:
+-        # DictMixin is new in Python 2.3
+-        class DictMixin: pass
+-    MutableMapping = DictMixin
++    from UserDict import DictMixin as MutableMapping
+ else :
+     import collections
+     MutableMapping = collections.MutableMapping
+diff -urN Python-2.7.3/Lib/bsddb/dbtables.py bsddb3-5.3.0/Lib/bsddb/dbtables.py
+--- Python-2.7.3/Lib/bsddb/dbtables.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/dbtables.py	2012-01-16 19:18:15.000000000 +0100
+@@ -15,7 +15,7 @@
+ # This provides a simple database table interface built on top of
+ # the Python Berkeley DB 3 interface.
+ #
+-_cvsid = '$Id$'
++_cvsid = '$Id: dbtables.py,v 53e5f052c511 2012/01/16 18:18:15 jcea $'
+ 
+ import re
+ import sys
+@@ -30,7 +30,7 @@
+     if sys.version_info < (2, 6) :
+         import cPickle as pickle
+     else :
+-        # When we drop support for python 2.3 and 2.4
++        # When we drop support for python 2.4
+         # we could use: (in 2.5 we need a __future__ statement)
+         #
+         #    with warnings.catch_warnings():
+@@ -38,7 +38,7 @@
+         #        ...
+         #
+         # We can not use "with" as is, because it would be invalid syntax
+-        # in python 2.3, 2.4 and (with no __future__) 2.5.
++        # in python 2.4 and (with no __future__) 2.5.
+         # Here we simulate "with" following PEP 343 :
+         import warnings
+         w = warnings.catch_warnings()
+@@ -52,12 +52,7 @@
+             w.__exit__()
+         del w
+ 
+-try:
+-    # For Pythons w/distutils pybsddb
+-    from bsddb3 import db
+-except ImportError:
+-    # For Python 2.3
+-    from bsddb import db
++from bsddb3 import db
+ 
+ class TableDBError(StandardError):
+     pass
+diff -urN Python-2.7.3/Lib/bsddb/__init__.py bsddb3-5.3.0/Lib/bsddb/__init__.py
+--- Python-2.7.3/Lib/bsddb/__init__.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/__init__.py	2012-01-16 18:53:27.000000000 +0100
+@@ -33,7 +33,7 @@
+ #----------------------------------------------------------------------
+ 
+ 
+-"""Support for Berkeley DB 4.1 through 4.8 with a simple interface.
++"""Support for Berkeley DB 4.3 through 5.3 with a simple interface.
+ 
+ For the full featured object oriented interface use the bsddb.db module
+ instead.  It mirrors the Oracle Berkeley DB C API.
+@@ -43,13 +43,11 @@
+ absolute_import = (sys.version_info[0] >= 3)
+ 
+ if (sys.version_info >= (2, 6)) and (sys.version_info < (3, 0)) :
+-    import warnings
+     if sys.py3kwarning and (__name__ != 'bsddb3') :
++        import warnings
+         warnings.warnpy3k("in 3.x, the bsddb module has been removed; "
+                           "please use the pybsddb project instead",
+                           DeprecationWarning, 2)
+-    warnings.filterwarnings("ignore", ".*CObject.*", DeprecationWarning,
+-                            "bsddb.__init__")
+ 
+ try:
+     if __name__ == 'bsddb3':
+@@ -138,7 +136,7 @@
+             except _bsddb.DBCursorClosedError:
+                 # the database was modified during iteration.  abort.
+                 pass
+-# When Python 2.3 not supported in bsddb3, we can change this to "finally"
++# When Python 2.4 not supported in bsddb3, we can change this to "finally"
+         except :
+             self._in_iter -= 1
+             raise
+@@ -181,7 +179,7 @@
+             except _bsddb.DBCursorClosedError:
+                 # the database was modified during iteration.  abort.
+                 pass
+-# When Python 2.3 not supported in bsddb3, we can change this to "finally"
++# When Python 2.4 not supported in bsddb3, we can change this to "finally"
+         except :
+             self._in_iter -= 1
+             raise
+diff -urN Python-2.7.3/Lib/bsddb/test/test_all.py bsddb3-5.3.0/Lib/bsddb/test/test_all.py
+--- Python-2.7.3/Lib/bsddb/test/test_all.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_all.py	2012-01-16 19:02:45.000000000 +0100
+@@ -4,12 +4,7 @@
+ import sys
+ import os
+ import unittest
+-try:
+-    # For Pythons w/distutils pybsddb
+-    import bsddb3 as bsddb
+-except ImportError:
+-    # For Python 2.3
+-    import bsddb
++import bsddb3 as bsddb
+ 
+ 
+ if sys.version_info[0] >= 3 :
+@@ -392,10 +387,8 @@
+             return self._dbenv.get_tmp_dir().decode(charset)
+ 
+         def get_data_dirs(self) :
+-            # Have to use a list comprehension and not
+-            # generators, because we are supporting Python 2.3.
+             return tuple(
+-                [i.decode(charset) for i in self._dbenv.get_data_dirs()])
++                (i.decode(charset) for i in self._dbenv.get_data_dirs()))
+ 
+     class DBSequence_py3k(object) :
+         def __init__(self, db, *args, **kwargs) :
+@@ -440,14 +433,8 @@
+     do_proxy_db_py3k.flag = False
+     do_proxy_db_py3k(True)
+ 
+-try:
+-    # For Pythons w/distutils pybsddb
+-    from bsddb3 import db, dbtables, dbutils, dbshelve, \
+-            hashopen, btopen, rnopen, dbobj
+-except ImportError:
+-    # For Python 2.3
+-    from bsddb import db, dbtables, dbutils, dbshelve, \
+-            hashopen, btopen, rnopen, dbobj
++from bsddb3 import db, dbtables, dbutils, dbshelve, \
++        hashopen, btopen, rnopen, dbobj
+ 
+ try:
+     from bsddb3 import test_support
+@@ -484,6 +471,8 @@
+     print '-=' * 38
+     print db.DB_VERSION_STRING
+     print 'bsddb.db.version():   %s' % (db.version(), )
++    if db.version() >= (5, 0) :
++        print 'bsddb.db.full_version(): %s' %repr(db.full_version())
+     print 'bsddb.db.__version__: %s' % db.__version__
+     print 'bsddb.db.cvsid:       %s' % db.cvsid
+ 
+@@ -528,7 +517,8 @@
+ 
+ # This path can be overriden via "set_test_path_prefix()".
+ import os, os.path
+-get_new_path.prefix=os.path.join(os.sep,"tmp","z-Berkeley_DB")
++get_new_path.prefix=os.path.join(os.environ.get("TMPDIR",
++    os.path.join(os.sep,"tmp")), "z-Berkeley_DB")
+ get_new_path.num=0
+ 
+ def get_test_path_prefix() :
+diff -urN Python-2.7.3/Lib/bsddb/test/test_basics.py bsddb3-5.3.0/Lib/bsddb/test/test_basics.py
+--- Python-2.7.3/Lib/bsddb/test/test_basics.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_basics.py	2012-01-16 19:14:38.000000000 +0100
+@@ -9,6 +9,7 @@
+ from pprint import pprint
+ import unittest
+ import time
++import sys
+ 
+ from test_all import db, test_support, verbose, get_new_environment_path, \
+         get_new_database_path
+@@ -44,13 +45,6 @@
+ 
+     _numKeys      = 1002    # PRIVATE.  NOTE: must be an even value
+ 
+-    import sys
+-    if sys.version_info < (2, 4):
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-        def assertFalse(self, expr, msg=None):
+-            self.failIf(expr,msg=msg)
+-
+     def setUp(self):
+         if self.useEnv:
+             self.homeDir=get_new_environment_path()
+@@ -74,14 +68,13 @@
+         # create and open the DB
+         self.d = db.DB(self.env)
+         if not self.useEnv :
+-            if db.version() >= (4, 2) :
+-                self.d.set_cachesize(*self.cachesize)
+-                cachesize = self.d.get_cachesize()
+-                self.assertEqual(cachesize[0], self.cachesize[0])
+-                self.assertEqual(cachesize[2], self.cachesize[2])
+-                # Berkeley DB expands the cache 25% accounting overhead,
+-                # if the cache is small.
+-                self.assertEqual(125, int(100.0*cachesize[1]/self.cachesize[1]))
++            self.d.set_cachesize(*self.cachesize)
++            cachesize = self.d.get_cachesize()
++            self.assertEqual(cachesize[0], self.cachesize[0])
++            self.assertEqual(cachesize[2], self.cachesize[2])
++            # Berkeley DB expands the cache 25% accounting overhead,
++            # if the cache is small.
++            self.assertEqual(125, int(100.0*cachesize[1]/self.cachesize[1]))
+         self.d.set_flags(self.dbsetflags)
+         if self.dbname:
+             self.d.open(self.filename, self.dbname, self.dbtype,
+@@ -161,7 +154,6 @@
+         try:
+             d.delete('abcd')
+         except db.DBNotFoundError, val:
+-            import sys
+             if sys.version_info < (2, 6) :
+                 self.assertEqual(val[0], db.DB_NOTFOUND)
+             else :
+@@ -184,7 +176,6 @@
+         try:
+             d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE)
+         except db.DBKeyExistError, val:
+-            import sys
+             if sys.version_info < (2, 6) :
+                 self.assertEqual(val[0], db.DB_KEYEXIST)
+             else :
+@@ -338,7 +329,6 @@
+                 rec = c.next()
+             except db.DBNotFoundError, val:
+                 if get_raises_error:
+-                    import sys
+                     if sys.version_info < (2, 6) :
+                         self.assertEqual(val[0], db.DB_NOTFOUND)
+                     else :
+@@ -363,7 +353,6 @@
+                 rec = c.prev()
+             except db.DBNotFoundError, val:
+                 if get_raises_error:
+-                    import sys
+                     if sys.version_info < (2, 6) :
+                         self.assertEqual(val[0], db.DB_NOTFOUND)
+                     else :
+@@ -390,7 +379,6 @@
+         try:
+             n = c.set('bad key')
+         except db.DBNotFoundError, val:
+-            import sys
+             if sys.version_info < (2, 6) :
+                 self.assertEqual(val[0], db.DB_NOTFOUND)
+             else :
+@@ -408,7 +396,6 @@
+         try:
+             n = c.get_both('0404', 'bad data')
+         except db.DBNotFoundError, val:
+-            import sys
+             if sys.version_info < (2, 6) :
+                 self.assertEqual(val[0], db.DB_NOTFOUND)
+             else :
+@@ -441,7 +428,6 @@
+             rec = c.current()
+         except db.DBKeyEmptyError, val:
+             if get_raises_error:
+-                import sys
+                 if sys.version_info < (2, 6) :
+                     self.assertEqual(val[0], db.DB_KEYEMPTY)
+                 else :
+@@ -490,7 +476,6 @@
+                 # a bug may cause a NULL pointer dereference...
+                 getattr(c, method)(*args)
+             except db.DBError, val:
+-                import sys
+                 if sys.version_info < (2, 6) :
+                     self.assertEqual(val[0], 0)
+                 else :
+@@ -712,11 +697,6 @@
+ #----------------------------------------------------------------------
+ 
+ class BasicTransactionTestCase(BasicTestCase):
+-    import sys
+-    if sys.version_info < (2, 4):
+-        def assertTrue(self, expr, msg=None):
+-            return self.failUnless(expr,msg=msg)
+-
+     if (sys.version_info < (2, 7)) or ((sys.version_info >= (3, 0)) and
+             (sys.version_info < (3, 2))) :
+         def assertIn(self, a, b, msg=None) :
+@@ -792,9 +772,8 @@
+         for log in logs:
+             if verbose:
+                 print 'log file: ' + log
+-        if db.version() >= (4,2):
+-            logs = self.env.log_archive(db.DB_ARCH_REMOVE)
+-            self.assertTrue(not logs)
++        logs = self.env.log_archive(db.DB_ARCH_REMOVE)
++        self.assertTrue(not logs)
+ 
+         self.txn = self.env.txn_begin()
+ 
+@@ -875,12 +854,11 @@
+ 
+     #----------------------------------------
+ 
+-    if db.version() >= (4, 2) :
+-        def test_get_tx_max(self) :
+-            self.assertEqual(self.env.get_tx_max(), 30)
++    def test_get_tx_max(self) :
++        self.assertEqual(self.env.get_tx_max(), 30)
+ 
+-        def test_get_tx_timestamp(self) :
+-            self.assertEqual(self.env.get_tx_timestamp(), self._t)
++    def test_get_tx_timestamp(self) :
++        self.assertEqual(self.env.get_tx_timestamp(), self._t)
+ 
+ 
+ 
+@@ -1098,11 +1076,6 @@
+ 
+ 
+ class PrivateObject(unittest.TestCase) :
+-    import sys
+-    if sys.version_info < (2, 4):
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+     def tearDown(self) :
+         del self.obj
+ 
+@@ -1116,7 +1089,6 @@
+         self.assertTrue(a is b)  # Object identity
+ 
+     def test03_leak_assignment(self) :
+-        import sys
+         a = "example of private object"
+         refcount = sys.getrefcount(a)
+         self.obj.set_private(a)
+@@ -1125,7 +1097,6 @@
+         self.assertEqual(refcount, sys.getrefcount(a))
+ 
+     def test04_leak_GC(self) :
+-        import sys
+         a = "example of private object"
+         refcount = sys.getrefcount(a)
+         self.obj.set_private(a)
+@@ -1141,11 +1112,6 @@
+         self.obj = db.DB()
+ 
+ class CrashAndBurn(unittest.TestCase) :
+-    import sys
+-    if sys.version_info < (2, 4):
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+     #def test01_OpenCrash(self) :
+     #    # See http://bugs.python.org/issue3307
+     #    self.assertRaises(db.DBInvalidArgError, db.DB, None, 65535)
+diff -urN Python-2.7.3/Lib/bsddb/test/test_compare.py bsddb3-5.3.0/Lib/bsddb/test/test_compare.py
+--- Python-2.7.3/Lib/bsddb/test/test_compare.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_compare.py	2012-01-16 19:11:19.000000000 +0100
+@@ -1,5 +1,5 @@
+ """
+-TestCases for python DB Btree key comparison function.
++TestCases for python DB duplicate and Btree key comparison function.
+ """
+ 
+ import sys, os, re
+@@ -20,31 +20,24 @@
+ 
+ lexical_cmp = cmp
+ 
+-def lowercase_cmp(left, right):
+-    return cmp (left.lower(), right.lower())
++def lowercase_cmp(left, right) :
++    return cmp(left.lower(), right.lower())
+ 
+-def make_reverse_comparator (cmp):
+-    def reverse (left, right, delegate=cmp):
+-        return - delegate (left, right)
++def make_reverse_comparator(cmp) :
++    def reverse(left, right, delegate=cmp) :
++        return - delegate(left, right)
+     return reverse
+ 
+ _expected_lexical_test_data = ['', 'CCCP', 'a', 'aaa', 'b', 'c', 'cccce', 'ccccf']
+ _expected_lowercase_test_data = ['', 'a', 'aaa', 'b', 'c', 'CC', 'cccce', 'ccccf', 'CCCP']
+ 
+-class ComparatorTests (unittest.TestCase):
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None) :
+-            return self.failUnless(expr,msg=msg)
+-
+-    def comparator_test_helper (self, comparator, expected_data):
++class ComparatorTests(unittest.TestCase) :
++    def comparator_test_helper(self, comparator, expected_data) :
+         data = expected_data[:]
+ 
+         import sys
+         if sys.version_info < (2, 6) :
+-            if sys.version_info < (2, 4) :
+-                data.sort(comparator)
+-            else :
+-                data.sort(cmp=comparator)
++            data.sort(cmp=comparator)
+         else :  # Insertion Sort. Please, improve
+             data2 = []
+             for i in data :
+@@ -60,143 +53,139 @@
+         self.assertEqual(data, expected_data,
+                          "comparator `%s' is not right: %s vs. %s"
+                          % (comparator, expected_data, data))
+-    def test_lexical_comparator (self):
+-        self.comparator_test_helper (lexical_cmp, _expected_lexical_test_data)
+-    def test_reverse_lexical_comparator (self):
++    def test_lexical_comparator(self) :
++        self.comparator_test_helper(lexical_cmp, _expected_lexical_test_data)
++    def test_reverse_lexical_comparator(self) :
+         rev = _expected_lexical_test_data[:]
+-        rev.reverse ()
+-        self.comparator_test_helper (make_reverse_comparator (lexical_cmp),
++        rev.reverse()
++        self.comparator_test_helper(make_reverse_comparator(lexical_cmp),
+                                      rev)
+-    def test_lowercase_comparator (self):
+-        self.comparator_test_helper (lowercase_cmp,
++    def test_lowercase_comparator(self) :
++        self.comparator_test_helper(lowercase_cmp,
+                                      _expected_lowercase_test_data)
+ 
+-class AbstractBtreeKeyCompareTestCase (unittest.TestCase):
++class AbstractBtreeKeyCompareTestCase(unittest.TestCase) :
+     env = None
+     db = None
+ 
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+     if (sys.version_info < (2, 7)) or ((sys.version_info >= (3,0)) and
+             (sys.version_info < (3, 2))) :
+         def assertLess(self, a, b, msg=None) :
+             return self.assertTrue(a<b, msg=msg)
+ 
+-    def setUp (self):
++    def setUp(self) :
+         self.filename = self.__class__.__name__ + '.db'
+         self.homeDir = get_new_environment_path()
+         env = db.DBEnv()
+-        env.open (self.homeDir,
++        env.open(self.homeDir,
+                   db.DB_CREATE | db.DB_INIT_MPOOL
+                   | db.DB_INIT_LOCK | db.DB_THREAD)
+         self.env = env
+ 
+-    def tearDown (self):
++    def tearDown(self) :
+         self.closeDB()
+         if self.env is not None:
+             self.env.close()
+             self.env = None
+         test_support.rmtree(self.homeDir)
+ 
+-    def addDataToDB (self, data):
++    def addDataToDB(self, data) :
+         i = 0
+         for item in data:
+-            self.db.put (item, str (i))
++            self.db.put(item, str(i))
+             i = i + 1
+ 
+-    def createDB (self, key_comparator):
+-        self.db = db.DB (self.env)
+-        self.setupDB (key_comparator)
+-        self.db.open (self.filename, "test", db.DB_BTREE, db.DB_CREATE)
++    def createDB(self, key_comparator) :
++        self.db = db.DB(self.env)
++        self.setupDB(key_comparator)
++        self.db.open(self.filename, "test", db.DB_BTREE, db.DB_CREATE)
+ 
+-    def setupDB (self, key_comparator):
+-        self.db.set_bt_compare (key_comparator)
++    def setupDB(self, key_comparator) :
++        self.db.set_bt_compare(key_comparator)
+ 
+-    def closeDB (self):
++    def closeDB(self) :
+         if self.db is not None:
+-            self.db.close ()
++            self.db.close()
+             self.db = None
+ 
+-    def startTest (self):
++    def startTest(self) :
+         pass
+ 
+-    def finishTest (self, expected = None):
++    def finishTest(self, expected = None) :
+         if expected is not None:
+-            self.check_results (expected)
+-        self.closeDB ()
++            self.check_results(expected)
++        self.closeDB()
+ 
+-    def check_results (self, expected):
+-        curs = self.db.cursor ()
++    def check_results(self, expected) :
++        curs = self.db.cursor()
+         try:
+             index = 0
+-            rec = curs.first ()
++            rec = curs.first()
+             while rec:
+                 key, ignore = rec
+-                self.assertLess(index, len (expected),
++                self.assertLess(index, len(expected),
+                                  "to many values returned from cursor")
+                 self.assertEqual(expected[index], key,
+                                  "expected value `%s' at %d but got `%s'"
+                                  % (expected[index], index, key))
+                 index = index + 1
+-                rec = curs.next ()
+-            self.assertEqual(index, len (expected),
++                rec = curs.next()
++            self.assertEqual(index, len(expected),
+                              "not enough values returned from cursor")
+         finally:
+-            curs.close ()
++            curs.close()
+ 
+-class BtreeKeyCompareTestCase (AbstractBtreeKeyCompareTestCase):
+-    def runCompareTest (self, comparator, data):
+-        self.startTest ()
+-        self.createDB (comparator)
+-        self.addDataToDB (data)
+-        self.finishTest (data)
++class BtreeKeyCompareTestCase(AbstractBtreeKeyCompareTestCase) :
++    def runCompareTest(self, comparator, data) :
++        self.startTest()
++        self.createDB(comparator)
++        self.addDataToDB(data)
++        self.finishTest(data)
+ 
+-    def test_lexical_ordering (self):
+-        self.runCompareTest (lexical_cmp, _expected_lexical_test_data)
++    def test_lexical_ordering(self) :
++        self.runCompareTest(lexical_cmp, _expected_lexical_test_data)
+ 
+-    def test_reverse_lexical_ordering (self):
++    def test_reverse_lexical_ordering(self) :
+         expected_rev_data = _expected_lexical_test_data[:]
+-        expected_rev_data.reverse ()
+-        self.runCompareTest (make_reverse_comparator (lexical_cmp),
++        expected_rev_data.reverse()
++        self.runCompareTest(make_reverse_comparator(lexical_cmp),
+                              expected_rev_data)
+ 
+-    def test_compare_function_useless (self):
+-        self.startTest ()
+-        def socialist_comparator (l, r):
++    def test_compare_function_useless(self) :
++        self.startTest()
++        def socialist_comparator(l, r) :
+             return 0
+-        self.createDB (socialist_comparator)
+-        self.addDataToDB (['b', 'a', 'd'])
++        self.createDB(socialist_comparator)
++        self.addDataToDB(['b', 'a', 'd'])
+         # all things being equal the first key will be the only key
+         # in the database...  (with the last key's value fwiw)
+-        self.finishTest (['b'])
++        self.finishTest(['b'])
++
+ 
++class BtreeExceptionsTestCase(AbstractBtreeKeyCompareTestCase) :
++    def test_raises_non_callable(self) :
++        self.startTest()
++        self.assertRaises(TypeError, self.createDB, 'abc')
++        self.assertRaises(TypeError, self.createDB, None)
++        self.finishTest()
+ 
+-class BtreeExceptionsTestCase (AbstractBtreeKeyCompareTestCase):
+-    def test_raises_non_callable (self):
+-        self.startTest ()
+-        self.assertRaises (TypeError, self.createDB, 'abc')
+-        self.assertRaises (TypeError, self.createDB, None)
+-        self.finishTest ()
+-
+-    def test_set_bt_compare_with_function (self):
+-        self.startTest ()
+-        self.createDB (lexical_cmp)
+-        self.finishTest ()
++    def test_set_bt_compare_with_function(self) :
++        self.startTest()
++        self.createDB(lexical_cmp)
++        self.finishTest()
+ 
+-    def check_results (self, results):
++    def check_results(self, results) :
+         pass
+ 
+-    def test_compare_function_incorrect (self):
+-        self.startTest ()
+-        def bad_comparator (l, r):
++    def test_compare_function_incorrect(self) :
++        self.startTest()
++        def bad_comparator(l, r) :
+             return 1
+         # verify that set_bt_compare checks that comparator('', '') == 0
+-        self.assertRaises (TypeError, self.createDB, bad_comparator)
+-        self.finishTest ()
++        self.assertRaises(TypeError, self.createDB, bad_comparator)
++        self.finishTest()
+ 
+-    def verifyStderr(self, method, successRe):
++    def verifyStderr(self, method, successRe) :
+         """
+         Call method() while capturing sys.stderr output internally and
+         call self.fail() if successRe.search() does not match the stderr
+@@ -210,64 +199,249 @@
+             temp = sys.stderr
+             sys.stderr = stdErr
+             errorOut = temp.getvalue()
+-            if not successRe.search(errorOut):
++            if not successRe.search(errorOut) :
+                 self.fail("unexpected stderr output:\n"+errorOut)
+         if sys.version_info < (3, 0) :  # XXX: How to do this in Py3k ???
+             sys.exc_traceback = sys.last_traceback = None
+ 
+-    def _test_compare_function_exception (self):
+-        self.startTest ()
+-        def bad_comparator (l, r):
++    def _test_compare_function_exception(self) :
++        self.startTest()
++        def bad_comparator(l, r) :
+             if l == r:
+                 # pass the set_bt_compare test
+                 return 0
+             raise RuntimeError, "i'm a naughty comparison function"
+-        self.createDB (bad_comparator)
++        self.createDB(bad_comparator)
+         #print "\n*** test should print 2 uncatchable tracebacks ***"
+-        self.addDataToDB (['a', 'b', 'c'])  # this should raise, but...
+-        self.finishTest ()
++        self.addDataToDB(['a', 'b', 'c'])  # this should raise, but...
++        self.finishTest()
+ 
+-    def test_compare_function_exception(self):
++    def test_compare_function_exception(self) :
+         self.verifyStderr(
+                 self._test_compare_function_exception,
+                 re.compile('(^RuntimeError:.* naughty.*){2}', re.M|re.S)
+         )
+ 
+-    def _test_compare_function_bad_return (self):
+-        self.startTest ()
+-        def bad_comparator (l, r):
++    def _test_compare_function_bad_return(self) :
++        self.startTest()
++        def bad_comparator(l, r) :
+             if l == r:
+                 # pass the set_bt_compare test
+                 return 0
+             return l
+-        self.createDB (bad_comparator)
++        self.createDB(bad_comparator)
++        #print "\n*** test should print 2 errors about returning an int ***"
++        self.addDataToDB(['a', 'b', 'c'])  # this should raise, but...
++        self.finishTest()
++
++    def test_compare_function_bad_return(self) :
++        self.verifyStderr(
++                self._test_compare_function_bad_return,
++                re.compile('(^TypeError:.* return an int.*){2}', re.M|re.S)
++        )
++
++
++    def test_cannot_assign_twice(self) :
++
++        def my_compare(a, b) :
++            return 0
++
++        self.startTest()
++        self.createDB(my_compare)
++        self.assertRaises(RuntimeError, self.db.set_bt_compare, my_compare)
++
++class AbstractDuplicateCompareTestCase(unittest.TestCase) :
++    env = None
++    db = None
++
++    if (sys.version_info < (2, 7)) or ((sys.version_info >= (3,0)) and
++            (sys.version_info < (3, 2))) :
++        def assertLess(self, a, b, msg=None) :
++            return self.assertTrue(a<b, msg=msg)
++
++    def setUp(self) :
++        self.filename = self.__class__.__name__ + '.db'
++        self.homeDir = get_new_environment_path()
++        env = db.DBEnv()
++        env.open(self.homeDir,
++                  db.DB_CREATE | db.DB_INIT_MPOOL
++                  | db.DB_INIT_LOCK | db.DB_THREAD)
++        self.env = env
++
++    def tearDown(self) :
++        self.closeDB()
++        if self.env is not None:
++            self.env.close()
++            self.env = None
++        test_support.rmtree(self.homeDir)
++
++    def addDataToDB(self, data) :
++        for item in data:
++            self.db.put("key", item)
++
++    def createDB(self, dup_comparator) :
++        self.db = db.DB(self.env)
++        self.setupDB(dup_comparator)
++        self.db.open(self.filename, "test", db.DB_BTREE, db.DB_CREATE)
++
++    def setupDB(self, dup_comparator) :
++        self.db.set_flags(db.DB_DUPSORT)
++        self.db.set_dup_compare(dup_comparator)
++
++    def closeDB(self) :
++        if self.db is not None:
++            self.db.close()
++            self.db = None
++
++    def startTest(self) :
++        pass
++
++    def finishTest(self, expected = None) :
++        if expected is not None:
++            self.check_results(expected)
++        self.closeDB()
++
++    def check_results(self, expected) :
++        curs = self.db.cursor()
++        try:
++            index = 0
++            rec = curs.first()
++            while rec:
++                ignore, data = rec
++                self.assertLess(index, len(expected),
++                                 "to many values returned from cursor")
++                self.assertEqual(expected[index], data,
++                                 "expected value `%s' at %d but got `%s'"
++                                 % (expected[index], index, data))
++                index = index + 1
++                rec = curs.next()
++            self.assertEqual(index, len(expected),
++                             "not enough values returned from cursor")
++        finally:
++            curs.close()
++
++class DuplicateCompareTestCase(AbstractDuplicateCompareTestCase) :
++    def runCompareTest(self, comparator, data) :
++        self.startTest()
++        self.createDB(comparator)
++        self.addDataToDB(data)
++        self.finishTest(data)
++
++    def test_lexical_ordering(self) :
++        self.runCompareTest(lexical_cmp, _expected_lexical_test_data)
++
++    def test_reverse_lexical_ordering(self) :
++        expected_rev_data = _expected_lexical_test_data[:]
++        expected_rev_data.reverse()
++        self.runCompareTest(make_reverse_comparator(lexical_cmp),
++                             expected_rev_data)
++
++class DuplicateExceptionsTestCase(AbstractDuplicateCompareTestCase) :
++    def test_raises_non_callable(self) :
++        self.startTest()
++        self.assertRaises(TypeError, self.createDB, 'abc')
++        self.assertRaises(TypeError, self.createDB, None)
++        self.finishTest()
++
++    def test_set_dup_compare_with_function(self) :
++        self.startTest()
++        self.createDB(lexical_cmp)
++        self.finishTest()
++
++    def check_results(self, results) :
++        pass
++
++    def test_compare_function_incorrect(self) :
++        self.startTest()
++        def bad_comparator(l, r) :
++            return 1
++        # verify that set_dup_compare checks that comparator('', '') == 0
++        self.assertRaises(TypeError, self.createDB, bad_comparator)
++        self.finishTest()
++
++    def test_compare_function_useless(self) :
++        self.startTest()
++        def socialist_comparator(l, r) :
++            return 0
++        self.createDB(socialist_comparator)
++        # DUPSORT does not allow "duplicate duplicates"
++        self.assertRaises(db.DBKeyExistError, self.addDataToDB, ['b', 'a', 'd'])
++        self.finishTest()
++
++    def verifyStderr(self, method, successRe) :
++        """
++        Call method() while capturing sys.stderr output internally and
++        call self.fail() if successRe.search() does not match the stderr
++        output.  This is used to test for uncatchable exceptions.
++        """
++        stdErr = sys.stderr
++        sys.stderr = StringIO()
++        try:
++            method()
++        finally:
++            temp = sys.stderr
++            sys.stderr = stdErr
++            errorOut = temp.getvalue()
++            if not successRe.search(errorOut) :
++                self.fail("unexpected stderr output:\n"+errorOut)
++        if sys.version_info < (3, 0) :  # XXX: How to do this in Py3k ???
++            sys.exc_traceback = sys.last_traceback = None
++
++    def _test_compare_function_exception(self) :
++        self.startTest()
++        def bad_comparator(l, r) :
++            if l == r:
++                # pass the set_dup_compare test
++                return 0
++            raise RuntimeError, "i'm a naughty comparison function"
++        self.createDB(bad_comparator)
++        #print "\n*** test should print 2 uncatchable tracebacks ***"
++        self.addDataToDB(['a', 'b', 'c'])  # this should raise, but...
++        self.finishTest()
++
++    def test_compare_function_exception(self) :
++        self.verifyStderr(
++                self._test_compare_function_exception,
++                re.compile('(^RuntimeError:.* naughty.*){2}', re.M|re.S)
++        )
++
++    def _test_compare_function_bad_return(self) :
++        self.startTest()
++        def bad_comparator(l, r) :
++            if l == r:
++                # pass the set_dup_compare test
++                return 0
++            return l
++        self.createDB(bad_comparator)
+         #print "\n*** test should print 2 errors about returning an int ***"
+-        self.addDataToDB (['a', 'b', 'c'])  # this should raise, but...
+-        self.finishTest ()
++        self.addDataToDB(['a', 'b', 'c'])  # this should raise, but...
++        self.finishTest()
+ 
+-    def test_compare_function_bad_return(self):
++    def test_compare_function_bad_return(self) :
+         self.verifyStderr(
+                 self._test_compare_function_bad_return,
+                 re.compile('(^TypeError:.* return an int.*){2}', re.M|re.S)
+         )
+ 
+ 
+-    def test_cannot_assign_twice (self):
++    def test_cannot_assign_twice(self) :
+ 
+-        def my_compare (a, b):
++        def my_compare(a, b) :
+             return 0
+ 
+         self.startTest()
+         self.createDB(my_compare)
+-        self.assertRaises (RuntimeError, self.db.set_bt_compare, my_compare)
++        self.assertRaises(RuntimeError, self.db.set_dup_compare, my_compare)
+ 
+-def test_suite ():
+-    res = unittest.TestSuite ()
++def test_suite() :
++    res = unittest.TestSuite()
+ 
+-    res.addTest (unittest.makeSuite (ComparatorTests))
+-    res.addTest (unittest.makeSuite (BtreeExceptionsTestCase))
+-    res.addTest (unittest.makeSuite (BtreeKeyCompareTestCase))
++    res.addTest(unittest.makeSuite(ComparatorTests))
++    res.addTest(unittest.makeSuite(BtreeExceptionsTestCase))
++    res.addTest(unittest.makeSuite(BtreeKeyCompareTestCase))
++    res.addTest(unittest.makeSuite(DuplicateExceptionsTestCase))
++    res.addTest(unittest.makeSuite(DuplicateCompareTestCase))
+     return res
+ 
+ if __name__ == '__main__':
+-    unittest.main (defaultTest = 'suite')
++    unittest.main(defaultTest = 'suite')
+diff -urN Python-2.7.3/Lib/bsddb/test/test_dbenv.py bsddb3-5.3.0/Lib/bsddb/test/test_dbenv.py
+--- Python-2.7.3/Lib/bsddb/test/test_dbenv.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_dbenv.py	2012-01-16 19:13:03.000000000 +0100
+@@ -7,14 +7,6 @@
+ #----------------------------------------------------------------------
+ 
+ class DBEnv(unittest.TestCase):
+-    import sys
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+-        def assertFalse(self, expr, msg=None):
+-            self.failIf(expr,msg=msg)
+-
+     def setUp(self):
+         self.homeDir = get_new_environment_path()
+         self.env = db.DBEnv()
+@@ -25,12 +17,31 @@
+         test_support.rmtree(self.homeDir)
+ 
+ class DBEnv_general(DBEnv) :
++    def test_get_open_flags(self) :
++        flags = db.DB_CREATE | db.DB_INIT_MPOOL
++        self.env.open(self.homeDir, flags)
++        self.assertEqual(flags, self.env.get_open_flags())
++
++    def test_get_open_flags2(self) :
++        flags = db.DB_CREATE | db.DB_INIT_MPOOL | \
++                db.DB_INIT_LOCK | db.DB_THREAD
++        self.env.open(self.homeDir, flags)
++        self.assertEqual(flags, self.env.get_open_flags())
++
+     if db.version() >= (4, 7) :
+         def test_lk_partitions(self) :
+             for i in [10, 20, 40] :
+                 self.env.set_lk_partitions(i)
+                 self.assertEqual(i, self.env.get_lk_partitions())
+ 
++        def test_getset_intermediate_dir_mode(self) :
++            self.assertEqual(None, self.env.get_intermediate_dir_mode())
++            for mode in ["rwx------", "rw-rw-rw-", "rw-r--r--"] :
++                self.env.set_intermediate_dir_mode(mode)
++                self.assertEqual(mode, self.env.get_intermediate_dir_mode())
++            self.assertRaises(db.DBInvalidArgError,
++                    self.env.set_intermediate_dir_mode, "abcde")
++
+     if db.version() >= (4, 6) :
+         def test_thread(self) :
+             for i in [16, 100, 1000] :
+@@ -58,145 +69,146 @@
+                 self.env.set_lg_filemode(i)
+                 self.assertEqual(i, self.env.get_lg_filemode())
+ 
+-    if db.version() >= (4, 3) :
+-        def test_mp_max_openfd(self) :
+-            for i in [17, 31, 42] :
+-                self.env.set_mp_max_openfd(i)
+-                self.assertEqual(i, self.env.get_mp_max_openfd())
+-
+-        def test_mp_max_write(self) :
+-            for i in [100, 200, 300] :
+-                for j in [1, 2, 3] :
+-                    j *= 1000000
+-                    self.env.set_mp_max_write(i, j)
+-                    v=self.env.get_mp_max_write()
+-                    self.assertEqual((i, j), v)
+-
+-    if db.version() >= (4, 2) :
+-        def test_invalid_txn(self) :
+-            # This environment doesn't support transactions
+-            self.assertRaises(db.DBInvalidArgError, self.env.txn_begin)
+-
+-        def test_mp_mmapsize(self) :
+-            for i in [16, 32, 64] :
+-                i *= 1024*1024
+-                self.env.set_mp_mmapsize(i)
+-                self.assertEqual(i, self.env.get_mp_mmapsize())
+-
+-        def test_tmp_dir(self) :
+-            for i in ["a", "bb", "ccc"] :
+-                self.env.set_tmp_dir(i)
+-                self.assertEqual(i, self.env.get_tmp_dir())
+-
+-        def test_flags(self) :
+-            self.env.set_flags(db.DB_AUTO_COMMIT, 1)
+-            self.assertEqual(db.DB_AUTO_COMMIT, self.env.get_flags())
+-            self.env.set_flags(db.DB_TXN_NOSYNC, 1)
+-            self.assertEqual(db.DB_AUTO_COMMIT | db.DB_TXN_NOSYNC,
+-                    self.env.get_flags())
+-            self.env.set_flags(db.DB_AUTO_COMMIT, 0)
+-            self.assertEqual(db.DB_TXN_NOSYNC, self.env.get_flags())
+-            self.env.set_flags(db.DB_TXN_NOSYNC, 0)
+-            self.assertEqual(0, self.env.get_flags())
+-
+-        def test_lk_max_objects(self) :
+-            for i in [1000, 2000, 3000] :
+-                self.env.set_lk_max_objects(i)
+-                self.assertEqual(i, self.env.get_lk_max_objects())
+-
+-        def test_lk_max_locks(self) :
+-            for i in [1000, 2000, 3000] :
+-                self.env.set_lk_max_locks(i)
+-                self.assertEqual(i, self.env.get_lk_max_locks())
+-
+-        def test_lk_max_lockers(self) :
+-            for i in [1000, 2000, 3000] :
+-                self.env.set_lk_max_lockers(i)
+-                self.assertEqual(i, self.env.get_lk_max_lockers())
+-
+-        def test_lg_regionmax(self) :
+-            for i in [128, 256, 1024] :
+-                i = i*1024*1024
+-                self.env.set_lg_regionmax(i)
+-                j = self.env.get_lg_regionmax()
+-                self.assertTrue(i <= j)
+-                self.assertTrue(2*i > j)
+-
+-        def test_lk_detect(self) :
+-            flags= [db.DB_LOCK_DEFAULT, db.DB_LOCK_EXPIRE, db.DB_LOCK_MAXLOCKS,
+-                    db.DB_LOCK_MINLOCKS, db.DB_LOCK_MINWRITE,
+-                    db.DB_LOCK_OLDEST, db.DB_LOCK_RANDOM, db.DB_LOCK_YOUNGEST]
+-
+-            if db.version() >= (4, 3) :
+-                flags.append(db.DB_LOCK_MAXWRITE)
+-
+-            for i in flags :
+-                self.env.set_lk_detect(i)
+-                self.assertEqual(i, self.env.get_lk_detect())
+-
+-        def test_lg_dir(self) :
+-            for i in ["a", "bb", "ccc", "dddd"] :
+-                self.env.set_lg_dir(i)
+-                self.assertEqual(i, self.env.get_lg_dir())
+-
+-        def test_lg_bsize(self) :
+-            log_size = 70*1024
+-            self.env.set_lg_bsize(log_size)
+-            self.assertTrue(self.env.get_lg_bsize() >= log_size)
+-            self.assertTrue(self.env.get_lg_bsize() < 4*log_size)
+-            self.env.set_lg_bsize(4*log_size)
+-            self.assertTrue(self.env.get_lg_bsize() >= 4*log_size)
+-
+-        def test_setget_data_dirs(self) :
+-            dirs = ("a", "b", "c", "d")
+-            for i in dirs :
+-                self.env.set_data_dir(i)
+-            self.assertEqual(dirs, self.env.get_data_dirs())
+-
+-        def test_setget_cachesize(self) :
+-            cachesize = (0, 512*1024*1024, 3)
+-            self.env.set_cachesize(*cachesize)
+-            self.assertEqual(cachesize, self.env.get_cachesize())
+-
+-            cachesize = (0, 1*1024*1024, 5)
+-            self.env.set_cachesize(*cachesize)
+-            cachesize2 = self.env.get_cachesize()
+-            self.assertEqual(cachesize[0], cachesize2[0])
+-            self.assertEqual(cachesize[2], cachesize2[2])
+-            # Berkeley DB expands the cache 25% accounting overhead,
+-            # if the cache is small.
+-            self.assertEqual(125, int(100.0*cachesize2[1]/cachesize[1]))
+-
+-            # You can not change configuration after opening
+-            # the environment.
+-            self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
+-            cachesize = (0, 2*1024*1024, 1)
+-            self.assertRaises(db.DBInvalidArgError,
+-                self.env.set_cachesize, *cachesize)
+-            self.assertEqual(cachesize2, self.env.get_cachesize())
+-
+-        def test_set_cachesize_dbenv_db(self) :
+-            # You can not configure the cachesize using
+-            # the database handle, if you are using an environment.
+-            d = db.DB(self.env)
+-            self.assertRaises(db.DBInvalidArgError,
+-                d.set_cachesize, 0, 1024*1024, 1)
+-
+-        def test_setget_shm_key(self) :
+-            shm_key=137
+-            self.env.set_shm_key(shm_key)
+-            self.assertEqual(shm_key, self.env.get_shm_key())
+-            self.env.set_shm_key(shm_key+1)
+-            self.assertEqual(shm_key+1, self.env.get_shm_key())
+-
+-            # You can not change configuration after opening
+-            # the environment.
+-            self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
+-            # If we try to reconfigure cache after opening the
+-            # environment, core dump.
+-            self.assertRaises(db.DBInvalidArgError,
+-                self.env.set_shm_key, shm_key)
+-            self.assertEqual(shm_key+1, self.env.get_shm_key())
++    def test_mp_max_openfd(self) :
++        for i in [17, 31, 42] :
++            self.env.set_mp_max_openfd(i)
++            self.assertEqual(i, self.env.get_mp_max_openfd())
++
++    def test_mp_max_write(self) :
++        for i in [100, 200, 300] :
++            for j in [1, 2, 3] :
++                j *= 1000000
++                self.env.set_mp_max_write(i, j)
++                v=self.env.get_mp_max_write()
++                self.assertEqual((i, j), v)
++
++    def test_invalid_txn(self) :
++        # This environment doesn't support transactions
++        self.assertRaises(db.DBInvalidArgError, self.env.txn_begin)
++
++    def test_mp_mmapsize(self) :
++        for i in [16, 32, 64] :
++            i *= 1024*1024
++            self.env.set_mp_mmapsize(i)
++            self.assertEqual(i, self.env.get_mp_mmapsize())
++
++    def test_tmp_dir(self) :
++        for i in ["a", "bb", "ccc"] :
++            self.env.set_tmp_dir(i)
++            self.assertEqual(i, self.env.get_tmp_dir())
++
++    def test_flags(self) :
++        self.env.set_flags(db.DB_AUTO_COMMIT, 1)
++        self.assertEqual(db.DB_AUTO_COMMIT, self.env.get_flags())
++        self.env.set_flags(db.DB_TXN_NOSYNC, 1)
++        self.assertEqual(db.DB_AUTO_COMMIT | db.DB_TXN_NOSYNC,
++                self.env.get_flags())
++        self.env.set_flags(db.DB_AUTO_COMMIT, 0)
++        self.assertEqual(db.DB_TXN_NOSYNC, self.env.get_flags())
++        self.env.set_flags(db.DB_TXN_NOSYNC, 0)
++        self.assertEqual(0, self.env.get_flags())
++
++    def test_lk_max_objects(self) :
++        for i in [1000, 2000, 3000] :
++            self.env.set_lk_max_objects(i)
++            self.assertEqual(i, self.env.get_lk_max_objects())
++
++    def test_lk_max_locks(self) :
++        for i in [1000, 2000, 3000] :
++            self.env.set_lk_max_locks(i)
++            self.assertEqual(i, self.env.get_lk_max_locks())
++
++    def test_lk_max_lockers(self) :
++        for i in [1000, 2000, 3000] :
++            self.env.set_lk_max_lockers(i)
++            self.assertEqual(i, self.env.get_lk_max_lockers())
++
++    def test_lg_regionmax(self) :
++        for i in [128, 256, 1000] :
++            i = i*1024*1024
++            self.env.set_lg_regionmax(i)
++            j = self.env.get_lg_regionmax()
++            self.assertTrue(i <= j)
++            self.assertTrue(2*i > j)
++
++    def test_lk_detect(self) :
++        flags= [db.DB_LOCK_DEFAULT, db.DB_LOCK_EXPIRE, db.DB_LOCK_MAXLOCKS,
++                db.DB_LOCK_MINLOCKS, db.DB_LOCK_MINWRITE,
++                db.DB_LOCK_OLDEST, db.DB_LOCK_RANDOM, db.DB_LOCK_YOUNGEST]
++
++        flags.append(db.DB_LOCK_MAXWRITE)
++
++        for i in flags :
++            self.env.set_lk_detect(i)
++            self.assertEqual(i, self.env.get_lk_detect())
++
++    def test_lg_dir(self) :
++        for i in ["a", "bb", "ccc", "dddd"] :
++            self.env.set_lg_dir(i)
++            self.assertEqual(i, self.env.get_lg_dir())
++
++    def test_lg_bsize(self) :
++        log_size = 70*1024
++        self.env.set_lg_bsize(log_size)
++        self.assertTrue(self.env.get_lg_bsize() >= log_size)
++        self.assertTrue(self.env.get_lg_bsize() < 4*log_size)
++        self.env.set_lg_bsize(4*log_size)
++        self.assertTrue(self.env.get_lg_bsize() >= 4*log_size)
++
++    def test_setget_data_dirs(self) :
++        dirs = ("a", "b", "c", "d")
++        for i in dirs :
++            self.env.set_data_dir(i)
++        self.assertEqual(dirs, self.env.get_data_dirs())
++
++    def test_setget_cachesize(self) :
++        cachesize = (0, 512*1024*1024, 3)
++        self.env.set_cachesize(*cachesize)
++        self.assertEqual(cachesize, self.env.get_cachesize())
++
++        cachesize = (0, 1*1024*1024, 5)
++        self.env.set_cachesize(*cachesize)
++        cachesize2 = self.env.get_cachesize()
++        self.assertEqual(cachesize[0], cachesize2[0])
++        self.assertEqual(cachesize[2], cachesize2[2])
++        # Berkeley DB expands the cache 25% accounting overhead,
++        # if the cache is small.
++        self.assertEqual(125, int(100.0*cachesize2[1]/cachesize[1]))
++
++        # You can not change configuration after opening
++        # the environment.
++        self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
++        cachesize = (0, 2*1024*1024, 1)
++        self.assertRaises(db.DBInvalidArgError,
++            self.env.set_cachesize, *cachesize)
++        cachesize3 = self.env.get_cachesize()
++        self.assertEqual(cachesize2[0], cachesize3[0])
++        self.assertEqual(cachesize2[2], cachesize3[2])
++        # In Berkeley DB 5.1, the cachesize can change when opening the Env
++        self.assertTrue(cachesize2[1] <= cachesize3[1])
++
++    def test_set_cachesize_dbenv_db(self) :
++        # You can not configure the cachesize using
++        # the database handle, if you are using an environment.
++        d = db.DB(self.env)
++        self.assertRaises(db.DBInvalidArgError,
++            d.set_cachesize, 0, 1024*1024, 1)
++
++    def test_setget_shm_key(self) :
++        shm_key=137
++        self.env.set_shm_key(shm_key)
++        self.assertEqual(shm_key, self.env.get_shm_key())
++        self.env.set_shm_key(shm_key+1)
++        self.assertEqual(shm_key+1, self.env.get_shm_key())
++
++        # You can not change configuration after opening
++        # the environment.
++        self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
++        # If we try to reconfigure cache after opening the
++        # environment, core dump.
++        self.assertRaises(db.DBInvalidArgError,
++            self.env.set_shm_key, shm_key)
++        self.assertEqual(shm_key+1, self.env.get_shm_key())
+ 
+     if db.version() >= (4, 4) :
+         def test_mutex_setget_max(self) :
+@@ -305,7 +317,7 @@
+         self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL |
+                 db.DB_INIT_LOG | db.DB_INIT_TXN)
+ 
+-    if db.version() >= (4, 5) :
++    if (db.version() >= (4, 5)) and (db.version() < (5, 2)) :
+         def test_tx_max(self) :
+             txns=[]
+             def tx() :
+diff -urN Python-2.7.3/Lib/bsddb/test/test_db.py bsddb3-5.3.0/Lib/bsddb/test/test_db.py
+--- Python-2.7.3/Lib/bsddb/test/test_db.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_db.py	2012-01-16 19:08:07.000000000 +0100
+@@ -7,11 +7,6 @@
+ #----------------------------------------------------------------------
+ 
+ class DB(unittest.TestCase):
+-    import sys
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+     def setUp(self):
+         self.path = get_new_database_path()
+         self.db = db.DB()
+@@ -19,21 +14,39 @@
+     def tearDown(self):
+         self.db.close()
+         del self.db
+-        test_support.rmtree(self.path)
++        test_support.unlink(self.path)
+ 
+ class DB_general(DB) :
+-    if db.version() >= (4, 2) :
+-        def test_bt_minkey(self) :
+-            for i in [17, 108, 1030] :
+-                self.db.set_bt_minkey(i)
+-                self.assertEqual(i, self.db.get_bt_minkey())
+-
+-        def test_lorder(self) :
+-            self.db.set_lorder(1234)
+-            self.assertEqual(1234, self.db.get_lorder())
+-            self.db.set_lorder(4321)
+-            self.assertEqual(4321, self.db.get_lorder())
+-            self.assertRaises(db.DBInvalidArgError, self.db.set_lorder, 9182)
++    def test_get_open_flags(self) :
++        self.db.open(self.path, dbtype=db.DB_HASH, flags = db.DB_CREATE)
++        self.assertEqual(db.DB_CREATE, self.db.get_open_flags())
++
++    def test_get_open_flags2(self) :
++        self.db.open(self.path, dbtype=db.DB_HASH, flags = db.DB_CREATE |
++                db.DB_THREAD)
++        self.assertEqual(db.DB_CREATE | db.DB_THREAD, self.db.get_open_flags())
++
++    def test_get_dbname_filename(self) :
++        self.db.open(self.path, dbtype=db.DB_HASH, flags = db.DB_CREATE)
++        self.assertEqual((self.path, None), self.db.get_dbname())
++
++    def test_get_dbname_filename_database(self) :
++        name = "jcea-random-name"
++        self.db.open(self.path, dbname=name, dbtype=db.DB_HASH,
++                flags = db.DB_CREATE)
++        self.assertEqual((self.path, name), self.db.get_dbname())
++
++    def test_bt_minkey(self) :
++        for i in [17, 108, 1030] :
++            self.db.set_bt_minkey(i)
++            self.assertEqual(i, self.db.get_bt_minkey())
++
++    def test_lorder(self) :
++        self.db.set_lorder(1234)
++        self.assertEqual(1234, self.db.get_lorder())
++        self.db.set_lorder(4321)
++        self.assertEqual(4321, self.db.get_lorder())
++        self.assertRaises(db.DBInvalidArgError, self.db.set_lorder, 9182)
+ 
+     if db.version() >= (4, 6) :
+         def test_priority(self) :
+@@ -44,30 +57,34 @@
+                 self.db.set_priority(flag)
+                 self.assertEqual(flag, self.db.get_priority())
+ 
++    def test_get_transactional(self) :
++        self.assertFalse(self.db.get_transactional())
++        self.db.open(self.path, dbtype=db.DB_HASH, flags = db.DB_CREATE)
++        self.assertFalse(self.db.get_transactional())
++
+ class DB_hash(DB) :
+-    if db.version() >= (4, 2) :
+-        def test_h_ffactor(self) :
+-            for ffactor in [4, 16, 256] :
+-                self.db.set_h_ffactor(ffactor)
+-                self.assertEqual(ffactor, self.db.get_h_ffactor())
+-
+-        def test_h_nelem(self) :
+-            for nelem in [1, 2, 4] :
+-                nelem = nelem*1024*1024  # Millions
+-                self.db.set_h_nelem(nelem)
+-                self.assertEqual(nelem, self.db.get_h_nelem())
+-
+-        def test_pagesize(self) :
+-            for i in xrange(9, 17) :  # From 512 to 65536
+-                i = 1<<i
+-                self.db.set_pagesize(i)
+-                self.assertEqual(i, self.db.get_pagesize())
+-
+-            # The valid values goes from 512 to 65536
+-            # Test 131072 bytes...
+-            self.assertRaises(db.DBInvalidArgError, self.db.set_pagesize, 1<<17)
+-            # Test 256 bytes...
+-            self.assertRaises(db.DBInvalidArgError, self.db.set_pagesize, 1<<8)
++    def test_h_ffactor(self) :
++        for ffactor in [4, 16, 256] :
++            self.db.set_h_ffactor(ffactor)
++            self.assertEqual(ffactor, self.db.get_h_ffactor())
++
++    def test_h_nelem(self) :
++        for nelem in [1, 2, 4] :
++            nelem = nelem*1024*1024  # Millions
++            self.db.set_h_nelem(nelem)
++            self.assertEqual(nelem, self.db.get_h_nelem())
++
++    def test_pagesize(self) :
++        for i in xrange(9, 17) :  # From 512 to 65536
++            i = 1<<i
++            self.db.set_pagesize(i)
++            self.assertEqual(i, self.db.get_pagesize())
++
++        # The valid values goes from 512 to 65536
++        # Test 131072 bytes...
++        self.assertRaises(db.DBInvalidArgError, self.db.set_pagesize, 1<<17)
++        # Test 256 bytes...
++        self.assertRaises(db.DBInvalidArgError, self.db.set_pagesize, 1<<8)
+ 
+ class DB_txn(DB) :
+     def setUp(self) :
+@@ -84,39 +101,43 @@
+         del self.env
+         test_support.rmtree(self.homeDir)
+ 
+-    if db.version() >= (4, 2) :
+-        def test_flags(self) :
+-            self.db.set_flags(db.DB_CHKSUM)
+-            self.assertEqual(db.DB_CHKSUM, self.db.get_flags())
+-            self.db.set_flags(db.DB_TXN_NOT_DURABLE)
+-            self.assertEqual(db.DB_TXN_NOT_DURABLE | db.DB_CHKSUM,
+-                    self.db.get_flags())
++    def test_flags(self) :
++        self.db.set_flags(db.DB_CHKSUM)
++        self.assertEqual(db.DB_CHKSUM, self.db.get_flags())
++        self.db.set_flags(db.DB_TXN_NOT_DURABLE)
++        self.assertEqual(db.DB_TXN_NOT_DURABLE | db.DB_CHKSUM,
++                self.db.get_flags())
++
++    def test_get_transactional(self) :
++        self.assertFalse(self.db.get_transactional())
++        # DB_AUTO_COMMIT = Implicit transaction
++        self.db.open("XXX", dbtype=db.DB_HASH,
++                flags = db.DB_CREATE | db.DB_AUTO_COMMIT)
++        self.assertTrue(self.db.get_transactional())
+ 
+ class DB_recno(DB) :
+-    if db.version() >= (4, 2) :
+-        def test_re_pad(self) :
+-            for i in [' ', '*'] :  # Check chars
+-                self.db.set_re_pad(i)
+-                self.assertEqual(ord(i), self.db.get_re_pad())
+-            for i in [97, 65] :  # Check integers
+-                self.db.set_re_pad(i)
+-                self.assertEqual(i, self.db.get_re_pad())
+-
+-        def test_re_delim(self) :
+-            for i in [' ', '*'] :  # Check chars
+-                self.db.set_re_delim(i)
+-                self.assertEqual(ord(i), self.db.get_re_delim())
+-            for i in [97, 65] :  # Check integers
+-                self.db.set_re_delim(i)
+-                self.assertEqual(i, self.db.get_re_delim())
+-
+-        def test_re_source(self) :
+-            for i in ["test", "test2", "test3"] :
+-                self.db.set_re_source(i)
+-                self.assertEqual(i, self.db.get_re_source())
++    def test_re_pad(self) :
++        for i in [' ', '*'] :  # Check chars
++            self.db.set_re_pad(i)
++            self.assertEqual(ord(i), self.db.get_re_pad())
++        for i in [97, 65] :  # Check integers
++            self.db.set_re_pad(i)
++            self.assertEqual(i, self.db.get_re_pad())
++
++    def test_re_delim(self) :
++        for i in [' ', '*'] :  # Check chars
++            self.db.set_re_delim(i)
++            self.assertEqual(ord(i), self.db.get_re_delim())
++        for i in [97, 65] :  # Check integers
++            self.db.set_re_delim(i)
++            self.assertEqual(i, self.db.get_re_delim())
++
++    def test_re_source(self) :
++        for i in ["test", "test2", "test3"] :
++            self.db.set_re_source(i)
++            self.assertEqual(i, self.db.get_re_source())
+ 
+ class DB_queue(DB) :
+-    if db.version() >= (4, 2) :
+         def test_re_len(self) :
+             for i in [33, 65, 300, 2000] :
+                 self.db.set_re_len(i)
+diff -urN Python-2.7.3/Lib/bsddb/test/test_dbshelve.py bsddb3-5.3.0/Lib/bsddb/test/test_dbshelve.py
+--- Python-2.7.3/Lib/bsddb/test/test_dbshelve.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_dbshelve.py	2012-01-16 19:08:26.000000000 +0100
+@@ -12,9 +12,6 @@
+ 
+ 
+ 
+-if sys.version_info < (2, 4) :
+-    from sets import Set as set
+-
+ 
+ 
+ #----------------------------------------------------------------------
+@@ -33,10 +30,6 @@
+ 
+ 
+ class DBShelveTestCase(unittest.TestCase):
+-    if sys.version_info < (2, 4):
+-        def assertTrue(self, expr, msg=None):
+-            return self.failUnless(expr,msg=msg)
+-
+     if (sys.version_info < (2, 7)) or ((sys.version_info >= (3, 0)) and
+             (sys.version_info < (3, 2))) :
+         def assertIn(self, a, b, msg=None) :
+diff -urN Python-2.7.3/Lib/bsddb/test/test_dbtables.py bsddb3-5.3.0/Lib/bsddb/test/test_dbtables.py
+--- Python-2.7.3/Lib/bsddb/test/test_dbtables.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_dbtables.py	2012-01-16 19:18:15.000000000 +0100
+@@ -18,7 +18,7 @@
+ #
+ #   --  Gregory P. Smith <greg at krypto.org>
+ #
+-# $Id$
++# $Id: test_dbtables.py,v 53e5f052c511 2012/01/16 18:18:15 jcea $
+ 
+ import os, re, sys
+ 
+diff -urN Python-2.7.3/Lib/bsddb/test/test_distributed_transactions.py bsddb3-5.3.0/Lib/bsddb/test/test_distributed_transactions.py
+--- Python-2.7.3/Lib/bsddb/test/test_distributed_transactions.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_distributed_transactions.py	2012-01-16 19:05:54.000000000 +0100
+@@ -7,13 +7,6 @@
+ from test_all import db, test_support, get_new_environment_path, \
+         get_new_database_path
+ 
+-try :
+-    a=set()
+-except : # Python 2.3
+-    from sets import Set as set
+-else :
+-    del a
+-
+ from test_all import verbose
+ 
+ #----------------------------------------------------------------------
+@@ -37,15 +30,11 @@
+         self.db = db.DB(self.dbenv)
+         self.db.set_re_len(db.DB_GID_SIZE)
+         if must_open_db :
+-            if db.version() >= (4,2) :
+-                txn=self.dbenv.txn_begin()
+-                self.db.open(self.filename,
+-                        db.DB_QUEUE, db.DB_CREATE | db.DB_THREAD, 0666,
+-                        txn=txn)
+-                txn.commit()
+-            else :
+-                self.db.open(self.filename,
+-                        db.DB_QUEUE, db.DB_CREATE | db.DB_THREAD, 0666)
++            txn=self.dbenv.txn_begin()
++            self.db.open(self.filename,
++                    db.DB_QUEUE, db.DB_CREATE | db.DB_THREAD, 0666,
++                    txn=txn)
++            txn.commit()
+ 
+     def setUp(self) :
+         self.homeDir = get_new_environment_path()
+diff -urN Python-2.7.3/Lib/bsddb/test/test_early_close.py bsddb3-5.3.0/Lib/bsddb/test/test_early_close.py
+--- Python-2.7.3/Lib/bsddb/test/test_early_close.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_early_close.py	2012-01-16 18:57:43.000000000 +0100
+@@ -174,7 +174,7 @@
+             txn.commit()
+             warnings.resetwarnings()
+         else :
+-            # When we drop support for python 2.3 and 2.4
++            # When we drop support for python 2.4
+             # we could use: (in 2.5 we need a __future__ statement)
+             #
+             #    with warnings.catch_warnings():
+@@ -182,7 +182,7 @@
+             #        txn.commit()
+             #
+             # We can not use "with" as is, because it would be invalid syntax
+-            # in python 2.3, 2.4 and (with no __future__) 2.5.
++            # in python 2.4 and (with no __future__) 2.5.
+             # Here we simulate "with" following PEP 343 :
+             w = warnings.catch_warnings()
+             w.__enter__()
+@@ -194,15 +194,14 @@
+ 
+         self.assertRaises(db.DBCursorClosedError, c2.first)
+ 
+-    if db.version() > (4,3,0) :
+-        def test07_close_db_before_sequence(self):
+-            import os.path
+-            path=os.path.join(self.homeDir,self.filename)
+-            d = db.DB()
+-            d.open(path, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)
+-            dbs=db.DBSequence(d)
+-            d.close()  # This "close" should close the child DBSequence also
+-            dbs.close()  # If not closed, core dump (in Berkeley DB 4.6.*)
++    def test07_close_db_before_sequence(self):
++        import os.path
++        path=os.path.join(self.homeDir,self.filename)
++        d = db.DB()
++        d.open(path, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)
++        dbs=db.DBSequence(d)
++        d.close()  # This "close" should close the child DBSequence also
++        dbs.close()  # If not closed, core dump (in Berkeley DB 4.6.*)
+ 
+ #----------------------------------------------------------------------
+ 
+diff -urN Python-2.7.3/Lib/bsddb/test/test_lock.py bsddb3-5.3.0/Lib/bsddb/test/test_lock.py
+--- Python-2.7.3/Lib/bsddb/test/test_lock.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_lock.py	2012-01-16 20:12:51.000000000 +0100
+@@ -19,12 +19,6 @@
+ #----------------------------------------------------------------------
+ 
+ class LockingTestCase(unittest.TestCase):
+-    import sys
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+-
+     def setUp(self):
+         self.homeDir = get_new_environment_path()
+         self.env = db.DBEnv()
+@@ -89,16 +83,15 @@
+         for t in threads:
+             t.join()
+ 
+-    if db.version() >= (4, 2) :
+-        def test03_lock_timeout(self):
+-            self.env.set_timeout(0, db.DB_SET_LOCK_TIMEOUT)
+-            self.assertEqual(self.env.get_timeout(db.DB_SET_LOCK_TIMEOUT), 0)
+-            self.env.set_timeout(0, db.DB_SET_TXN_TIMEOUT)
+-            self.assertEqual(self.env.get_timeout(db.DB_SET_TXN_TIMEOUT), 0)
+-            self.env.set_timeout(123456, db.DB_SET_LOCK_TIMEOUT)
+-            self.assertEqual(self.env.get_timeout(db.DB_SET_LOCK_TIMEOUT), 123456)
+-            self.env.set_timeout(7890123, db.DB_SET_TXN_TIMEOUT)
+-            self.assertEqual(self.env.get_timeout(db.DB_SET_TXN_TIMEOUT), 7890123)
++    def test03_lock_timeout(self):
++        self.env.set_timeout(0, db.DB_SET_LOCK_TIMEOUT)
++        self.assertEqual(self.env.get_timeout(db.DB_SET_LOCK_TIMEOUT), 0)
++        self.env.set_timeout(0, db.DB_SET_TXN_TIMEOUT)
++        self.assertEqual(self.env.get_timeout(db.DB_SET_TXN_TIMEOUT), 0)
++        self.env.set_timeout(123456, db.DB_SET_LOCK_TIMEOUT)
++        self.assertEqual(self.env.get_timeout(db.DB_SET_LOCK_TIMEOUT), 123456)
++        self.env.set_timeout(7890123, db.DB_SET_TXN_TIMEOUT)
++        self.assertEqual(self.env.get_timeout(db.DB_SET_TXN_TIMEOUT), 7890123)
+ 
+     def test04_lock_timeout2(self):
+         self.env.set_timeout(0, db.DB_SET_LOCK_TIMEOUT)
+diff -urN Python-2.7.3/Lib/bsddb/test/test_misc.py bsddb3-5.3.0/Lib/bsddb/test/test_misc.py
+--- Python-2.7.3/Lib/bsddb/test/test_misc.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_misc.py	2012-01-16 19:06:38.000000000 +0100
+@@ -9,13 +9,6 @@
+ #----------------------------------------------------------------------
+ 
+ class MiscTestCase(unittest.TestCase):
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr, msg=msg)
+-
+-        def assertFalse(self, expr, msg=None):
+-            self.failIf(expr, msg=msg)
+-
+     def setUp(self):
+         self.filename = get_new_database_path()
+         self.homeDir = get_new_environment_path()
+@@ -97,10 +90,6 @@
+             test_support.unlink(self.filename)
+ 
+     def test07_DB_set_flags_persists(self):
+-        if db.version() < (4,2):
+-            # The get_flags API required for this to work is only available
+-            # in Berkeley DB >= 4.2
+-            return
+         try:
+             db1 = db.DB()
+             db1.set_flags(db.DB_DUPSORT)
+diff -urN Python-2.7.3/Lib/bsddb/test/test_queue.py bsddb3-5.3.0/Lib/bsddb/test/test_queue.py
+--- Python-2.7.3/Lib/bsddb/test/test_queue.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_queue.py	2012-01-16 04:38:42.000000000 +0100
+@@ -99,11 +99,6 @@
+             print '\n', '-=' * 30
+             print "Running %s.test02_basicPost32..." % self.__class__.__name__
+ 
+-        if db.version() < (3, 2, 0):
+-            if verbose:
+-                print "Test not run, DB not new enough..."
+-            return
+-
+         d = db.DB()
+         d.set_re_len(40)  # Queues must be fixed length
+         d.open(self.filename, db.DB_QUEUE, db.DB_CREATE)
+diff -urN Python-2.7.3/Lib/bsddb/test/test_recno.py bsddb3-5.3.0/Lib/bsddb/test/test_recno.py
+--- Python-2.7.3/Lib/bsddb/test/test_recno.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_recno.py	2012-01-16 19:06:46.000000000 +0100
+@@ -14,12 +14,6 @@
+ #----------------------------------------------------------------------
+ 
+ class SimpleRecnoTestCase(unittest.TestCase):
+-    if sys.version_info < (2, 4) :
+-        def assertFalse(self, expr, msg=None) :
+-            return self.failIf(expr,msg=msg)
+-        def assertTrue(self, expr, msg=None) :
+-            return self.assertTrue(expr, msg=msg)
+-
+     if (sys.version_info < (2, 7)) or ((sys.version_info >= (3, 0)) and
+             (sys.version_info < (3, 2))) :
+         def assertIsInstance(self, obj, datatype, msg=None) :
+@@ -236,7 +230,9 @@
+         d.close()
+ 
+         # get the text from the backing source
+-        text = open(source, 'r').read()
++        f = open(source, 'r')
++        text = f.read()
++        f.close()
+         text = text.strip()
+         if verbose:
+             print text
+@@ -256,7 +252,9 @@
+         d.sync()
+         d.close()
+ 
+-        text = open(source, 'r').read()
++        f = open(source, 'r')
++        text = f.read()
++        f.close()
+         text = text.strip()
+         if verbose:
+             print text
+@@ -298,6 +296,18 @@
+         c.close()
+         d.close()
+ 
++    def test04_get_size_empty(self) :
++        d = db.DB()
++        d.open(self.filename, dbtype=db.DB_RECNO, flags=db.DB_CREATE)
++
++        row_id = d.append(' ')
++        self.assertEqual(1, d.get_size(key=row_id))
++        row_id = d.append('')
++        self.assertEqual(0, d.get_size(key=row_id))
++
++
++
++
+ 
+ #----------------------------------------------------------------------
+ 
+diff -urN Python-2.7.3/Lib/bsddb/test/test_replication.py bsddb3-5.3.0/Lib/bsddb/test/test_replication.py
+--- Python-2.7.3/Lib/bsddb/test/test_replication.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_replication.py	2012-01-16 19:07:00.000000000 +0100
+@@ -12,11 +12,6 @@
+ #----------------------------------------------------------------------
+ 
+ class DBReplication(unittest.TestCase) :
+-    import sys
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+     def setUp(self) :
+         self.homeDirMaster = get_new_environment_path()
+         self.homeDirClient = get_new_environment_path()
+@@ -76,13 +71,57 @@
+ class DBReplicationManager(DBReplication) :
+     def test01_basic_replication(self) :
+         master_port = test_support.find_unused_port()
+-        self.dbenvMaster.repmgr_set_local_site("127.0.0.1", master_port)
+         client_port = test_support.find_unused_port()
+-        self.dbenvClient.repmgr_set_local_site("127.0.0.1", client_port)
+-        self.dbenvMaster.repmgr_add_remote_site("127.0.0.1", client_port)
+-        self.dbenvClient.repmgr_add_remote_site("127.0.0.1", master_port)
+-        self.dbenvMaster.rep_set_nsites(2)
+-        self.dbenvClient.rep_set_nsites(2)
++        if db.version() >= (5, 2) :
++            self.site = self.dbenvMaster.repmgr_site("127.0.0.1", master_port)
++            self.site.set_config(db.DB_GROUP_CREATOR, True)
++            self.site.set_config(db.DB_LOCAL_SITE, True)
++            self.site2 = self.dbenvMaster.repmgr_site("127.0.0.1", client_port)
++
++            self.site3 = self.dbenvClient.repmgr_site("127.0.0.1", master_port)
++            self.site3.set_config(db.DB_BOOTSTRAP_HELPER, True)
++            self.site4 = self.dbenvClient.repmgr_site("127.0.0.1", client_port)
++            self.site4.set_config(db.DB_LOCAL_SITE, True)
++
++            d = {
++                    db.DB_BOOTSTRAP_HELPER: [False, False, True, False],
++                    db.DB_GROUP_CREATOR: [True, False, False, False],
++                    db.DB_LEGACY: [False, False, False, False],
++                    db.DB_LOCAL_SITE: [True, False, False, True],
++                    db.DB_REPMGR_PEER: [False, False, False, False ],
++                }
++
++            for i, j in d.items() :
++                for k, v in \
++                        zip([self.site, self.site2, self.site3, self.site4], j) :
++                    if v :
++                        self.assertTrue(k.get_config(i))
++                    else :
++                        self.assertFalse(k.get_config(i))
++
++            self.assertNotEqual(self.site.get_eid(), self.site2.get_eid())
++            self.assertNotEqual(self.site3.get_eid(), self.site4.get_eid())
++
++            for i, j in zip([self.site, self.site2, self.site3, self.site4], \
++                    [master_port, client_port, master_port, client_port]) :
++                addr = i.get_address()
++                self.assertEqual(addr, ("127.0.0.1", j))
++
++            for i in [self.site, self.site2] :
++                self.assertEqual(i.get_address(),
++                        self.dbenvMaster.repmgr_site_by_eid(i.get_eid()).get_address())
++            for i in [self.site3, self.site4] :
++                self.assertEqual(i.get_address(),
++                        self.dbenvClient.repmgr_site_by_eid(i.get_eid()).get_address())
++        else :
++            self.dbenvMaster.repmgr_set_local_site("127.0.0.1", master_port)
++            self.dbenvClient.repmgr_set_local_site("127.0.0.1", client_port)
++            self.dbenvMaster.repmgr_add_remote_site("127.0.0.1", client_port)
++            self.dbenvClient.repmgr_add_remote_site("127.0.0.1", master_port)
++
++            self.dbenvMaster.rep_set_nsites(2)
++            self.dbenvClient.rep_set_nsites(2)
++
+         self.dbenvMaster.rep_set_priority(10)
+         self.dbenvClient.rep_set_priority(0)
+ 
+@@ -126,35 +165,26 @@
+         # is not generated if the master has no new transactions.
+         # This is solved in BDB 4.6 (#15542).
+         import time
+-        timeout = time.time()+60
++        timeout = time.time()+10
+         while (time.time()<timeout) and not (self.confirmed_master and self.client_startupdone) :
+             time.sleep(0.02)
+-        # self.client_startupdone does not always get set to True within
+-        # the timeout.  On windows this may be a deep issue, on other
+-        # platforms it is likely just a timing issue, especially on slow
+-        # virthost buildbots (see issue 3892 for more).  Even though
+-        # the timeout triggers, the rest of this test method usually passes
+-        # (but not all of it always, see below).  So we just note the
+-        # timeout on stderr and keep soldering on.
+-        if time.time()>timeout:
+-            import sys
+-            print >> sys.stderr, ("XXX: timeout happened before"
+-                "startup was confirmed - see issue 3892")
+-            startup_timeout = True
++        self.assertTrue(time.time()<timeout)
+ 
+         d = self.dbenvMaster.repmgr_site_list()
+         self.assertEqual(len(d), 1)
+-        self.assertEqual(d[0][0], "127.0.0.1")
+-        self.assertEqual(d[0][1], client_port)
+-        self.assertTrue((d[0][2]==db.DB_REPMGR_CONNECTED) or \
+-                (d[0][2]==db.DB_REPMGR_DISCONNECTED))
++        d = d.values()[0]  # There is only one
++        self.assertEqual(d[0], "127.0.0.1")
++        self.assertEqual(d[1], client_port)
++        self.assertTrue((d[2]==db.DB_REPMGR_CONNECTED) or \
++                (d[2]==db.DB_REPMGR_DISCONNECTED))
+ 
+         d = self.dbenvClient.repmgr_site_list()
+         self.assertEqual(len(d), 1)
+-        self.assertEqual(d[0][0], "127.0.0.1")
+-        self.assertEqual(d[0][1], master_port)
+-        self.assertTrue((d[0][2]==db.DB_REPMGR_CONNECTED) or \
+-                (d[0][2]==db.DB_REPMGR_DISCONNECTED))
++        d = d.values()[0]  # There is only one
++        self.assertEqual(d[0], "127.0.0.1")
++        self.assertEqual(d[1], master_port)
++        self.assertTrue((d[2]==db.DB_REPMGR_CONNECTED) or \
++                (d[2]==db.DB_REPMGR_DISCONNECTED))
+ 
+         if db.version() >= (4,6) :
+             d = self.dbenvMaster.repmgr_stat(flags=db.DB_STAT_CLEAR);
+@@ -198,14 +228,6 @@
+             txn.commit()
+             if v is None :
+                 time.sleep(0.02)
+-        # If startup did not happen before the timeout above, then this test
+-        # sometimes fails.  This happens randomly, which causes buildbot
+-        # instability, but all the other bsddb tests pass.  Since bsddb3 in the
+-        # stdlib is currently not getting active maintenance, and is gone in
+-        # py3k, we just skip the end of the test in that case.
+-        if time.time()>=timeout and startup_timeout:
+-            self.skipTest("replication test skipped due to random failure, "
+-                "see issue 3892")
+         self.assertTrue(time.time()<timeout)
+         self.assertEqual("123", v)
+ 
+@@ -336,7 +358,7 @@
+         # is not generated if the master has no new transactions.
+         # This is solved in BDB 4.6 (#15542).
+         import time
+-        timeout = time.time()+60
++        timeout = time.time()+10
+         while (time.time()<timeout) and not (self.confirmed_master and
+                 self.client_startupdone) :
+             time.sleep(0.02)
+@@ -461,6 +483,13 @@
+ 
+             self.assertTrue(self.confirmed_master)
+ 
++            # Race condition showed up after upgrading to Solaris 10 Update 10
++            # https://forums.oracle.com/forums/thread.jspa?messageID=9902860
++            # jcea at jcea.es: See private email from Paula Bingham (Oracle),
++            # in 20110929.
++            while not (self.dbenvClient.rep_stat()["startup_complete"]) :
++                pass
++
+     if db.version() >= (4,7) :
+         def test04_test_clockskew(self) :
+             fast, slow = 1234, 1230
+diff -urN Python-2.7.3/Lib/bsddb/test/test_sequence.py bsddb3-5.3.0/Lib/bsddb/test/test_sequence.py
+--- Python-2.7.3/Lib/bsddb/test/test_sequence.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_sequence.py	2012-01-16 19:07:09.000000000 +0100
+@@ -5,11 +5,6 @@
+ 
+ 
+ class DBSequenceTest(unittest.TestCase):
+-    import sys
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+     def setUp(self):
+         self.int_32_max = 0x100000000
+         self.homeDir = get_new_environment_path()
+@@ -133,8 +128,7 @@
+ 
+ def test_suite():
+     suite = unittest.TestSuite()
+-    if db.version() >= (4,3):
+-        suite.addTest(unittest.makeSuite(DBSequenceTest))
++    suite.addTest(unittest.makeSuite(DBSequenceTest))
+     return suite
+ 
+ 
+diff -urN Python-2.7.3/Lib/bsddb/test/test_thread.py bsddb3-5.3.0/Lib/bsddb/test/test_thread.py
+--- Python-2.7.3/Lib/bsddb/test/test_thread.py	2012-04-10 01:07:29.000000000 +0200
++++ bsddb3-5.3.0/Lib/bsddb/test/test_thread.py	2012-01-16 19:07:20.000000000 +0100
+@@ -35,10 +35,6 @@
+     dbsetflags   = 0
+     envflags     = 0
+ 
+-    if sys.version_info < (2, 4) :
+-        def assertTrue(self, expr, msg=None):
+-            self.failUnless(expr,msg=msg)
+-
+     def setUp(self):
+         if verbose:
+             dbutils._deadlock_VerboseFile = sys.stdout
+diff -urN Python-2.7.3/Lib/bsddb/test_support.py bsddb3-5.3.0/Lib/bsddb/test_support.py
+--- Python-2.7.3/Lib/bsddb/test_support.py	1970-01-01 01:00:00.000000000 +0100
++++ bsddb3-5.3.0/Lib/bsddb/test_support.py	2012-01-16 04:38:42.000000000 +0100
+@@ -0,0 +1,54 @@
++# This module is a bridge.
++#
++# Code is copied from Python 2.6 (trunk) Lib/test/test_support.py that
++# the bsddb test suite needs even when run standalone on a python
++# version that may not have all of these.
++
++# DO NOT ADD NEW UNIQUE CODE.  Copy code from the python trunk
++# trunk test_support module into here.  If you need a place for your
++# own stuff specific to bsddb tests, make a bsddb.test.foo module.
++
++import errno
++import os
++import shutil
++import socket
++
++def unlink(filename):
++    try:
++        os.unlink(filename)
++    except OSError:
++        pass
++
++def rmtree(path):
++    try:
++        shutil.rmtree(path)
++    except OSError, e:
++        # Unix returns ENOENT, Windows returns ESRCH.
++        if e.errno not in (errno.ENOENT, errno.ESRCH):
++            raise
++
++def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM):
++    tempsock = socket.socket(family, socktype)
++    port = bind_port(tempsock, family=family, socktype=socktype)
++    tempsock.close()
++    del tempsock
++    return port
++
++HOST = 'localhost'
++def bind_port(sock, family, socktype, host=HOST):
++    if family == socket.AF_INET and type == socket.SOCK_STREAM:
++        if hasattr(socket, 'SO_REUSEADDR'):
++            if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) == 1:
++                raise TestFailed("tests should never set the SO_REUSEADDR "   \
++                                 "socket option on TCP/IP sockets!")
++        if hasattr(socket, 'SO_REUSEPORT'):
++            if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
++                raise TestFailed("tests should never set the SO_REUSEPORT "   \
++                                 "socket option on TCP/IP sockets!")
++        if hasattr(socket, 'SO_EXCLUSIVEADDRUSE'):
++            sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)
++
++    sock.bind((host, 0))
++    port = sock.getsockname()[1]
++    return port
++
+--- Python-2.7.3/Modules/_bsddb.c	2012-04-10 01:07:33.000000000 +0200
++++ bsddb3-5.3.0/Modules/_bsddb.c	2012-01-16 19:54:28.000000000 +0100
+@@ -64,7 +64,7 @@
+  *
+  * http://www.python.org/peps/pep-0291.html
+  *
+- * This module contains 6 types:
++ * This module contains 7 types:
+  *
+  * DB           (Database)
+  * DBCursor     (Database Cursor)
+@@ -72,6 +72,7 @@
+  * DBTxn        (An explicit database transaction)
+  * DBLock       (A lock handle)
+  * DBSequence   (Sequence)
++ * DBSite       (Site)
+  *
+  * More datatypes added:
+  *
+@@ -99,7 +100,7 @@
+ #include "bsddb.h"
+ #undef COMPILING_BSDDB_C
+ 
+-static char *rcs_id = "$Id$";
++static char *rcs_id = "$Id: _bsddb.c,v a377bbc1ed58 2012/01/16 18:54:28 jcea $";
+ 
+ /* --------------------------------------------------------------------- */
+ /* Various macro definitions */
+@@ -135,34 +136,11 @@
+ #define MYDB_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS;
+ #define MYDB_END_ALLOW_THREADS Py_END_ALLOW_THREADS;
+ 
+-/* For 2.3, use the PyGILState_ calls */
+-#if (PY_VERSION_HEX >= 0x02030000)
+-#define MYDB_USE_GILSTATE
+-#endif
+-
+ /* and these are for calling C --> Python */
+-#if defined(MYDB_USE_GILSTATE)
+ #define MYDB_BEGIN_BLOCK_THREADS \
+-                PyGILState_STATE __savestate = PyGILState_Ensure();
++		PyGILState_STATE __savestate = PyGILState_Ensure();
+ #define MYDB_END_BLOCK_THREADS \
+-                PyGILState_Release(__savestate);
+-#else /* MYDB_USE_GILSTATE */
+-/* Pre GILState API - do it the long old way */
+-static PyInterpreterState* _db_interpreterState = NULL;
+-#define MYDB_BEGIN_BLOCK_THREADS {                              \
+-        PyThreadState* prevState;                               \
+-        PyThreadState* newState;                                \
+-        PyEval_AcquireLock();                                   \
+-        newState  = PyThreadState_New(_db_interpreterState);    \
+-        prevState = PyThreadState_Swap(newState);
+-
+-#define MYDB_END_BLOCK_THREADS                                  \
+-        newState = PyThreadState_Swap(prevState);               \
+-        PyThreadState_Clear(newState);                          \
+-        PyEval_ReleaseLock();                                   \
+-        PyThreadState_Delete(newState);                         \
+-        }
+-#endif /* MYDB_USE_GILSTATE */
++		PyGILState_Release(__savestate);
+ 
+ #else
+ /* Compiled without threads - avoid all this cruft */
+@@ -187,24 +165,24 @@
+ static PyObject* DBRunRecoveryError;    /* DB_RUNRECOVERY */
+ static PyObject* DBVerifyBadError;      /* DB_VERIFY_BAD */
+ static PyObject* DBNoServerError;       /* DB_NOSERVER */
++#if (DBVER < 52)
+ static PyObject* DBNoServerHomeError;   /* DB_NOSERVER_HOME */
+ static PyObject* DBNoServerIDError;     /* DB_NOSERVER_ID */
++#endif
+ static PyObject* DBPageNotFoundError;   /* DB_PAGE_NOTFOUND */
+ static PyObject* DBSecondaryBadError;   /* DB_SECONDARY_BAD */
+ 
+ static PyObject* DBInvalidArgError;     /* EINVAL */
+ static PyObject* DBAccessError;         /* EACCES */
+ static PyObject* DBNoSpaceError;        /* ENOSPC */
+-static PyObject* DBNoMemoryError;       /* DB_BUFFER_SMALL (ENOMEM when < 4.3) */
++static PyObject* DBNoMemoryError;       /* DB_BUFFER_SMALL */
+ static PyObject* DBAgainError;          /* EAGAIN */
+ static PyObject* DBBusyError;           /* EBUSY  */
+ static PyObject* DBFileExistsError;     /* EEXIST */
+ static PyObject* DBNoSuchFileError;     /* ENOENT */
+ static PyObject* DBPermissionsError;    /* EPERM  */
+ 
+-#if (DBVER >= 42)
+ static PyObject* DBRepHandleDeadError;  /* DB_REP_HANDLE_DEAD */
+-#endif
+ #if (DBVER >= 44)
+ static PyObject* DBRepLockoutError;     /* DB_REP_LOCKOUT */
+ #endif
+@@ -220,10 +198,6 @@
+ 
+ static PyObject* DBRepUnavailError;     /* DB_REP_UNAVAIL */
+ 
+-#if (DBVER < 43)
+-#define DB_BUFFER_SMALL         ENOMEM
+-#endif
+-
+ #if (DBVER < 48)
+ #define DB_GID_SIZE DB_XIDDATASIZE
+ #endif
+@@ -252,8 +226,9 @@
+ 
+ staticforward PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type,
+               DBLock_Type, DBLogCursor_Type;
+-#if (DBVER >= 43)
+ staticforward PyTypeObject DBSequence_Type;
++#if (DBVER >= 52)
++staticforward PyTypeObject DBSite_Type;
+ #endif
+ 
+ #ifndef Py_TYPE
+@@ -267,8 +242,9 @@
+ #define DBEnvObject_Check(v)        (Py_TYPE(v) == &DBEnv_Type)
+ #define DBTxnObject_Check(v)        (Py_TYPE(v) == &DBTxn_Type)
+ #define DBLockObject_Check(v)       (Py_TYPE(v) == &DBLock_Type)
+-#if (DBVER >= 43)
+ #define DBSequenceObject_Check(v)   (Py_TYPE(v) == &DBSequence_Type)
++#if (DBVER >= 52)
++#define DBSiteObject_Check(v)       (Py_TYPE(v) == &DBSite_Type)
+ #endif
+ 
+ #if (DBVER < 46)
+@@ -372,9 +348,12 @@
+ #define CHECK_LOGCURSOR_NOT_CLOSED(logcurs) \
+         _CHECK_OBJECT_NOT_CLOSED(logcurs->logc, DBCursorClosedError, DBLogCursor)
+ 
+-#if (DBVER >= 43)
+ #define CHECK_SEQUENCE_NOT_CLOSED(curs) \
+         _CHECK_OBJECT_NOT_CLOSED(curs->sequence, DBError, DBSequence)
++
++#if (DBVER >= 52)
++#define CHECK_SITE_NOT_CLOSED(db_site) \
++         _CHECK_OBJECT_NOT_CLOSED(db_site->site, DBError, DBSite)
+ #endif
+ 
+ #define CHECK_DBFLAG(mydb, flag)    (((mydb)->flags & (flag)) || \
+@@ -554,7 +533,7 @@
+ 
+     srclen = strlen(src);
+     if (n <= 0)
+-        return srclen;
++	return srclen;
+     copylen = (srclen > n-1) ? n-1 : srclen;
+     /* populate dest[0] thru dest[copylen-1] */
+     memcpy(dest, src, copylen);
+@@ -567,12 +546,8 @@
+ /* Callback used to save away more information about errors from the DB
+  * library. */
+ static char _db_errmsg[1024];
+-#if (DBVER <= 42)
+-static void _db_errorCallback(const char* prefix, char* msg)
+-#else
+ static void _db_errorCallback(const DB_ENV *db_env,
+-        const char* prefix, const char* msg)
+-#endif
++	const char* prefix, const char* msg)
+ {
+     our_strlcpy(_db_errmsg, msg, sizeof(_db_errmsg));
+ }
+@@ -626,11 +601,7 @@
+       return NULL;
+   }
+ 
+-#if (PY_VERSION_HEX >= 0x02040000)
+   r = PyTuple_Pack(2, a, b) ;
+-#else
+-  r = Py_BuildValue("OO", a, b);
+-#endif
+   Py_DECREF(a);
+   Py_DECREF(b);
+   return r;
+@@ -696,16 +667,15 @@
+         case DB_RUNRECOVERY:        errObj = DBRunRecoveryError;    break;
+         case DB_VERIFY_BAD:         errObj = DBVerifyBadError;      break;
+         case DB_NOSERVER:           errObj = DBNoServerError;       break;
++#if (DBVER < 52)
+         case DB_NOSERVER_HOME:      errObj = DBNoServerHomeError;   break;
+         case DB_NOSERVER_ID:        errObj = DBNoServerIDError;     break;
++#endif
+         case DB_PAGE_NOTFOUND:      errObj = DBPageNotFoundError;   break;
+         case DB_SECONDARY_BAD:      errObj = DBSecondaryBadError;   break;
+         case DB_BUFFER_SMALL:       errObj = DBNoMemoryError;       break;
+ 
+-#if (DBVER >= 43)
+-        /* ENOMEM and DB_BUFFER_SMALL were one and the same until 4.3 */
+         case ENOMEM:  errObj = PyExc_MemoryError;   break;
+-#endif
+         case EINVAL:  errObj = DBInvalidArgError;   break;
+         case EACCES:  errObj = DBAccessError;       break;
+         case ENOSPC:  errObj = DBNoSpaceError;      break;
+@@ -715,9 +685,7 @@
+         case ENOENT:  errObj = DBNoSuchFileError;   break;
+         case EPERM :  errObj = DBPermissionsError;  break;
+ 
+-#if (DBVER >= 42)
+         case DB_REP_HANDLE_DEAD : errObj = DBRepHandleDeadError; break;
+-#endif
+ #if (DBVER >= 44)
+         case DB_REP_LOCKOUT : errObj = DBRepLockoutError; break;
+ #endif
+@@ -818,7 +786,7 @@
+ 
+ /* Get a key/data pair from a cursor */
+ static PyObject* _DBCursor_get(DBCursorObject* self, int extra_flags,
+-                               PyObject *args, PyObject *kwargs, char *format)
++			       PyObject *args, PyObject *kwargs, char *format)
+ {
+     int err;
+     PyObject* retval = NULL;
+@@ -829,7 +797,7 @@
+     static char* kwnames[] = { "flags", "dlen", "doff", NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, format, kwnames,
+-                                     &flags, &dlen, &doff))
++				     &flags, &dlen, &doff))
+       return NULL;
+ 
+     CHECK_CURSOR_NOT_CLOSED(self);
+@@ -845,7 +813,7 @@
+     MYDB_END_ALLOW_THREADS;
+ 
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->mydb->moduleFlags.getReturnsNone) {
++	    && self->mydb->moduleFlags.getReturnsNone) {
+         Py_INCREF(Py_None);
+         retval = Py_None;
+     }
+@@ -889,20 +857,19 @@
+ static void _addTimeTToDict(PyObject* dict, char *name, time_t value)
+ {
+     PyObject* v;
+-        /* if the value fits in regular int, use that. */
++	/* if the value fits in regular int, use that. */
+ #ifdef PY_LONG_LONG
+-        if (sizeof(time_t) > sizeof(long))
+-                v = PyLong_FromLongLong((PY_LONG_LONG) value);
+-        else
++	if (sizeof(time_t) > sizeof(long))
++		v = PyLong_FromLongLong((PY_LONG_LONG) value);
++	else
+ #endif
+-                v = NUMBER_FromLong((long) value);
++		v = NUMBER_FromLong((long) value);
+     if (!v || PyDict_SetItemString(dict, name, v))
+         PyErr_Clear();
+ 
+     Py_XDECREF(v);
+ }
+ 
+-#if (DBVER >= 43)
+ /* add an db_seq_t to a dictionary using the given name as a key */
+ static void _addDb_seq_tToDict(PyObject* dict, char *name, db_seq_t value)
+ {
+@@ -912,7 +879,6 @@
+ 
+     Py_XDECREF(v);
+ }
+-#endif
+ 
+ static void _addDB_lsnToDict(PyObject* dict, char *name, DB_LSN value)
+ {
+@@ -942,11 +908,10 @@
+     self->myenvobj = NULL;
+     self->db = NULL;
+     self->children_cursors = NULL;
+-#if (DBVER >=43)
+     self->children_sequences = NULL;
+-#endif
+     self->associateCallback = NULL;
+     self->btCompareCallback = NULL;
++    self->dupCompareCallback = NULL;
+     self->primaryDBType = 0;
+     Py_INCREF(Py_None);
+     self->private_obj = Py_None;
+@@ -1028,6 +993,10 @@
+         Py_DECREF(self->btCompareCallback);
+         self->btCompareCallback = NULL;
+     }
++    if (self->dupCompareCallback != NULL) {
++        Py_DECREF(self->dupCompareCallback);
++        self->dupCompareCallback = NULL;
++    }
+     Py_DECREF(self->private_obj);
+     PyObject_Del(self);
+ }
+@@ -1044,10 +1013,10 @@
+ 
+     INSERT_IN_DOUBLE_LINKED_LIST(self->mydb->children_cursors,self);
+     if (txn && ((PyObject *)txn!=Py_None)) {
+-            INSERT_IN_DOUBLE_LINKED_LIST_TXN(txn->children_cursors,self);
+-            self->txn=txn;
++	    INSERT_IN_DOUBLE_LINKED_LIST_TXN(txn->children_cursors,self);
++	    self->txn=txn;
+     } else {
+-            self->txn=NULL;
++	    self->txn=NULL;
+     }
+ 
+     self->in_weakreflist = NULL;
+@@ -1147,6 +1116,9 @@
+     self->children_dbs = NULL;
+     self->children_txns = NULL;
+     self->children_logcursors = NULL ;
++#if (DBVER >= 52)
++    self->children_sites = NULL;
++#endif
+     Py_INCREF(Py_None);
+     self->private_obj = Py_None;
+     Py_INCREF(Py_None);
+@@ -1340,7 +1312,6 @@
+ }
+ 
+ 
+-#if (DBVER >= 43)
+ static DBSequenceObject*
+ newDBSequenceObject(DBObject* mydb,  int flags)
+ {
+@@ -1396,6 +1367,53 @@
+     Py_DECREF(self->mydb);
+     PyObject_Del(self);
+ }
++
++#if (DBVER >= 52)
++static DBSiteObject*
++newDBSiteObject(DB_SITE* sitep, DBEnvObject* env)
++{
++    DBSiteObject* self;
++
++    self = PyObject_New(DBSiteObject, &DBSite_Type);
++
++    if (self == NULL)
++        return NULL;
++
++    self->site = sitep;
++    self->env = env;
++
++    INSERT_IN_DOUBLE_LINKED_LIST(self->env->children_sites, self);
++
++    self->in_weakreflist = NULL;
++    Py_INCREF(self->env);
++    return self;
++}
++
++/* Forward declaration */
++static PyObject *DBSite_close_internal(DBSiteObject* self);
++
++static void
++DBSite_dealloc(DBSiteObject* self)
++{
++    PyObject *dummy;
++
++    if (self->site != NULL) {
++        dummy = DBSite_close_internal(self);
++        /*
++        ** Raising exceptions while doing
++        ** garbage collection is a fatal error.
++        */
++        if (dummy)
++            Py_DECREF(dummy);
++        else
++            PyErr_Clear();
++    }
++    if (self->in_weakreflist != NULL) {
++        PyObject_ClearWeakRefs((PyObject *) self);
++    }
++    Py_DECREF(self->env);
++    PyObject_Del(self);
++}
+ #endif
+ 
+ /* --------------------------------------------------------------------- */
+@@ -1474,16 +1492,16 @@
+             PyBytes_AsStringAndSize(result, &data, &size);
+             secKey->flags = DB_DBT_APPMALLOC;   /* DB will free */
+             secKey->data = malloc(size);        /* TODO, check this */
+-            if (secKey->data) {
+-                memcpy(secKey->data, data, size);
+-                secKey->size = size;
+-                retval = 0;
+-            }
+-            else {
+-                PyErr_SetString(PyExc_MemoryError,
++	    if (secKey->data) {
++		memcpy(secKey->data, data, size);
++		secKey->size = size;
++		retval = 0;
++	    }
++	    else {
++		PyErr_SetString(PyExc_MemoryError,
+                                 "malloc failed in _db_associateCallback");
+-                PyErr_Print();
+-            }
++		PyErr_Print();
++	    }
+         }
+ #if (DBVER >= 46)
+         else if (PyList_Check(result))
+@@ -1615,7 +1633,7 @@
+ #endif
+     MYDB_BEGIN_ALLOW_THREADS;
+     err = self->db->associate(self->db,
+-                              txn,
++	                      txn,
+                               secondaryDB->db,
+                               _db_associateCallback,
+                               flags);
+@@ -1652,12 +1670,10 @@
+           Py_XDECREF(dummy);
+         }
+ 
+-#if (DBVER >= 43)
+         while(self->children_sequences) {
+             dummy=DBSequence_close_internal(self->children_sequences,0,0);
+             Py_XDECREF(dummy);
+         }
+-#endif
+ 
+         /*
+         ** "do_not_close" is used to dispose all related objects in the
+@@ -1727,7 +1743,7 @@
+     MYDB_END_ALLOW_THREADS;
+ 
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->moduleFlags.getReturnsNone) {
++	    && self->moduleFlags.getReturnsNone) {
+         err = 0;
+         Py_INCREF(Py_None);
+         retval = Py_None;
+@@ -1981,7 +1997,7 @@
+         retval = dfltobj;
+     }
+     else if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-             && self->moduleFlags.getReturnsNone) {
++	     && self->moduleFlags.getReturnsNone) {
+         err = 0;
+         Py_INCREF(Py_None);
+         retval = Py_None;
+@@ -2050,7 +2066,7 @@
+         retval = dfltobj;
+     }
+     else if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-             && self->moduleFlags.getReturnsNone) {
++	     && self->moduleFlags.getReturnsNone) {
+         err = 0;
+         Py_INCREF(Py_None);
+         retval = Py_None;
+@@ -2074,20 +2090,12 @@
+                 keyObj = NUMBER_FromLong(*(int *)key.data);
+             else
+                 keyObj = Build_PyString(key.data, key.size);
+-#if (PY_VERSION_HEX >= 0x02040000)
+             retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
+-#else
+-            retval = Py_BuildValue("OOO", keyObj, pkeyObj, dataObj);
+-#endif
+             Py_DECREF(keyObj);
+         }
+         else /* return just the pkey and data */
+         {
+-#if (PY_VERSION_HEX >= 0x02040000)
+             retval = PyTuple_Pack(2, pkeyObj, dataObj);
+-#else
+-            retval = Py_BuildValue("OO", pkeyObj, dataObj);
+-#endif
+         }
+         Py_DECREF(dataObj);
+         Py_DECREF(pkeyObj);
+@@ -2132,7 +2140,7 @@
+     MYDB_BEGIN_ALLOW_THREADS;
+     err = self->db->get(self->db, txn, &key, &data, flags);
+     MYDB_END_ALLOW_THREADS;
+-    if (err == DB_BUFFER_SMALL) {
++    if ((err == DB_BUFFER_SMALL) || (err == 0)) {
+         retval = NUMBER_FromLong((long)data.size);
+         err = 0;
+     }
+@@ -2185,7 +2193,7 @@
+     MYDB_END_ALLOW_THREADS;
+ 
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->moduleFlags.getReturnsNone) {
++	    && self->moduleFlags.getReturnsNone) {
+         err = 0;
+         Py_INCREF(Py_None);
+         retval = Py_None;
+@@ -2341,17 +2349,17 @@
+         "filename", "dbtype", "flags", "mode", "txn", NULL};
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|ziiiO:open", kwnames,
+-                                     &filename, &dbname, &type, &flags, &mode,
++				     &filename, &dbname, &type, &flags, &mode,
+                                      &txnobj))
+     {
+-        PyErr_Clear();
+-        type = DB_UNKNOWN; flags = 0; mode = 0660;
+-        filename = NULL; dbname = NULL;
+-        if (!PyArg_ParseTupleAndKeywords(args, kwargs,"z|iiiO:open",
++	PyErr_Clear();
++	type = DB_UNKNOWN; flags = 0; mode = 0660;
++	filename = NULL; dbname = NULL;
++	if (!PyArg_ParseTupleAndKeywords(args, kwargs,"z|iiiO:open",
+                                          kwnames_basic,
+-                                         &filename, &type, &flags, &mode,
++					 &filename, &type, &flags, &mode,
+                                          &txnobj))
+-            return NULL;
++	    return NULL;
+     }
+ 
+     if (!checkTxnObj(txnobj, &txn)) return NULL;
+@@ -2385,9 +2393,7 @@
+         return NULL;
+     }
+ 
+-#if (DBVER >= 42)
+     self->db->get_flags(self->db, &self->setflags);
+-#endif
+ 
+     self->flags = flags;
+ 
+@@ -2539,6 +2545,37 @@
+ #endif
+ 
+ static PyObject*
++DB_get_dbname(DBObject* self)
++{
++    int err;
++    const char *filename, *dbname;
++
++    CHECK_DB_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db->get_dbname(self->db, &filename, &dbname);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++    /* If "dbname==NULL", it is correctly converted to "None" */
++    return Py_BuildValue("(ss)", filename, dbname);
++}
++
++static PyObject*
++DB_get_open_flags(DBObject* self)
++{
++    int err;
++    unsigned int flags;
++
++    CHECK_DB_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db->get_open_flags(self->db, &flags);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++    return NUMBER_FromLong(flags);
++}
++
++static PyObject*
+ DB_set_q_extentsize(DBObject* self, PyObject* args)
+ {
+     int err;
+@@ -2555,7 +2592,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_q_extentsize(DBObject* self)
+ {
+@@ -2570,7 +2606,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(extentsize);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_bt_minkey(DBObject* self, PyObject* args)
+@@ -2588,7 +2623,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_bt_minkey(DBObject* self)
+ {
+@@ -2603,24 +2637,23 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(bt_minkey);
+ }
+-#endif
+ 
+ static int
+ _default_cmp(const DBT *leftKey,
+-             const DBT *rightKey)
++	     const DBT *rightKey)
+ {
+   int res;
+   int lsize = leftKey->size, rsize = rightKey->size;
+ 
+   res = memcmp(leftKey->data, rightKey->data,
+-               lsize < rsize ? lsize : rsize);
++	       lsize < rsize ? lsize : rsize);
+ 
+   if (res == 0) {
+       if (lsize < rsize) {
+-          res = -1;
++	  res = -1;
+       }
+       else if (lsize > rsize) {
+-          res = 1;
++	  res = 1;
+       }
+   }
+   return res;
+@@ -2628,8 +2661,8 @@
+ 
+ static int
+ _db_compareCallback(DB* db,
+-                    const DBT *leftKey,
+-                    const DBT *rightKey)
++		    const DBT *leftKey,
++		    const DBT *rightKey)
+ {
+     int res = 0;
+     PyObject *args;
+@@ -2637,40 +2670,40 @@
+     DBObject *self = (DBObject *)db->app_private;
+ 
+     if (self == NULL || self->btCompareCallback == NULL) {
+-        MYDB_BEGIN_BLOCK_THREADS;
+-        PyErr_SetString(PyExc_TypeError,
+-                        (self == 0
+-                         ? "DB_bt_compare db is NULL."
+-                         : "DB_bt_compare callback is NULL."));
+-        /* we're in a callback within the DB code, we can't raise */
+-        PyErr_Print();
+-        res = _default_cmp(leftKey, rightKey);
+-        MYDB_END_BLOCK_THREADS;
++	MYDB_BEGIN_BLOCK_THREADS;
++	PyErr_SetString(PyExc_TypeError,
++			(self == 0
++			 ? "DB_bt_compare db is NULL."
++			 : "DB_bt_compare callback is NULL."));
++	/* we're in a callback within the DB code, we can't raise */
++	PyErr_Print();
++	res = _default_cmp(leftKey, rightKey);
++	MYDB_END_BLOCK_THREADS;
+     } else {
+-        MYDB_BEGIN_BLOCK_THREADS;
++	MYDB_BEGIN_BLOCK_THREADS;
+ 
+-        args = BuildValue_SS(leftKey->data, leftKey->size, rightKey->data, rightKey->size);
+-        if (args != NULL) {
+-                result = PyEval_CallObject(self->btCompareCallback, args);
+-        }
+-        if (args == NULL || result == NULL) {
+-            /* we're in a callback within the DB code, we can't raise */
+-            PyErr_Print();
+-            res = _default_cmp(leftKey, rightKey);
+-        } else if (NUMBER_Check(result)) {
+-            res = NUMBER_AsLong(result);
+-        } else {
+-            PyErr_SetString(PyExc_TypeError,
+-                            "DB_bt_compare callback MUST return an int.");
+-            /* we're in a callback within the DB code, we can't raise */
+-            PyErr_Print();
+-            res = _default_cmp(leftKey, rightKey);
+-        }
++	args = BuildValue_SS(leftKey->data, leftKey->size, rightKey->data, rightKey->size);
++	if (args != NULL) {
++		result = PyEval_CallObject(self->btCompareCallback, args);
++	}
++	if (args == NULL || result == NULL) {
++	    /* we're in a callback within the DB code, we can't raise */
++	    PyErr_Print();
++	    res = _default_cmp(leftKey, rightKey);
++	} else if (NUMBER_Check(result)) {
++	    res = NUMBER_AsLong(result);
++	} else {
++	    PyErr_SetString(PyExc_TypeError,
++			    "DB_bt_compare callback MUST return an int.");
++	    /* we're in a callback within the DB code, we can't raise */
++	    PyErr_Print();
++	    res = _default_cmp(leftKey, rightKey);
++	}
+ 
+-        Py_XDECREF(args);
+-        Py_XDECREF(result);
++	Py_XDECREF(args);
++	Py_XDECREF(result);
+ 
+-        MYDB_END_BLOCK_THREADS;
++	MYDB_END_BLOCK_THREADS;
+     }
+     return res;
+ }
+@@ -2684,8 +2717,8 @@
+     CHECK_DB_NOT_CLOSED(self);
+ 
+     if (!PyCallable_Check(comparator)) {
+-        makeTypeError("Callable", comparator);
+-        return NULL;
++	makeTypeError("Callable", comparator);
++	return NULL;
+     }
+ 
+     /*
+@@ -2699,15 +2732,15 @@
+     if (result == NULL)
+         return NULL;
+     if (!NUMBER_Check(result)) {
+-        Py_DECREF(result);
+-        PyErr_SetString(PyExc_TypeError,
+-                        "callback MUST return an int");
+-        return NULL;
++	Py_DECREF(result);
++	PyErr_SetString(PyExc_TypeError,
++		        "callback MUST return an int");
++	return NULL;
+     } else if (NUMBER_AsLong(result) != 0) {
+-        Py_DECREF(result);
+-        PyErr_SetString(PyExc_TypeError,
+-                        "callback failed to return 0 on two empty strings");
+-        return NULL;
++	Py_DECREF(result);
++	PyErr_SetString(PyExc_TypeError,
++		        "callback failed to return 0 on two empty strings");
++	return NULL;
+     }
+     Py_DECREF(result);
+ 
+@@ -2715,8 +2748,8 @@
+      * simplify the code. This would have no real use, as one cannot
+      * change the function once the db is opened anyway */
+     if (self->btCompareCallback != NULL) {
+-        PyErr_SetString(PyExc_RuntimeError, "set_bt_compare() cannot be called more than once");
+-        return NULL;
++	PyErr_SetString(PyExc_RuntimeError, "set_bt_compare() cannot be called more than once");
++	return NULL;
+     }
+ 
+     Py_INCREF(comparator);
+@@ -2731,9 +2764,123 @@
+     err = self->db->set_bt_compare(self->db, _db_compareCallback);
+ 
+     if (err) {
+-        /* restore the old state in case of error */
+-        Py_DECREF(comparator);
+-        self->btCompareCallback = NULL;
++	/* restore the old state in case of error */
++	Py_DECREF(comparator);
++	self->btCompareCallback = NULL;
++    }
++
++    RETURN_IF_ERR();
++    RETURN_NONE();
++}
++
++static int
++_db_dupCompareCallback(DB* db,
++		    const DBT *leftKey,
++		    const DBT *rightKey)
++{
++    int res = 0;
++    PyObject *args;
++    PyObject *result = NULL;
++    DBObject *self = (DBObject *)db->app_private;
++
++    if (self == NULL || self->dupCompareCallback == NULL) {
++	MYDB_BEGIN_BLOCK_THREADS;
++	PyErr_SetString(PyExc_TypeError,
++			(self == 0
++			 ? "DB_dup_compare db is NULL."
++			 : "DB_dup_compare callback is NULL."));
++	/* we're in a callback within the DB code, we can't raise */
++	PyErr_Print();
++	res = _default_cmp(leftKey, rightKey);
++	MYDB_END_BLOCK_THREADS;
++    } else {
++	MYDB_BEGIN_BLOCK_THREADS;
++
++	args = BuildValue_SS(leftKey->data, leftKey->size, rightKey->data, rightKey->size);
++	if (args != NULL) {
++		result = PyEval_CallObject(self->dupCompareCallback, args);
++	}
++	if (args == NULL || result == NULL) {
++	    /* we're in a callback within the DB code, we can't raise */
++	    PyErr_Print();
++	    res = _default_cmp(leftKey, rightKey);
++	} else if (NUMBER_Check(result)) {
++	    res = NUMBER_AsLong(result);
++	} else {
++	    PyErr_SetString(PyExc_TypeError,
++			    "DB_dup_compare callback MUST return an int.");
++	    /* we're in a callback within the DB code, we can't raise */
++	    PyErr_Print();
++	    res = _default_cmp(leftKey, rightKey);
++	}
++
++	Py_XDECREF(args);
++	Py_XDECREF(result);
++
++	MYDB_END_BLOCK_THREADS;
++    }
++    return res;
++}
++
++static PyObject*
++DB_set_dup_compare(DBObject* self, PyObject* comparator)
++{
++    int err;
++    PyObject *tuple, *result;
++
++    CHECK_DB_NOT_CLOSED(self);
++
++    if (!PyCallable_Check(comparator)) {
++	makeTypeError("Callable", comparator);
++	return NULL;
++    }
++
++    /*
++     * Perform a test call of the comparator function with two empty
++     * string objects here.  verify that it returns an int (0).
++     * err if not.
++     */
++    tuple = Py_BuildValue("(ss)", "", "");
++    result = PyEval_CallObject(comparator, tuple);
++    Py_DECREF(tuple);
++    if (result == NULL)
++        return NULL;
++    if (!NUMBER_Check(result)) {
++	Py_DECREF(result);
++	PyErr_SetString(PyExc_TypeError,
++		        "callback MUST return an int");
++	return NULL;
++    } else if (NUMBER_AsLong(result) != 0) {
++	Py_DECREF(result);
++	PyErr_SetString(PyExc_TypeError,
++		        "callback failed to return 0 on two empty strings");
++	return NULL;
++    }
++    Py_DECREF(result);
++
++    /* We don't accept multiple set_dup_compare operations, in order to
++     * simplify the code. This would have no real use, as one cannot
++     * change the function once the db is opened anyway */
++    if (self->dupCompareCallback != NULL) {
++	PyErr_SetString(PyExc_RuntimeError, "set_dup_compare() cannot be called more than once");
++	return NULL;
++    }
++
++    Py_INCREF(comparator);
++    self->dupCompareCallback = comparator;
++
++    /* This is to workaround a problem with un-initialized threads (see
++       comment in DB_associate) */
++#ifdef WITH_THREAD
++    PyEval_InitThreads();
++#endif
++
++    err = self->db->set_dup_compare(self->db, _db_dupCompareCallback);
++
++    if (err) {
++	/* restore the old state in case of error */
++	Py_DECREF(comparator);
++	self->dupCompareCallback = NULL;
+     }
+ 
+     RETURN_IF_ERR();
+@@ -2759,7 +2906,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_cachesize(DBObject* self)
+ {
+@@ -2777,7 +2923,6 @@
+ 
+     return Py_BuildValue("(iii)", gbytes, bytes, ncache);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_flags(DBObject* self, PyObject* args)
+@@ -2797,7 +2942,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_flags(DBObject* self)
+ {
+@@ -2812,7 +2956,34 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(flags);
+ }
+-#endif
++
++static PyObject*
++DB_get_transactional(DBObject* self)
++{
++    int err;
++
++    CHECK_DB_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db->get_transactional(self->db);
++    MYDB_END_ALLOW_THREADS;
++
++    if(err == 0) {
++        Py_INCREF(Py_False);
++        return Py_False;
++    } else if(err == 1) {
++        Py_INCREF(Py_True);
++        return Py_True;
++    }
++
++    /*
++    ** If we reach there, there was an error. The
++    ** "return" should be unreachable.
++    */
++    RETURN_IF_ERR();
++    assert(0);  /* This code SHOULD be unreachable */
++    return NULL;
++}
+ 
+ static PyObject*
+ DB_set_h_ffactor(DBObject* self, PyObject* args)
+@@ -2830,7 +3001,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_h_ffactor(DBObject* self)
+ {
+@@ -2845,7 +3015,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(ffactor);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_h_nelem(DBObject* self, PyObject* args)
+@@ -2863,7 +3032,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_h_nelem(DBObject* self)
+ {
+@@ -2878,7 +3046,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(nelem);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_lorder(DBObject* self, PyObject* args)
+@@ -2896,7 +3063,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_lorder(DBObject* self)
+ {
+@@ -2911,7 +3077,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(lorder);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_pagesize(DBObject* self, PyObject* args)
+@@ -2929,7 +3094,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_pagesize(DBObject* self)
+ {
+@@ -2944,7 +3108,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(pagesize);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_re_delim(DBObject* self, PyObject* args)
+@@ -2967,7 +3130,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_re_delim(DBObject* self)
+ {
+@@ -2981,7 +3143,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(re_delim);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_re_len(DBObject* self, PyObject* args)
+@@ -2999,7 +3160,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_re_len(DBObject* self)
+ {
+@@ -3014,7 +3174,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(re_len);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_re_pad(DBObject* self, PyObject* args)
+@@ -3036,7 +3195,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_re_pad(DBObject* self)
+ {
+@@ -3050,7 +3208,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(re_pad);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_set_re_source(DBObject* self, PyObject* args)
+@@ -3069,7 +3226,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_re_source(DBObject* self)
+ {
+@@ -3084,7 +3240,6 @@
+     RETURN_IF_ERR();
+     return PyBytes_FromString(source);
+ }
+-#endif
+ 
+ static PyObject*
+ DB_stat(DBObject* self, PyObject* args, PyObject* kwargs)
+@@ -3092,32 +3247,19 @@
+     int err, flags = 0, type;
+     void* sp;
+     PyObject* d;
+-#if (DBVER >= 43)
+     PyObject* txnobj = NULL;
+     DB_TXN *txn = NULL;
+     static char* kwnames[] = { "flags", "txn", NULL };
+-#else
+-    static char* kwnames[] = { "flags", NULL };
+-#endif
+ 
+-#if (DBVER >= 43)
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO:stat", kwnames,
+                                      &flags, &txnobj))
+         return NULL;
+     if (!checkTxnObj(txnobj, &txn))
+         return NULL;
+-#else
+-    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:stat", kwnames, &flags))
+-        return NULL;
+-#endif
+     CHECK_DB_NOT_CLOSED(self);
+ 
+     MYDB_BEGIN_ALLOW_THREADS;
+-#if (DBVER >= 43)
+     err = self->db->stat(self->db, txn, &sp, flags);
+-#else
+-    err = self->db->stat(self->db, &sp, flags);
+-#endif
+     MYDB_END_ALLOW_THREADS;
+     RETURN_IF_ERR();
+ 
+@@ -3172,9 +3314,7 @@
+         MAKE_BT_ENTRY(leaf_pg);
+         MAKE_BT_ENTRY(dup_pg);
+         MAKE_BT_ENTRY(over_pg);
+-#if (DBVER >= 43)
+         MAKE_BT_ENTRY(empty_pg);
+-#endif
+         MAKE_BT_ENTRY(free);
+         MAKE_BT_ENTRY(int_pgfree);
+         MAKE_BT_ENTRY(leaf_pgfree);
+@@ -3214,7 +3354,6 @@
+     return d;
+ }
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DB_stat_print(DBObject* self, PyObject* args, PyObject *kwargs)
+ {
+@@ -3234,7 +3373,6 @@
+     RETURN_IF_ERR();
+     RETURN_NONE();
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -3315,8 +3453,8 @@
+     CHECK_DB_NOT_CLOSED(self);
+     if (outFileName)
+         outFile = fopen(outFileName, "w");
+-        /* XXX(nnorwitz): it should probably be an exception if outFile
+-           can't be opened. */
++	/* XXX(nnorwitz): it should probably be an exception if outFile
++	   can't be opened. */
+ 
+     {  /* DB.verify acts as a DB handle destructor (like close) */
+         PyObject *error;
+@@ -3369,8 +3507,8 @@
+     static char* kwnames[] = { "passwd", "flags", NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|i:set_encrypt", kwnames,
+-                &passwd, &flags)) {
+-        return NULL;
++		&passwd, &flags)) {
++	return NULL;
+     }
+ 
+     MYDB_BEGIN_ALLOW_THREADS;
+@@ -3381,7 +3519,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DB_get_encrypt_flags(DBObject* self)
+ {
+@@ -3396,7 +3533,6 @@
+ 
+     return NUMBER_FromLong(flags);
+ }
+-#endif
+ 
+ 
+ 
+@@ -3420,11 +3556,7 @@
+     }
+ 
+     MYDB_BEGIN_ALLOW_THREADS;
+-#if (DBVER >= 43)
+     err = self->db->stat(self->db, /*txnid*/ NULL, &sp, 0);
+-#else
+-    err = self->db->stat(self->db, &sp, 0);
+-#endif
+     MYDB_END_ALLOW_THREADS;
+ 
+     /* All the stat structures have matching fields upto the ndata field,
+@@ -3868,69 +4000,199 @@
+ }
+ 
+ 
+-
+ /* --------------------------------------------------------------------- */
+-/* DBCursor methods */
++/* DBSite methods */
+ 
+ 
++#if (DBVER >= 52)
+ static PyObject*
+-DBC_close_internal(DBCursorObject* self)
++DBSite_close_internal(DBSiteObject* self)
+ {
+     int err = 0;
+ 
+-    if (self->dbc != NULL) {
++    if (self->site != NULL) {
+         EXTRACT_FROM_DOUBLE_LINKED_LIST(self);
+-        if (self->txn) {
+-            EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(self);
+-            self->txn=NULL;
+-        }
  
+         MYDB_BEGIN_ALLOW_THREADS;
+-        err = _DBC_close(self->dbc);
++        err = self->site->close(self->site);
+         MYDB_END_ALLOW_THREADS;
+-        self->dbc = NULL;
++        self->site = NULL;
+     }
+     RETURN_IF_ERR();
+     RETURN_NONE();
+ }
+ 
+ static PyObject*
+-DBC_close(DBCursorObject* self)
++DBSite_close(DBSiteObject* self)
+ {
+-    return DBC_close_internal(self);
++    return DBSite_close_internal(self);
+ }
+ 
+-
+ static PyObject*
+-DBC_count(DBCursorObject* self, PyObject* args)
++DBSite_remove(DBSiteObject* self)
+ {
+     int err = 0;
+-    db_recno_t count;
+-    int flags = 0;
+ 
+-    if (!PyArg_ParseTuple(args, "|i:count", &flags))
+-        return NULL;
+-
+-    CHECK_CURSOR_NOT_CLOSED(self);
++    CHECK_SITE_NOT_CLOSED(self);
+ 
+     MYDB_BEGIN_ALLOW_THREADS;
+-    err = _DBC_count(self->dbc, &count, flags);
++    err = self->site->remove(self->site);
+     MYDB_END_ALLOW_THREADS;
+-    RETURN_IF_ERR();
+ 
+-    return NUMBER_FromLong(count);
++    RETURN_IF_ERR();
++    RETURN_NONE();
+ }
+ 
+-
+ static PyObject*
+-DBC_current(DBCursorObject* self, PyObject* args, PyObject *kwargs)
++DBSite_get_eid(DBSiteObject* self)
+ {
+-    return _DBCursor_get(self,DB_CURRENT,args,kwargs,"|iii:current");
+-}
++    int err = 0;
++    int eid;
+ 
++    CHECK_SITE_NOT_CLOSED(self);
+ 
+-static PyObject*
+-DBC_delete(DBCursorObject* self, PyObject* args)
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->site->get_eid(self->site, &eid);
++    MYDB_END_ALLOW_THREADS;
++
++    RETURN_IF_ERR();
++    return NUMBER_FromLong(eid);
++}
++
++static PyObject*
++DBSite_get_address(DBSiteObject* self)
++{
++    int err = 0;
++    const char *host;
++    u_int port;
++
++    CHECK_SITE_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->site->get_address(self->site, &host, &port);
++    MYDB_END_ALLOW_THREADS;
++
++    RETURN_IF_ERR();
++
++    return Py_BuildValue("(sI)", host, port);
++}
++
++static PyObject*
++DBSite_get_config(DBSiteObject* self, PyObject* args, PyObject* kwargs)
++{
++    int err = 0;
++    u_int32_t which, value;
++    static char* kwnames[] = { "which", NULL };
++
++    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:get_config", kwnames,
++                                     &which))
++        return NULL;
++
++    CHECK_SITE_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->site->get_config(self->site, which, &value);
++    MYDB_END_ALLOW_THREADS;
++
++    RETURN_IF_ERR();
++
++    if (value) {
++        Py_INCREF(Py_True);
++        return Py_True;
++    } else {
++        Py_INCREF(Py_False);
++        return Py_False;
++    }
++}
++
++static PyObject*
++DBSite_set_config(DBSiteObject* self, PyObject* args, PyObject* kwargs)
++{
++    int err = 0;
++    u_int32_t which, value;
++    PyObject *valueO;
++    static char* kwnames[] = { "which", "value", NULL };
++
++    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO:set_config", kwnames,
++                                     &which, &valueO))
++        return NULL;
++
++    CHECK_SITE_NOT_CLOSED(self);
++
++    value = PyObject_IsTrue(valueO);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->site->set_config(self->site, which, value);
++    MYDB_END_ALLOW_THREADS;
++
++    RETURN_IF_ERR();
++    RETURN_NONE();
++}
++#endif
++
++
++/* --------------------------------------------------------------------- */
++/* DBCursor methods */
++
++
++static PyObject*
++DBC_close_internal(DBCursorObject* self)
++{
++    int err = 0;
++
++    if (self->dbc != NULL) {
++        EXTRACT_FROM_DOUBLE_LINKED_LIST(self);
++        if (self->txn) {
++            EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(self);
++            self->txn=NULL;
++        }
++
++        MYDB_BEGIN_ALLOW_THREADS;
++        err = _DBC_close(self->dbc);
++        MYDB_END_ALLOW_THREADS;
++        self->dbc = NULL;
++    }
++    RETURN_IF_ERR();
++    RETURN_NONE();
++}
++
++static PyObject*
++DBC_close(DBCursorObject* self)
++{
++    return DBC_close_internal(self);
++}
++
++
++static PyObject*
++DBC_count(DBCursorObject* self, PyObject* args)
++{
++    int err = 0;
++    db_recno_t count;
++    int flags = 0;
++
++    if (!PyArg_ParseTuple(args, "|i:count", &flags))
++        return NULL;
++
++    CHECK_CURSOR_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = _DBC_count(self->dbc, &count, flags);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++
++    return NUMBER_FromLong(count);
++}
++
++
++static PyObject*
++DBC_current(DBCursorObject* self, PyObject* args, PyObject *kwargs)
++{
++    return _DBCursor_get(self,DB_CURRENT,args,kwargs,"|iii:current");
++}
++
++
++static PyObject*
++DBC_delete(DBCursorObject* self, PyObject* args)
+ {
+     int err, flags=0;
+ 
+@@ -3990,12 +4252,12 @@
+     CLEAR_DBT(key);
+     CLEAR_DBT(data);
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|ii:get", &kwnames[2],
+-                                     &flags, &dlen, &doff))
++				     &flags, &dlen, &doff))
+     {
+         PyErr_Clear();
+         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|ii:get",
+                                          &kwnames[1],
+-                                         &keyobj, &flags, &dlen, &doff))
++					 &keyobj, &flags, &dlen, &doff))
+         {
+             PyErr_Clear();
+             if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOi|ii:get",
+@@ -4003,8 +4265,8 @@
+                                              &flags, &dlen, &doff))
+             {
+                 return NULL;
+-            }
+-        }
++	    }
++	}
+     }
+ 
+     CHECK_CURSOR_NOT_CLOSED(self);
+@@ -4023,7 +4285,7 @@
+     MYDB_END_ALLOW_THREADS;
+ 
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->mydb->moduleFlags.getReturnsNone) {
++	    && self->mydb->moduleFlags.getReturnsNone) {
+         Py_INCREF(Py_None);
+         retval = Py_None;
+     }
+@@ -4066,12 +4328,12 @@
+     CLEAR_DBT(key);
+     CLEAR_DBT(data);
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|ii:pget", &kwnames[2],
+-                                     &flags, &dlen, &doff))
++				     &flags, &dlen, &doff))
+     {
+         PyErr_Clear();
+         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|ii:pget",
+                                          kwnames_keyOnly,
+-                                         &keyobj, &flags, &dlen, &doff))
++					 &keyobj, &flags, &dlen, &doff))
+         {
+             PyErr_Clear();
+             if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOi|ii:pget",
+@@ -4079,8 +4341,8 @@
+                                              &flags, &dlen, &doff))
+             {
+                 return NULL;
+-            }
+-        }
++	    }
++	}
+     }
+ 
+     CHECK_CURSOR_NOT_CLOSED(self);
+@@ -4101,7 +4363,7 @@
+     MYDB_END_ALLOW_THREADS;
+ 
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->mydb->moduleFlags.getReturnsNone) {
++	    && self->mydb->moduleFlags.getReturnsNone) {
+         Py_INCREF(Py_None);
+         retval = Py_None;
+     }
+@@ -4127,21 +4389,13 @@
+                 keyObj = NUMBER_FromLong(*(int *)key.data);
+             else
+                 keyObj = Build_PyString(key.data, key.size);
+-#if (PY_VERSION_HEX >= 0x02040000)
+             retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
+-#else
+-            retval = Py_BuildValue("OOO", keyObj, pkeyObj, dataObj);
+-#endif
+             Py_DECREF(keyObj);
+             FREE_DBT(key);  /* 'make_key_dbt' could do a 'malloc' */
+         }
+         else /* return just the pkey and data */
+         {
+-#if (PY_VERSION_HEX >= 0x02040000)
+             retval = PyTuple_Pack(2, pkeyObj, dataObj);
+-#else
+-            retval = Py_BuildValue("OO", pkeyObj, dataObj);
+-#endif
+         }
+         Py_DECREF(dataObj);
+         Py_DECREF(pkeyObj);
+@@ -4212,7 +4466,7 @@
+     int doff = -1;
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|iii:put", kwnames,
+-                                     &keyobj, &dataobj, &flags, &dlen, &doff))
++				     &keyobj, &dataobj, &flags, &dlen, &doff))
+         return NULL;
+ 
+     CHECK_CURSOR_NOT_CLOSED(self);
+@@ -4246,7 +4500,7 @@
+     int doff = -1;
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iii:set", kwnames,
+-                                     &keyobj, &flags, &dlen, &doff))
++				     &keyobj, &flags, &dlen, &doff))
+         return NULL;
+ 
+     CHECK_CURSOR_NOT_CLOSED(self);
+@@ -4264,7 +4518,7 @@
+     err = _DBC_get(self->dbc, &key, &data, flags|DB_SET);
+     MYDB_END_ALLOW_THREADS;
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->mydb->moduleFlags.cursorSetReturnsNone) {
++	    && self->mydb->moduleFlags.cursorSetReturnsNone) {
+         Py_INCREF(Py_None);
+         retval = Py_None;
+     }
+@@ -4309,7 +4563,7 @@
+     int doff = -1;
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iii:set_range", kwnames,
+-                                     &keyobj, &flags, &dlen, &doff))
++				     &keyobj, &flags, &dlen, &doff))
+         return NULL;
+ 
+     CHECK_CURSOR_NOT_CLOSED(self);
+@@ -4326,7 +4580,7 @@
+     err = _DBC_get(self->dbc, &key, &data, flags|DB_SET_RANGE);
+     MYDB_END_ALLOW_THREADS;
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->mydb->moduleFlags.cursorSetReturnsNone) {
++	    && self->mydb->moduleFlags.cursorSetReturnsNone) {
+         Py_INCREF(Py_None);
+         retval = Py_None;
+     }
+@@ -4480,7 +4734,7 @@
+     static char* kwnames[] = { "recno","flags", "dlen", "doff", NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|iii:set_recno", kwnames,
+-                                     &irecno, &flags, &dlen, &doff))
++				     &irecno, &flags, &dlen, &doff))
+       return NULL;
+ 
+     CHECK_CURSOR_NOT_CLOSED(self);
+@@ -4509,7 +4763,7 @@
+     err = _DBC_get(self->dbc, &key, &data, flags|DB_SET_RECNO);
+     MYDB_END_ALLOW_THREADS;
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->mydb->moduleFlags.cursorSetReturnsNone) {
++	    && self->mydb->moduleFlags.cursorSetReturnsNone) {
+         Py_INCREF(Py_None);
+         retval = Py_None;
+     }
+@@ -4579,7 +4833,7 @@
+     err = _DBC_get(self->dbc, &key, &data, flags | DB_JOIN_ITEM);
+     MYDB_END_ALLOW_THREADS;
+     if ((err == DB_NOTFOUND || err == DB_KEYEMPTY)
+-            && self->mydb->moduleFlags.getReturnsNone) {
++	    && self->mydb->moduleFlags.getReturnsNone) {
+         Py_INCREF(Py_None);
+         retval = Py_None;
+     }
+@@ -4602,7 +4856,7 @@
+     static char* kwnames[] = { "priority", NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:set_priority", kwnames,
+-                                     &priority))
++				     &priority))
+         return NULL;
+ 
+     CHECK_CURSOR_NOT_CLOSED(self);
+@@ -4656,6 +4910,12 @@
+             dummy = DBLogCursor_close_internal(self->children_logcursors);
+             Py_XDECREF(dummy);
+         }
++#if (DBVER >= 52)
++        while(self->children_sites) {
++            dummy = DBSite_close_internal(self->children_sites);
++            Py_XDECREF(dummy);
++        }
++#endif
+     }
+ 
+     self->closed = 1;
+@@ -4735,17 +4995,16 @@
+ #define MAKE_ENTRY(name)  _addIntToDict(d, #name, gsp->st_##name)
+ 
+     MAKE_ENTRY(gbytes);
++    MAKE_ENTRY(bytes);
+     MAKE_ENTRY(ncache);
+ #if (DBVER >= 46)
+     MAKE_ENTRY(max_ncache);
+ #endif
+     MAKE_ENTRY(regsize);
+-#if (DBVER >= 43)
+     MAKE_ENTRY(mmapsize);
+     MAKE_ENTRY(maxopenfd);
+     MAKE_ENTRY(maxwrite);
+     MAKE_ENTRY(maxwrite_sleep);
+-#endif
+     MAKE_ENTRY(map);
+     MAKE_ENTRY(cache_hit);
+     MAKE_ENTRY(cache_miss);
+@@ -4828,13 +5087,12 @@
+ #undef MAKE_ENTRY
+     free(fsp);
+ 
+-    r = Py_BuildValue("(OO)", d, d2);
++    r = PyTuple_Pack(2, d, d2);
+     Py_DECREF(d);
+     Py_DECREF(d2);
+     return r;
+ }
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DBEnv_memp_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs)
+ {
+@@ -4854,7 +5112,6 @@
+     RETURN_IF_ERR();
+     RETURN_NONE();
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -4921,8 +5178,8 @@
+                                      NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zOi:dbremove", kwnames,
+-                &file, &database, &txnobj, &flags)) {
+-        return NULL;
++		&file, &database, &txnobj, &flags)) {
++	return NULL;
+     }
+     if (!checkTxnObj(txnobj, &txn)) {
+         return NULL;
+@@ -4949,8 +5206,8 @@
+                                      "flags", NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "szs|Oi:dbrename", kwnames,
+-                &file, &database, &newname, &txnobj, &flags)) {
+-        return NULL;
++		&file, &database, &newname, &txnobj, &flags)) {
++	return NULL;
+     }
+     if (!checkTxnObj(txnobj, &txn)) {
+         return NULL;
+@@ -4975,8 +5232,8 @@
+     static char* kwnames[] = { "passwd", "flags", NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|i:set_encrypt", kwnames,
+-                &passwd, &flags)) {
+-        return NULL;
++		&passwd, &flags)) {
++	return NULL;
+     }
+ 
+     MYDB_BEGIN_ALLOW_THREADS;
+@@ -4987,7 +5244,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_encrypt_flags(DBEnvObject* self)
+ {
+@@ -5025,7 +5281,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(timeout);
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -5037,8 +5292,8 @@
+     static char* kwnames[] = { "timeout", "flags", NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:set_timeout", kwnames,
+-                &timeout, &flags)) {
+-        return NULL;
++		&timeout, &flags)) {
++	return NULL;
+     }
+ 
+     MYDB_BEGIN_ALLOW_THREADS;
+@@ -5064,7 +5319,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_shm_key(DBEnvObject* self)
+ {
+@@ -5081,7 +5335,6 @@
+ 
+     return NUMBER_FromLong(shm_key);
+ }
+-#endif
+ 
+ #if (DBVER >= 46)
+ static PyObject*
+@@ -5170,7 +5423,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_cachesize(DBEnvObject* self)
+ {
+@@ -5188,7 +5440,6 @@
+ 
+     return Py_BuildValue("(iii)", gbytes, bytes, ncache);
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -5208,7 +5459,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_flags(DBEnvObject* self)
+ {
+@@ -5223,7 +5473,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(flags);
+ }
+-#endif
+ 
+ #if (DBVER >= 47)
+ static PyObject*
+@@ -5423,7 +5672,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_data_dirs(DBEnvObject* self)
+ {
+@@ -5463,7 +5711,6 @@
+     }
+     return tuple;
+ }
+-#endif
+ 
+ #if (DBVER >= 44)
+ static PyObject*
+@@ -5513,7 +5760,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_lg_bsize(DBEnvObject* self)
+ {
+@@ -5528,7 +5774,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(lg_bsize);
+ }
+-#endif
+ 
+ static PyObject*
+ DBEnv_set_lg_dir(DBEnvObject* self, PyObject* args)
+@@ -5547,7 +5792,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_lg_dir(DBEnvObject* self)
+ {
+@@ -5562,7 +5806,6 @@
+     RETURN_IF_ERR();
+     return PyBytes_FromString(dirp);
+ }
+-#endif
+ 
+ static PyObject*
+ DBEnv_set_lg_max(DBEnvObject* self, PyObject* args)
+@@ -5580,7 +5823,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_lg_max(DBEnvObject* self)
+ {
+@@ -5595,8 +5837,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(lg_max);
+ }
+-#endif
+-
+ 
+ static PyObject*
+ DBEnv_set_lg_regionmax(DBEnvObject* self, PyObject* args)
+@@ -5614,7 +5854,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_lg_regionmax(DBEnvObject* self)
+ {
+@@ -5629,7 +5868,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(lg_regionmax);
+ }
+-#endif
+ 
+ #if (DBVER >= 47)
+ static PyObject*
+@@ -5680,7 +5918,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_lk_detect(DBEnvObject* self)
+ {
+@@ -5695,8 +5932,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(lk_detect);
+ }
+-#endif
+-
+ 
+ #if (DBVER < 45)
+ static PyObject*
+@@ -5734,7 +5969,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_lk_max_locks(DBEnvObject* self)
+ {
+@@ -5749,7 +5983,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(lk_max);
+ }
+-#endif
+ 
+ static PyObject*
+ DBEnv_set_lk_max_lockers(DBEnvObject* self, PyObject* args)
+@@ -5767,7 +6000,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_lk_max_lockers(DBEnvObject* self)
+ {
+@@ -5782,7 +6014,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(lk_max);
+ }
+-#endif
+ 
+ static PyObject*
+ DBEnv_set_lk_max_objects(DBEnvObject* self, PyObject* args)
+@@ -5800,7 +6031,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_lk_max_objects(DBEnvObject* self)
+ {
+@@ -5815,9 +6045,7 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(lk_max);
+ }
+-#endif
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_mp_mmapsize(DBEnvObject* self)
+ {
+@@ -5832,8 +6060,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(mmapsize);
+ }
+-#endif
+-
+ 
+ static PyObject*
+ DBEnv_set_mp_mmapsize(DBEnvObject* self, PyObject* args)
+@@ -5869,8 +6095,6 @@
+     RETURN_NONE();
+ }
+ 
+-
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_tmp_dir(DBEnvObject* self)
+ {
+@@ -5887,8 +6111,6 @@
+ 
+     return PyBytes_FromString(dirpp);
+ }
+-#endif
+-
+ 
+ static PyObject*
+ DBEnv_txn_recover(DBEnvObject* self)
+@@ -5899,7 +6121,7 @@
+     DBTxnObject *txn;
+ #define PREPLIST_LEN 16
+     DB_PREPLIST preplist[PREPLIST_LEN];
+-#if (DBVER < 48)
++#if (DBVER < 48) || (DBVER >= 52)
+     long retp;
+ #else
+     u_int32_t retp;
+@@ -6003,8 +6225,6 @@
+     RETURN_NONE();
+ }
+ 
+-
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_tx_max(DBEnvObject* self)
+ {
+@@ -6019,8 +6239,6 @@
+     RETURN_IF_ERR();
+     return PyLong_FromUnsignedLong(max);
+ }
+-#endif
+-
+ 
+ static PyObject*
+ DBEnv_set_tx_max(DBEnvObject* self, PyObject* args)
+@@ -6038,8 +6256,6 @@
+     RETURN_NONE();
+ }
+ 
+-
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_tx_timestamp(DBEnvObject* self)
+ {
+@@ -6054,7 +6270,6 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(timestamp);
+ }
+-#endif
+ 
+ static PyObject*
+ DBEnv_set_tx_timestamp(DBEnvObject* self, PyObject* args)
+@@ -6204,7 +6419,6 @@
+ #endif /* DBVER >= 4.4 */
+ 
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DBEnv_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs)
+ {
+@@ -6224,7 +6438,6 @@
+     RETURN_IF_ERR();
+     RETURN_NONE();
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -6288,7 +6501,6 @@
+ } /* DBEnv_log_stat */
+ 
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DBEnv_log_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs)
+ {
+@@ -6308,7 +6520,6 @@
+     RETURN_IF_ERR();
+     RETURN_NONE();
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -6390,7 +6601,6 @@
+     return d;
+ }
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DBEnv_lock_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs)
+ {
+@@ -6410,7 +6620,6 @@
+     RETURN_IF_ERR();
+     RETURN_NONE();
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -6572,6 +6781,52 @@
+ }
+ 
+ 
++#if (DBVER >= 52)
++static PyObject*
++DBEnv_repmgr_site(DBEnvObject* self, PyObject* args, PyObject *kwargs)
++{
++    int err;
++    DB_SITE* site;
++    char *host;
++    u_int port;
++    static char* kwnames[] = {"host", "port", NULL};
++
++    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si:repmgr_site", kwnames,
++                                     &host, &port))
++        return NULL;
++
++    CHECK_ENV_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db_env->repmgr_site(self->db_env, host, port, &site, 0);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++    return (PyObject*) newDBSiteObject(site, self);
++}
++
++static PyObject*
++DBEnv_repmgr_site_by_eid(DBEnvObject* self, PyObject* args, PyObject *kwargs)
++{
++    int err;
++    DB_SITE* site;
++    int eid;
++    static char* kwnames[] = {"eid", NULL};
++
++    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:repmgr_site_by_eid",
++                kwnames, &eid))
++        return NULL;
++
++    CHECK_ENV_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db_env->repmgr_site_by_eid(self->db_env, eid, &site);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++    return (PyObject*) newDBSiteObject(site, self);
++}
++#endif
++
++
+ #if (DBVER >= 44)
+ static PyObject*
+ DBEnv_mutex_stat(DBEnvObject* self, PyObject* args)
+@@ -6640,7 +6895,6 @@
+ #endif
+ 
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DBEnv_txn_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs)
+ {
+@@ -6662,7 +6916,6 @@
+     RETURN_IF_ERR();
+     RETURN_NONE();
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -6756,6 +7009,76 @@
+     RETURN_NONE();
+ }
+ 
++#if (DBVER >= 47)
++static PyObject*
++DBEnv_set_intermediate_dir_mode(DBEnvObject* self, PyObject* args)
++{
++    int err;
++    const char *mode;
++
++    if (!PyArg_ParseTuple(args,"s:set_intermediate_dir_mode", &mode))
++        return NULL;
++
++    CHECK_ENV_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db_env->set_intermediate_dir_mode(self->db_env, mode);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++    RETURN_NONE();
++}
++
++static PyObject*
++DBEnv_get_intermediate_dir_mode(DBEnvObject* self)
++{
++    int err;
++    const char *mode;
++
++    CHECK_ENV_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db_env->get_intermediate_dir_mode(self->db_env, &mode);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++    return Py_BuildValue("s", mode);
++}
++#endif
++
++#if (DBVER < 47)
++static PyObject*
++DBEnv_set_intermediate_dir(DBEnvObject* self, PyObject* args)
++{
++    int err;
++    int mode;
++    u_int32_t flags;
++
++    if (!PyArg_ParseTuple(args, "iI:set_intermediate_dir", &mode, &flags))
++        return NULL;
++
++    CHECK_ENV_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db_env->set_intermediate_dir(self->db_env, mode, flags);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++    RETURN_NONE();
++}
++#endif
++
++static PyObject*
++DBEnv_get_open_flags(DBEnvObject* self)
++{
++    int err;
++    unsigned int flags;
++
++    CHECK_ENV_NOT_CLOSED(self);
++
++    MYDB_BEGIN_ALLOW_THREADS;
++    err = self->db_env->get_open_flags(self->db_env, &flags);
++    MYDB_END_ALLOW_THREADS;
++    RETURN_IF_ERR();
++    return NUMBER_FromLong(flags);
++}
+ 
+ #if (DBVER < 48)
+ static PyObject*
+@@ -6781,7 +7104,6 @@
+ }
+ #endif
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DBEnv_set_mp_max_openfd(DBEnvObject* self, PyObject* args)
+ {
+@@ -6855,7 +7177,6 @@
+ 
+     return Py_BuildValue("(ii)", maxwrite, (int)maxwrite_sleep);
+ }
+-#endif
+ 
+ 
+ static PyObject*
+@@ -6875,7 +7196,6 @@
+     RETURN_NONE();
+ }
+ 
+-#if (DBVER >= 42)
+ static PyObject*
+ DBEnv_get_verbose(DBEnvObject* self, PyObject* args)
+ {
+@@ -6893,7 +7213,6 @@
+     RETURN_IF_ERR();
+     return PyBool_FromLong(verbose);
+ }
+-#endif
+ 
+ #if (DBVER >= 45)
+ static void
+@@ -6935,8 +7254,8 @@
+     CHECK_ENV_NOT_CLOSED(self);
+ 
+     if (!PyCallable_Check(notifyFunc)) {
+-            makeTypeError("Callable", notifyFunc);
+-            return NULL;
++	    makeTypeError("Callable", notifyFunc);
++	    return NULL;
+     }
+ 
+     Py_XDECREF(self->event_notifyCallback);
+@@ -6954,8 +7273,8 @@
+     MYDB_END_ALLOW_THREADS;
+ 
+     if (err) {
+-            Py_DECREF(notifyFunc);
+-            self->event_notifyCallback = NULL;
++	    Py_DECREF(notifyFunc);
++	    self->event_notifyCallback = NULL;
+     }
+ 
+     RETURN_IF_ERR();
+@@ -6975,9 +7294,7 @@
+     PyObject *control_py, *rec_py;
+     DBT control, rec;
+     int envid;
+-#if (DBVER >= 42)
+     DB_LSN lsn;
+-#endif
+ 
+     if (!PyArg_ParseTuple(args, "OOi:rep_process_message", &control_py,
+                 &rec_py, &envid))
+@@ -6994,13 +7311,8 @@
+     err = self->db_env->rep_process_message(self->db_env, &control, &rec,
+             envid, &lsn);
+ #else
+-#if (DBVER >= 42)
+     err = self->db_env->rep_process_message(self->db_env, &control, &rec,
+             &envid, &lsn);
+-#else
+-    err = self->db_env->rep_process_message(self->db_env, &control, &rec,
+-            &envid);
+-#endif
+ #endif
+     MYDB_END_ALLOW_THREADS;
+     switch (err) {
+@@ -7029,15 +7341,13 @@
+                 return r;
+                 break;
+             }
+-#if (DBVER >= 42)
+         case DB_REP_NOTPERM :
+         case DB_REP_ISPERM :
+             return Py_BuildValue("(i(ll))", err, lsn.file, lsn.offset);
+             break;
+-#endif
+     }
+     RETURN_IF_ERR();
+-    return Py_BuildValue("(OO)", Py_None, Py_None);
++    return PyTuple_Pack(2, Py_None, Py_None);
+ }
+ 
+ static int
+@@ -7062,11 +7372,7 @@
+     b = PyBytes_FromStringAndSize(rec->data, rec->size);
+ 
+     args = Py_BuildValue(
+-#if (PY_VERSION_HEX >= 0x02040000)
+             "(OOO(ll)iI)",
+-#else
+-            "(OOO(ll)ii)",
+-#endif
+             dbenv,
+             a, b,
+             lsn->file, lsn->offset, envid, flags);
+@@ -7086,20 +7392,6 @@
+     return ret;
+ }
+ 
+-#if (DBVER <= 41)
+-static int
+-_DBEnv_rep_transportCallbackOLD(DB_ENV* db_env, const DBT* control, const DBT* rec,
+-        int envid, u_int32_t flags)
+-{
+-    DB_LSN lsn;
+-
+-    lsn.file = -1;  /* Dummy values */
+-    lsn.offset = -1;
+-    return _DBEnv_rep_transportCallback(db_env, control, rec, &lsn, envid,
+-            flags);
+-}
+-#endif
+-
+ static PyObject*
+ DBEnv_rep_set_transport(DBEnvObject* self, PyObject* args)
+ {
+@@ -7120,13 +7412,8 @@
+     err = self->db_env->rep_set_transport(self->db_env, envid,
+             &_DBEnv_rep_transportCallback);
+ #else
+-#if (DBVER >= 42)
+     err = self->db_env->set_rep_transport(self->db_env, envid,
+             &_DBEnv_rep_transportCallback);
+-#else
+-    err = self->db_env->set_rep_transport(self->db_env, envid,
+-            &_DBEnv_rep_transportCallbackOLD);
+-#endif
+ #endif
+     MYDB_END_ALLOW_THREADS;
+     RETURN_IF_ERR();
+@@ -7166,11 +7453,7 @@
+     err = self->db_env->rep_get_request(self->db_env, &minimum, &maximum);
+     MYDB_END_ALLOW_THREADS;
+     RETURN_IF_ERR();
+-#if (PY_VERSION_HEX >= 0x02040000)
+     return Py_BuildValue("II", minimum, maximum);
+-#else
+-    return Py_BuildValue("ii", minimum, maximum);
+-#endif
+ }
+ #endif
+ 
+@@ -7257,7 +7540,7 @@
+     }
+     CHECK_ENV_NOT_CLOSED(self);
+     MYDB_BEGIN_ALLOW_THREADS;
+-    err = self->db_env->rep_elect(self->db_env, nsites, nvotes, 0);
++    err = self->db_env->rep_elect(self->db_env, nvotes, nvotes, 0);
+     MYDB_END_ALLOW_THREADS;
+     RETURN_IF_ERR();
+     RETURN_NONE();
+@@ -7276,7 +7559,7 @@
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                 "i|O:rep_start", kwnames, &flags, &cdata_py))
+     {
+-            return NULL;
++	    return NULL;
+     }
+     CHECK_ENV_NOT_CLOSED(self);
+ 
+@@ -7422,13 +7705,8 @@
+     int err;
+     unsigned int fast, slow;
+ 
+-#if (PY_VERSION_HEX >= 0x02040000)
+     if (!PyArg_ParseTuple(args,"II:rep_set_clockskew", &fast, &slow))
+         return NULL;
+-#else
+-    if (!PyArg_ParseTuple(args,"ii:rep_set_clockskew", &fast, &slow))
+-        return NULL;
+-#endif
+ 
+     CHECK_ENV_NOT_CLOSED(self);
+ 
+@@ -7450,15 +7728,10 @@
+     err = self->db_env->rep_get_clockskew(self->db_env, &fast, &slow);
+     MYDB_END_ALLOW_THREADS;
+     RETURN_IF_ERR();
+-#if (PY_VERSION_HEX >= 0x02040000)
+     return Py_BuildValue("(II)", fast, slow);
+-#else
+-    return Py_BuildValue("(ii)", fast, slow);
+-#endif
+ }
+ #endif
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DBEnv_rep_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs)
+ {
+@@ -7478,7 +7751,6 @@
+     RETURN_IF_ERR();
+     RETURN_NONE();
+ }
+-#endif
+ 
+ static PyObject*
+ DBEnv_rep_stat(DBEnvObject* self, PyObject* args, PyObject *kwargs)
+@@ -7519,7 +7791,6 @@
+     MAKE_ENTRY(client_svc_req);
+ #endif
+     MAKE_ENTRY(dupmasters);
+-#if (DBVER >= 43)
+     MAKE_ENTRY(egen);
+     MAKE_ENTRY(election_nvotes);
+     MAKE_ENTRY(startup_complete);
+@@ -7528,7 +7799,6 @@
+     MAKE_ENTRY(pg_requested);
+     MAKE_ENTRY(next_pg);
+     MAKE_ENTRY(waiting_pg);
+-#endif
+     MAKE_ENTRY(election_cur_winner);
+     MAKE_ENTRY(election_gen);
+     MAKE_DB_LSN_ENTRY(election_lsn);
+@@ -7598,7 +7868,7 @@
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                 "ii:repmgr_start", kwnames, &nthreads, &flags))
+     {
+-            return NULL;
++	    return NULL;
+     }
+     CHECK_ENV_NOT_CLOSED(self);
+     MYDB_BEGIN_ALLOW_THREADS;
+@@ -7608,6 +7878,7 @@
+     RETURN_NONE();
+ }
+ 
++#if (DBVER < 52)
+ static PyObject*
+ DBEnv_repmgr_set_local_site(DBEnvObject* self, PyObject* args, PyObject*
+         kwargs)
+@@ -7621,7 +7892,7 @@
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                 "si|i:repmgr_set_local_site", kwnames, &host, &port, &flags))
+     {
+-            return NULL;
++	    return NULL;
+     }
+     CHECK_ENV_NOT_CLOSED(self);
+     MYDB_BEGIN_ALLOW_THREADS;
+@@ -7645,7 +7916,7 @@
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                 "si|i:repmgr_add_remote_site", kwnames, &host, &port, &flags))
+     {
+-            return NULL;
++	    return NULL;
+     }
+     CHECK_ENV_NOT_CLOSED(self);
+     MYDB_BEGIN_ALLOW_THREADS;
+@@ -7654,6 +7925,7 @@
+     RETURN_IF_ERR();
+     return NUMBER_FromLong(eidp);
+ }
++#endif
+ 
+ static PyObject*
+ DBEnv_repmgr_set_ack_policy(DBEnvObject* self, PyObject* args)
+@@ -7663,7 +7935,7 @@
+ 
+     if (!PyArg_ParseTuple(args, "i:repmgr_set_ack_policy", &ack_policy))
+     {
+-            return NULL;
++	    return NULL;
+     }
+     CHECK_ENV_NOT_CLOSED(self);
+     MYDB_BEGIN_ALLOW_THREADS;
+@@ -7714,13 +7986,8 @@
+             free(listp);
+             return NULL;
+         }
+-#if (PY_VERSION_HEX >= 0x02040000)
+         tuple=Py_BuildValue("(sII)", listp[countp].host,
+                 listp[countp].port, listp[countp].status);
+-#else
+-        tuple=Py_BuildValue("(sii)", listp[countp].host,
+-                listp[countp].port, listp[countp].status);
+-#endif
+         if(!tuple) {
+             Py_DECREF(key);
+             Py_DECREF(stats);
+@@ -7824,9 +8091,7 @@
+ static void _promote_transaction_dbs_and_sequences(DBTxnObject *txn)
+ {
+     DBObject *db;
+-#if (DBVER >= 43)
+     DBSequenceObject *dbs;
+-#endif
+ 
+     while (txn->children_dbs) {
+         db=txn->children_dbs;
+@@ -7842,7 +8107,6 @@
+         }
+     }
+ 
+-#if (DBVER >= 43)
+     while (txn->children_sequences) {
+         dbs=txn->children_sequences;
+         EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(dbs);
+@@ -7856,7 +8120,6 @@
+             dbs->txn=NULL;
+         }
+     }
+-#endif
+ }
+ 
+ 
+@@ -7953,12 +8216,10 @@
+     self->txn = NULL;   /* this DB_TXN is no longer valid after this call */
+ 
+     _close_transaction_cursors(self);
+-#if (DBVER >= 43)
+     while (self->children_sequences) {
+         dummy=DBSequence_close_internal(self->children_sequences,0,0);
+         Py_XDECREF(dummy);
+     }
+-#endif
+     while (self->children_dbs) {
+         dummy=DB_close_internal(self->children_dbs, 0, 0);
+         Py_XDECREF(dummy);
+@@ -8034,8 +8295,8 @@
+     static char* kwnames[] = { "timeout", "flags", NULL };
+ 
+     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:set_timeout", kwnames,
+-                &timeout, &flags)) {
+-        return NULL;
++		&timeout, &flags)) {
++	return NULL;
+     }
+ 
+     MYDB_BEGIN_ALLOW_THREADS;
+@@ -8094,7 +8355,6 @@
+ #endif
+ 
+ 
+-#if (DBVER >= 43)
+ /* --------------------------------------------------------------------- */
+ /* DBSequence methods */
+ 
+@@ -8444,7 +8704,6 @@
+     free(sp);
+     return dict_stat;
+ }
+-#endif
+ 
+ 
+ /* --------------------------------------------------------------------- */
+@@ -8482,70 +8741,45 @@
+     {"remove",          (PyCFunction)DB_remove,         METH_VARARGS|METH_KEYWORDS},
+     {"rename",          (PyCFunction)DB_rename,         METH_VARARGS},
+     {"set_bt_minkey",   (PyCFunction)DB_set_bt_minkey,  METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_bt_minkey",   (PyCFunction)DB_get_bt_minkey,  METH_NOARGS},
+-#endif
+     {"set_bt_compare",  (PyCFunction)DB_set_bt_compare, METH_O},
+     {"set_cachesize",   (PyCFunction)DB_set_cachesize,  METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_cachesize",   (PyCFunction)DB_get_cachesize,  METH_NOARGS},
+-#endif
++    {"set_dup_compare", (PyCFunction)DB_set_dup_compare, METH_O},
+     {"set_encrypt",     (PyCFunction)DB_set_encrypt,    METH_VARARGS|METH_KEYWORDS},
+-#if (DBVER >= 42)
+     {"get_encrypt_flags", (PyCFunction)DB_get_encrypt_flags, METH_NOARGS},
+-#endif
+-
+     {"set_flags",       (PyCFunction)DB_set_flags,      METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_flags",       (PyCFunction)DB_get_flags,      METH_NOARGS},
+-#endif
++    {"get_transactional", (PyCFunction)DB_get_transactional, METH_NOARGS},
+     {"set_h_ffactor",   (PyCFunction)DB_set_h_ffactor,  METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_h_ffactor",   (PyCFunction)DB_get_h_ffactor,  METH_NOARGS},
+-#endif
+     {"set_h_nelem",     (PyCFunction)DB_set_h_nelem,    METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_h_nelem",     (PyCFunction)DB_get_h_nelem,    METH_NOARGS},
+-#endif
+     {"set_lorder",      (PyCFunction)DB_set_lorder,     METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lorder",      (PyCFunction)DB_get_lorder,     METH_NOARGS},
+-#endif
+     {"set_pagesize",    (PyCFunction)DB_set_pagesize,   METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_pagesize",    (PyCFunction)DB_get_pagesize,   METH_NOARGS},
+-#endif
+     {"set_re_delim",    (PyCFunction)DB_set_re_delim,   METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_re_delim",    (PyCFunction)DB_get_re_delim,   METH_NOARGS},
+-#endif
+     {"set_re_len",      (PyCFunction)DB_set_re_len,     METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_re_len",      (PyCFunction)DB_get_re_len,     METH_NOARGS},
+-#endif
+     {"set_re_pad",      (PyCFunction)DB_set_re_pad,     METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_re_pad",      (PyCFunction)DB_get_re_pad,     METH_NOARGS},
+-#endif
+     {"set_re_source",   (PyCFunction)DB_set_re_source,  METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_re_source",   (PyCFunction)DB_get_re_source,  METH_NOARGS},
+-#endif
+     {"set_q_extentsize",(PyCFunction)DB_set_q_extentsize, METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_q_extentsize",(PyCFunction)DB_get_q_extentsize, METH_NOARGS},
+-#endif
+     {"set_private",     (PyCFunction)DB_set_private,    METH_O},
+     {"get_private",     (PyCFunction)DB_get_private,    METH_NOARGS},
+ #if (DBVER >= 46)
+     {"set_priority",    (PyCFunction)DB_set_priority,   METH_VARARGS},
+     {"get_priority",    (PyCFunction)DB_get_priority,   METH_NOARGS},
+ #endif
++    {"get_dbname",      (PyCFunction)DB_get_dbname,     METH_NOARGS},
++    {"get_open_flags",  (PyCFunction)DB_get_open_flags, METH_NOARGS},
+     {"stat",            (PyCFunction)DB_stat,           METH_VARARGS|METH_KEYWORDS},
+-#if (DBVER >= 43)
+     {"stat_print",      (PyCFunction)DB_stat_print,
+         METH_VARARGS|METH_KEYWORDS},
+-#endif
+     {"sync",            (PyCFunction)DB_sync,           METH_VARARGS},
+     {"truncate",        (PyCFunction)DB_truncate,       METH_VARARGS|METH_KEYWORDS},
+     {"type",            (PyCFunction)DB_get_type,       METH_NOARGS},
+@@ -8627,6 +8861,19 @@
+     {NULL,      NULL}       /* sentinel */
+ };
+ 
++#if (DBVER >= 52)
++static PyMethodDef DBSite_methods[] = {
++    {"get_config",  (PyCFunction)DBSite_get_config,
++        METH_VARARGS | METH_KEYWORDS},
++    {"set_config",  (PyCFunction)DBSite_set_config,
++        METH_VARARGS | METH_KEYWORDS},
++    {"remove",      (PyCFunction)DBSite_remove,     METH_NOARGS},
++    {"get_eid",     (PyCFunction)DBSite_get_eid,    METH_NOARGS},
++    {"get_address", (PyCFunction)DBSite_get_address,    METH_NOARGS},
++    {"close",       (PyCFunction)DBSite_close,      METH_NOARGS},
++    {NULL,      NULL}       /* sentinel */
++};
++#endif
+ 
+ static PyMethodDef DBEnv_methods[] = {
+     {"close",           (PyCFunction)DBEnv_close,            METH_VARARGS},
+@@ -8639,32 +8886,24 @@
+     {"get_thread_count", (PyCFunction)DBEnv_get_thread_count, METH_NOARGS},
+ #endif
+     {"set_encrypt",     (PyCFunction)DBEnv_set_encrypt,      METH_VARARGS|METH_KEYWORDS},
+-#if (DBVER >= 42)
+     {"get_encrypt_flags", (PyCFunction)DBEnv_get_encrypt_flags, METH_NOARGS},
+     {"get_timeout",     (PyCFunction)DBEnv_get_timeout,
+         METH_VARARGS|METH_KEYWORDS},
+-#endif
+     {"set_timeout",     (PyCFunction)DBEnv_set_timeout,     METH_VARARGS|METH_KEYWORDS},
+     {"set_shm_key",     (PyCFunction)DBEnv_set_shm_key,     METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_shm_key",     (PyCFunction)DBEnv_get_shm_key,     METH_NOARGS},
+-#endif
+ #if (DBVER >= 46)
+     {"set_cache_max",   (PyCFunction)DBEnv_set_cache_max,   METH_VARARGS},
+     {"get_cache_max",   (PyCFunction)DBEnv_get_cache_max,   METH_NOARGS},
+ #endif
+     {"set_cachesize",   (PyCFunction)DBEnv_set_cachesize,   METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_cachesize",   (PyCFunction)DBEnv_get_cachesize,   METH_NOARGS},
+-#endif
+     {"memp_trickle",    (PyCFunction)DBEnv_memp_trickle,    METH_VARARGS},
+     {"memp_sync",       (PyCFunction)DBEnv_memp_sync,       METH_VARARGS},
+     {"memp_stat",       (PyCFunction)DBEnv_memp_stat,
+         METH_VARARGS|METH_KEYWORDS},
+-#if (DBVER >= 43)
+     {"memp_stat_print", (PyCFunction)DBEnv_memp_stat_print,
+         METH_VARARGS|METH_KEYWORDS},
+-#endif
+ #if (DBVER >= 44)
+     {"mutex_set_max",   (PyCFunction)DBEnv_mutex_set_max,   METH_VARARGS},
+     {"mutex_get_max",   (PyCFunction)DBEnv_mutex_get_max,   METH_NOARGS},
+@@ -8685,33 +8924,21 @@
+ #endif
+ #endif
+     {"set_data_dir",    (PyCFunction)DBEnv_set_data_dir,    METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_data_dirs",   (PyCFunction)DBEnv_get_data_dirs,   METH_NOARGS},
+-#endif
+-#if (DBVER >= 42)
+     {"get_flags",       (PyCFunction)DBEnv_get_flags,       METH_NOARGS},
+-#endif
+     {"set_flags",       (PyCFunction)DBEnv_set_flags,       METH_VARARGS},
+ #if (DBVER >= 47)
+     {"log_set_config",  (PyCFunction)DBEnv_log_set_config,  METH_VARARGS},
+     {"log_get_config",  (PyCFunction)DBEnv_log_get_config,  METH_VARARGS},
+ #endif
+     {"set_lg_bsize",    (PyCFunction)DBEnv_set_lg_bsize,    METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lg_bsize",    (PyCFunction)DBEnv_get_lg_bsize,    METH_NOARGS},
+-#endif
+     {"set_lg_dir",      (PyCFunction)DBEnv_set_lg_dir,      METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lg_dir",      (PyCFunction)DBEnv_get_lg_dir,      METH_NOARGS},
+-#endif
+     {"set_lg_max",      (PyCFunction)DBEnv_set_lg_max,      METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lg_max",      (PyCFunction)DBEnv_get_lg_max,      METH_NOARGS},
+-#endif
+     {"set_lg_regionmax",(PyCFunction)DBEnv_set_lg_regionmax, METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lg_regionmax",(PyCFunction)DBEnv_get_lg_regionmax, METH_NOARGS},
+-#endif
+ #if (DBVER >= 44)
+     {"set_lg_filemode", (PyCFunction)DBEnv_set_lg_filemode, METH_VARARGS},
+     {"get_lg_filemode", (PyCFunction)DBEnv_get_lg_filemode, METH_NOARGS},
+@@ -8721,47 +8948,29 @@
+     {"get_lk_partitions", (PyCFunction)DBEnv_get_lk_partitions, METH_NOARGS},
+ #endif
+     {"set_lk_detect",   (PyCFunction)DBEnv_set_lk_detect,   METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lk_detect",   (PyCFunction)DBEnv_get_lk_detect,   METH_NOARGS},
+-#endif
+ #if (DBVER < 45)
+     {"set_lk_max",      (PyCFunction)DBEnv_set_lk_max,      METH_VARARGS},
+ #endif
+     {"set_lk_max_locks", (PyCFunction)DBEnv_set_lk_max_locks, METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lk_max_locks", (PyCFunction)DBEnv_get_lk_max_locks, METH_NOARGS},
+-#endif
+     {"set_lk_max_lockers", (PyCFunction)DBEnv_set_lk_max_lockers, METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lk_max_lockers", (PyCFunction)DBEnv_get_lk_max_lockers, METH_NOARGS},
+-#endif
+     {"set_lk_max_objects", (PyCFunction)DBEnv_set_lk_max_objects, METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_lk_max_objects", (PyCFunction)DBEnv_get_lk_max_objects, METH_NOARGS},
+-#endif
+-#if (DBVER >= 43)
+     {"stat_print",          (PyCFunction)DBEnv_stat_print,
+         METH_VARARGS|METH_KEYWORDS},
+-#endif
+     {"set_mp_mmapsize", (PyCFunction)DBEnv_set_mp_mmapsize, METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_mp_mmapsize", (PyCFunction)DBEnv_get_mp_mmapsize, METH_NOARGS},
+-#endif
+     {"set_tmp_dir",     (PyCFunction)DBEnv_set_tmp_dir,     METH_VARARGS},
+-#if (DBVER >= 42)
+     {"get_tmp_dir",     (PyCFunction)DBEnv_get_tmp_dir,     METH_NOARGS},
+-#endif
+     {"txn_begin",       (PyCFunction)DBEnv_txn_begin,       METH_VARARGS|METH_KEYWORDS},
+     {"txn_checkpoint",  (PyCFunction)DBEnv_txn_checkpoint,  METH_VARARGS},
+     {"txn_stat",        (PyCFunction)DBEnv_txn_stat,        METH_VARARGS},
+-#if (DBVER >= 43)
+     {"txn_stat_print",  (PyCFunction)DBEnv_txn_stat_print,
+         METH_VARARGS|METH_KEYWORDS},
+-#endif
+-#if (DBVER >= 42)
+     {"get_tx_max",      (PyCFunction)DBEnv_get_tx_max,      METH_NOARGS},
+     {"get_tx_timestamp", (PyCFunction)DBEnv_get_tx_timestamp, METH_NOARGS},
+-#endif
+     {"set_tx_max",      (PyCFunction)DBEnv_set_tx_max,      METH_VARARGS},
+     {"set_tx_timestamp", (PyCFunction)DBEnv_set_tx_timestamp, METH_VARARGS},
+     {"lock_detect",     (PyCFunction)DBEnv_lock_detect,     METH_VARARGS},
+@@ -8770,10 +8979,8 @@
+     {"lock_id_free",    (PyCFunction)DBEnv_lock_id_free,    METH_VARARGS},
+     {"lock_put",        (PyCFunction)DBEnv_lock_put,        METH_VARARGS},
+     {"lock_stat",       (PyCFunction)DBEnv_lock_stat,       METH_VARARGS},
+-#if (DBVER >= 43)
+     {"lock_stat_print", (PyCFunction)DBEnv_lock_stat_print,
+         METH_VARARGS|METH_KEYWORDS},
+-#endif
+     {"log_cursor",      (PyCFunction)DBEnv_log_cursor,      METH_NOARGS},
+     {"log_file",        (PyCFunction)DBEnv_log_file,        METH_VARARGS},
+ #if (DBVER >= 44)
+@@ -8783,10 +8990,8 @@
+     {"log_archive",     (PyCFunction)DBEnv_log_archive,     METH_VARARGS},
+     {"log_flush",       (PyCFunction)DBEnv_log_flush,       METH_NOARGS},
+     {"log_stat",        (PyCFunction)DBEnv_log_stat,        METH_VARARGS},
+-#if (DBVER >= 43)
+     {"log_stat_print",  (PyCFunction)DBEnv_log_stat_print,
+         METH_VARARGS|METH_KEYWORDS},
+-#endif
+ #if (DBVER >= 44)
+     {"fileid_reset",    (PyCFunction)DBEnv_fileid_reset,    METH_VARARGS|METH_KEYWORDS},
+     {"lsn_reset",       (PyCFunction)DBEnv_lsn_reset,       METH_VARARGS|METH_KEYWORDS},
+@@ -8795,20 +9000,27 @@
+     {"txn_recover",     (PyCFunction)DBEnv_txn_recover,     METH_NOARGS},
+ #if (DBVER < 48)
+     {"set_rpc_server",  (PyCFunction)DBEnv_set_rpc_server,
+-        METH_VARARGS|METH_KEYWORDS},
++        METH_VARARGS||METH_KEYWORDS},
+ #endif
+-#if (DBVER >= 43)
+     {"set_mp_max_openfd", (PyCFunction)DBEnv_set_mp_max_openfd, METH_VARARGS},
+     {"get_mp_max_openfd", (PyCFunction)DBEnv_get_mp_max_openfd, METH_NOARGS},
+     {"set_mp_max_write", (PyCFunction)DBEnv_set_mp_max_write, METH_VARARGS},
+     {"get_mp_max_write", (PyCFunction)DBEnv_get_mp_max_write, METH_NOARGS},
+-#endif
+     {"set_verbose",     (PyCFunction)DBEnv_set_verbose,     METH_VARARGS},
+-#if (DBVER >= 42)
+-    {"get_verbose",     (PyCFunction)DBEnv_get_verbose,       METH_VARARGS},
++    {"get_verbose",     (PyCFunction)DBEnv_get_verbose,     METH_VARARGS},
++    {"set_private",     (PyCFunction)DBEnv_set_private,     METH_O},
++    {"get_private",     (PyCFunction)DBEnv_get_private,     METH_NOARGS},
++    {"get_open_flags",  (PyCFunction)DBEnv_get_open_flags,  METH_NOARGS},
++#if (DBVER >= 47)
++    {"set_intermediate_dir_mode", (PyCFunction)DBEnv_set_intermediate_dir_mode,
++        METH_VARARGS},
++    {"get_intermediate_dir_mode", (PyCFunction)DBEnv_get_intermediate_dir_mode,
++        METH_NOARGS},
++#endif
++#if (DBVER < 47)
++    {"set_intermediate_dir", (PyCFunction)DBEnv_set_intermediate_dir,
++        METH_VARARGS},
+ #endif
+-    {"set_private",     (PyCFunction)DBEnv_set_private,       METH_O},
+-    {"get_private",     (PyCFunction)DBEnv_get_private,       METH_NOARGS},
+     {"rep_start",       (PyCFunction)DBEnv_rep_start,
+         METH_VARARGS|METH_KEYWORDS},
+     {"rep_set_transport", (PyCFunction)DBEnv_rep_set_transport, METH_VARARGS},
+@@ -8847,18 +9059,18 @@
+ #endif
+     {"rep_stat", (PyCFunction)DBEnv_rep_stat,
+         METH_VARARGS|METH_KEYWORDS},
+-#if (DBVER >= 43)
+     {"rep_stat_print", (PyCFunction)DBEnv_rep_stat_print,
+         METH_VARARGS|METH_KEYWORDS},
+-#endif
+ 
+ #if (DBVER >= 45)
+     {"repmgr_start", (PyCFunction)DBEnv_repmgr_start,
+         METH_VARARGS|METH_KEYWORDS},
++#if (DBVER < 52)
+     {"repmgr_set_local_site", (PyCFunction)DBEnv_repmgr_set_local_site,
+         METH_VARARGS|METH_KEYWORDS},
+     {"repmgr_add_remote_site", (PyCFunction)DBEnv_repmgr_add_remote_site,
+         METH_VARARGS|METH_KEYWORDS},
++#endif
+     {"repmgr_set_ack_policy", (PyCFunction)DBEnv_repmgr_set_ack_policy,
+         METH_VARARGS},
+     {"repmgr_get_ack_policy", (PyCFunction)DBEnv_repmgr_get_ack_policy,
+@@ -8872,6 +9084,12 @@
+     {"repmgr_stat_print", (PyCFunction)DBEnv_repmgr_stat_print,
+         METH_VARARGS|METH_KEYWORDS},
+ #endif
++#if (DBVER >= 52)
++    {"repmgr_site", (PyCFunction)DBEnv_repmgr_site,
++        METH_VARARGS | METH_KEYWORDS},
++    {"repmgr_site_by_eid",  (PyCFunction)DBEnv_repmgr_site_by_eid,
++        METH_VARARGS | METH_KEYWORDS},
++#endif
+     {NULL,      NULL}       /* sentinel */
+ };
+ 
+@@ -8892,7 +9110,6 @@
+ };
+ 
+ 
+-#if (DBVER >= 43)
+ static PyMethodDef DBSequence_methods[] = {
+     {"close",           (PyCFunction)DBSequence_close,          METH_VARARGS},
+     {"get",             (PyCFunction)DBSequence_get,            METH_VARARGS|METH_KEYWORDS},
+@@ -8912,7 +9129,6 @@
+         METH_VARARGS|METH_KEYWORDS},
+     {NULL,      NULL}       /* sentinel */
+ };
+-#endif
+ 
+ 
+ static PyObject*
+@@ -8922,13 +9138,9 @@
+ 
+     CHECK_ENV_NOT_CLOSED(self);
+ 
+-#if (DBVER >= 42)
+     MYDB_BEGIN_ALLOW_THREADS;
+     self->db_env->get_home(self->db_env, &home);
+     MYDB_END_ALLOW_THREADS;
+-#else
+-    home=self->db_env->db_home;
+-#endif
+ 
+     if (home == NULL) {
+         RETURN_NONE();
+@@ -8963,20 +9175,20 @@
+     &DB_sequence,/*tp_as_sequence*/
+     &DB_mapping,/*tp_as_mapping*/
+     0,          /*tp_hash*/
+-    0,                  /* tp_call */
+-    0,                  /* tp_str */
+-    0,                  /* tp_getattro */
++    0,			/* tp_call */
++    0,			/* tp_str */
++    0,  		/* tp_getattro */
+     0,          /* tp_setattro */
+-    0,                  /* tp_as_buffer */
++    0,			/* tp_as_buffer */
+ #if (PY_VERSION_HEX < 0x03000000)
+     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
+ #else
+     Py_TPFLAGS_DEFAULT,      /* tp_flags */
+ #endif
+     0,          /* tp_doc */
+-    0,              /* tp_traverse */
+-    0,                  /* tp_clear */
+-    0,                  /* tp_richcompare */
++    0,		    /* tp_traverse */
++    0,			/* tp_clear */
++    0,			/* tp_richcompare */
+     offsetof(DBObject, in_weakreflist),   /* tp_weaklistoffset */
+     0,          /*tp_iter*/
+     0,          /*tp_iternext*/
+@@ -9070,6 +9282,49 @@
+     0,          /*tp_members*/
+ };
+ 
++#if (DBVER >= 52)
++statichere PyTypeObject DBSite_Type = {
++#if (PY_VERSION_HEX < 0x03000000)
++    PyObject_HEAD_INIT(NULL)
++    0,                  /*ob_size*/
++#else
++    PyVarObject_HEAD_INIT(NULL, 0)
++#endif
++    "DBSite",         /*tp_name*/
++    sizeof(DBSiteObject),  /*tp_basicsize*/
++    0,          /*tp_itemsize*/
++    /* methods */
++    (destructor)DBSite_dealloc,/*tp_dealloc*/
++    0,          /*tp_print*/
++    0,          /*tp_getattr*/
++    0,          /*tp_setattr*/
++    0,          /*tp_compare*/
++    0,          /*tp_repr*/
++    0,          /*tp_as_number*/
++    0,          /*tp_as_sequence*/
++    0,          /*tp_as_mapping*/
++    0,          /*tp_hash*/
++    0,          /*tp_call*/
++    0,          /*tp_str*/
++    0,          /*tp_getattro*/
++    0,          /*tp_setattro*/
++    0,          /*tp_as_buffer*/
++#if (PY_VERSION_HEX < 0x03000000)
++    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
++#else
++    Py_TPFLAGS_DEFAULT,      /* tp_flags */
++#endif
++    0,          /* tp_doc */
++    0,          /* tp_traverse */
++    0,          /* tp_clear */
++    0,          /* tp_richcompare */
++    offsetof(DBSiteObject, in_weakreflist),   /* tp_weaklistoffset */
++    0,          /*tp_iter*/
++    0,          /*tp_iternext*/
++    DBSite_methods, /*tp_methods*/
++    0,          /*tp_members*/
++};
++#endif
+ 
+ statichere PyTypeObject DBEnv_Type = {
+ #if (PY_VERSION_HEX < 0x03000000)
+@@ -9092,20 +9347,20 @@
+     0,          /*tp_as_sequence*/
+     0,          /*tp_as_mapping*/
+     0,          /*tp_hash*/
+-    0,                  /* tp_call */
+-    0,                  /* tp_str */
+-    0,                  /* tp_getattro */
++    0,			/* tp_call */
++    0,			/* tp_str */
++    0,  		/* tp_getattro */
+     0,          /* tp_setattro */
+-    0,                  /* tp_as_buffer */
++    0,			/* tp_as_buffer */
+ #if (PY_VERSION_HEX < 0x03000000)
+     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
+ #else
+     Py_TPFLAGS_DEFAULT,      /* tp_flags */
+ #endif
+     0,          /* tp_doc */
+-    0,              /* tp_traverse */
+-    0,                  /* tp_clear */
+-    0,                  /* tp_richcompare */
++    0,		    /* tp_traverse */
++    0,			/* tp_clear */
++    0,			/* tp_richcompare */
+     offsetof(DBEnvObject, in_weakreflist),   /* tp_weaklistoffset */
+     0,          /* tp_iter */
+     0,          /* tp_iternext */
+@@ -9135,20 +9390,20 @@
+     0,          /*tp_as_sequence*/
+     0,          /*tp_as_mapping*/
+     0,          /*tp_hash*/
+-    0,                  /* tp_call */
+-    0,                  /* tp_str */
+-    0,                  /* tp_getattro */
++    0,			/* tp_call */
++    0,			/* tp_str */
++    0,  		/* tp_getattro */
+     0,          /* tp_setattro */
+-    0,                  /* tp_as_buffer */
++    0,			/* tp_as_buffer */
+ #if (PY_VERSION_HEX < 0x03000000)
+     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
+ #else
+     Py_TPFLAGS_DEFAULT,      /* tp_flags */
+ #endif
+     0,          /* tp_doc */
+-    0,          /* tp_traverse */
+-    0,                  /* tp_clear */
+-    0,                  /* tp_richcompare */
++    0,	        /* tp_traverse */
++    0,			/* tp_clear */
++    0,			/* tp_richcompare */
+     offsetof(DBTxnObject, in_weakreflist),   /* tp_weaklistoffset */
+     0,          /*tp_iter*/
+     0,          /*tp_iternext*/
+@@ -9178,24 +9433,23 @@
+     0,          /*tp_as_sequence*/
+     0,          /*tp_as_mapping*/
+     0,          /*tp_hash*/
+-    0,                  /* tp_call */
+-    0,                  /* tp_str */
+-    0,                  /* tp_getattro */
++    0,			/* tp_call */
++    0,			/* tp_str */
++    0,  		/* tp_getattro */
+     0,          /* tp_setattro */
+-    0,                  /* tp_as_buffer */
++    0,			/* tp_as_buffer */
+ #if (PY_VERSION_HEX < 0x03000000)
+     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
+ #else
+     Py_TPFLAGS_DEFAULT,      /* tp_flags */
+ #endif
+     0,          /* tp_doc */
+-    0,              /* tp_traverse */
+-    0,                  /* tp_clear */
+-    0,                  /* tp_richcompare */
++    0,		    /* tp_traverse */
++    0,			/* tp_clear */
++    0,			/* tp_richcompare */
+     offsetof(DBLockObject, in_weakreflist),   /* tp_weaklistoffset */
+ };
+ 
+-#if (DBVER >= 43)
+ statichere PyTypeObject DBSequence_Type = {
+ #if (PY_VERSION_HEX < 0x03000000)
+     PyObject_HEAD_INIT(NULL)
+@@ -9217,27 +9471,26 @@
+     0,          /*tp_as_sequence*/
+     0,          /*tp_as_mapping*/
+     0,          /*tp_hash*/
+-    0,                  /* tp_call */
+-    0,                  /* tp_str */
+-    0,                  /* tp_getattro */
++    0,			/* tp_call */
++    0,			/* tp_str */
++    0,  		/* tp_getattro */
+     0,          /* tp_setattro */
+-    0,                  /* tp_as_buffer */
++    0,			/* tp_as_buffer */
+ #if (PY_VERSION_HEX < 0x03000000)
+     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
+ #else
+     Py_TPFLAGS_DEFAULT,      /* tp_flags */
+ #endif
+     0,          /* tp_doc */
+-    0,              /* tp_traverse */
+-    0,                  /* tp_clear */
+-    0,                  /* tp_richcompare */
++    0,		    /* tp_traverse */
++    0,			/* tp_clear */
++    0,			/* tp_richcompare */
+     offsetof(DBSequenceObject, in_weakreflist),   /* tp_weaklistoffset */
+     0,          /*tp_iter*/
+     0,          /*tp_iternext*/
+     DBSequence_methods, /*tp_methods*/
+     0,          /*tp_members*/
+ };
+-#endif
+ 
+ /* --------------------------------------------------------------------- */
+ /* Module-level functions */
+@@ -9271,7 +9524,6 @@
+     return (PyObject* )newDBEnvObject(flags);
+ }
+ 
+-#if (DBVER >= 43)
+ static PyObject*
+ DBSequence_construct(PyObject* self, PyObject* args, PyObject* kwargs)
+ {
+@@ -9287,7 +9539,6 @@
+     }
+     return (PyObject* )newDBSequenceObject((DBObject*)dbobj, flags);
+ }
+-#endif
+ 
+ static char bsddb_version_doc[] =
+ "Returns a tuple of major, minor, and patch release numbers of the\n\
+@@ -9298,19 +9549,35 @@
+ {
+     int major, minor, patch;
+ 
++    /* This should be instantaneous, no need to release the GIL */
+     db_version(&major, &minor, &patch);
+     return Py_BuildValue("(iii)", major, minor, patch);
+ }
+ 
++#if (DBVER >= 50)
++static PyObject*
++bsddb_version_full(PyObject* self)
++{
++    char *version_string;
++    int family, release, major, minor, patch;
++
++    /* This should be instantaneous, no need to release the GIL */
++    version_string = db_full_version(&family, &release, &major, &minor, &patch);
++    return Py_BuildValue("(siiiii)",
++            version_string, family, release, major, minor, patch);
++}
++#endif
++
+ 
+ /* List of functions defined in the module */
+ static PyMethodDef bsddb_methods[] = {
+     {"DB",          (PyCFunction)DB_construct,          METH_VARARGS | METH_KEYWORDS },
+     {"DBEnv",       (PyCFunction)DBEnv_construct,       METH_VARARGS},
+-#if (DBVER >= 43)
+     {"DBSequence",  (PyCFunction)DBSequence_construct,  METH_VARARGS | METH_KEYWORDS },
+-#endif
+     {"version",     (PyCFunction)bsddb_version,         METH_NOARGS, bsddb_version_doc},
++#if (DBVER >= 50)
++    {"full_version", (PyCFunction)bsddb_version_full, METH_NOARGS},
++#endif
+     {NULL,      NULL}       /* sentinel */
+ };
+ 
+@@ -9328,6 +9595,11 @@
+  */
+ #define ADD_INT(dict, NAME)         _addIntToDict(dict, #NAME, NAME)
+ 
++/*
++** We can rename the module at import time, so the string allocated
++** must be big enough, and any use of the name must use this particular
++** string.
++*/
+ #define MODULE_NAME_MAX_LEN     11
+ static char _bsddbModuleName[MODULE_NAME_MAX_LEN+1] = "_bsddb";
+ 
+@@ -9378,8 +9650,9 @@
+         || (PyType_Ready(&DBEnv_Type) < 0)
+         || (PyType_Ready(&DBTxn_Type) < 0)
+         || (PyType_Ready(&DBLock_Type) < 0)
+-#if (DBVER >= 43)
+         || (PyType_Ready(&DBSequence_Type) < 0)
++#if (DBVER >= 52)
++        || (PyType_Ready(&DBSite_Type) < 0)
+ #endif
+         ) {
+ #if (PY_VERSION_HEX < 0x03000000)
+@@ -9389,11 +9662,6 @@
+ #endif
+     }
+ 
+-#if defined(WITH_THREAD) && !defined(MYDB_USE_GILSTATE)
+-    /* Save the current interpreter, so callbacks can do the right thing. */
+-    _db_interpreterState = PyThreadState_GET()->interp;
+-#endif
+-
+     /* Create the module and add the functions */
+ #if (PY_VERSION_HEX < 0x03000000)
+     m = Py_InitModule(_bsddbModuleName, bsddb_methods);
+@@ -9404,7 +9672,7 @@
+ #if (PY_VERSION_HEX < 0x03000000)
+         return;
+ #else
+-        return NULL;
++    	return NULL;
+ #endif
+     }
+ 
+@@ -9428,13 +9696,7 @@
+     ADD_INT(d, DB_MAX_RECORDS);
+ 
+ #if (DBVER < 48)
+-#if (DBVER >= 42)
+     ADD_INT(d, DB_RPCCLIENT);
+-#else
+-    ADD_INT(d, DB_CLIENT);
+-    /* allow apps to be written using DB_RPCCLIENT on older Berkeley DB */
+-    _addIntToDict(d, "DB_RPCCLIENT", DB_CLIENT);
+-#endif
+ #endif
+ 
+ #if (DBVER < 48)
+@@ -9477,6 +9739,14 @@
+     ADD_INT(d, DB_TXN_SYNC);
+     ADD_INT(d, DB_TXN_NOWAIT);
+ 
++#if (DBVER >= 51)
++    ADD_INT(d, DB_TXN_BULK);
++#endif
++
++#if (DBVER >= 48)
++    ADD_INT(d, DB_CURSOR_BULK);
++#endif
++
+ #if (DBVER >= 46)
+     ADD_INT(d, DB_TXN_WAIT);
+ #endif
+@@ -9511,9 +9781,7 @@
+     ADD_INT(d, DB_LOCK_MINWRITE);
+ 
+     ADD_INT(d, DB_LOCK_EXPIRE);
+-#if (DBVER >= 43)
+     ADD_INT(d, DB_LOCK_MAXWRITE);
+-#endif
+ 
+     _addIntToDict(d, "DB_LOCK_CONFLICT", 0);
+ 
+@@ -9549,9 +9817,6 @@
+     ADD_INT(d, DB_LOCK_UPGRADE);
+ 
+     ADD_INT(d, DB_LSTAT_ABORTED);
+-#if (DBVER < 43)
+-    ADD_INT(d, DB_LSTAT_ERR);
+-#endif
+     ADD_INT(d, DB_LSTAT_FREE);
+     ADD_INT(d, DB_LSTAT_HELD);
+ 
+@@ -9561,9 +9826,7 @@
+     ADD_INT(d, DB_ARCH_ABS);
+     ADD_INT(d, DB_ARCH_DATA);
+     ADD_INT(d, DB_ARCH_LOG);
+-#if (DBVER >= 42)
+     ADD_INT(d, DB_ARCH_REMOVE);
+-#endif
+ 
+     ADD_INT(d, DB_BTREE);
+     ADD_INT(d, DB_HASH);
+@@ -9578,9 +9841,7 @@
+     ADD_INT(d, DB_REVSPLITOFF);
+     ADD_INT(d, DB_SNAPSHOT);
+ 
+-#if (DBVER >= 43)
+     ADD_INT(d, DB_INORDER);
+-#endif
+ 
+     ADD_INT(d, DB_JOIN_NOSORT);
+ 
+@@ -9591,9 +9852,6 @@
+     ADD_INT(d, DB_CACHED_COUNTS);
+ #endif
+ 
+-#if (DBVER <= 41)
+-    ADD_INT(d, DB_COMMIT);
+-#endif
+     ADD_INT(d, DB_CONSUME);
+     ADD_INT(d, DB_CONSUME_WAIT);
+     ADD_INT(d, DB_CURRENT);
+@@ -9651,8 +9909,10 @@
+     ADD_INT(d, DB_LOCK_DEADLOCK);
+     ADD_INT(d, DB_LOCK_NOTGRANTED);
+     ADD_INT(d, DB_NOSERVER);
++#if (DBVER < 52)
+     ADD_INT(d, DB_NOSERVER_HOME);
+     ADD_INT(d, DB_NOSERVER_ID);
++#endif
+     ADD_INT(d, DB_NOTFOUND);
+     ADD_INT(d, DB_OLD_VERSION);
+     ADD_INT(d, DB_RUNRECOVERY);
+@@ -9665,13 +9925,14 @@
+     ADD_INT(d, DB_YIELDCPU);
+     ADD_INT(d, DB_PANIC_ENVIRONMENT);
+     ADD_INT(d, DB_NOPANIC);
+-
+     ADD_INT(d, DB_OVERWRITE);
+ 
+-#if (DBVER >= 43)
+     ADD_INT(d, DB_STAT_SUBSYSTEM);
+     ADD_INT(d, DB_STAT_MEMP_HASH);
+-#endif
++    ADD_INT(d, DB_STAT_LOCK_CONF);
++    ADD_INT(d, DB_STAT_LOCK_LOCKERS);
++    ADD_INT(d, DB_STAT_LOCK_OBJECTS);
++    ADD_INT(d, DB_STAT_LOCK_PARAMS);
+ 
+ #if (DBVER >= 48)
+     ADD_INT(d, DB_OVERWRITE_DUP);
+@@ -9690,7 +9951,6 @@
+     ADD_INT(d, DB_EID_INVALID);
+     ADD_INT(d, DB_EID_BROADCAST);
+ 
+-#if (DBVER >= 42)
+     ADD_INT(d, DB_TIME_NOTGRANTED);
+     ADD_INT(d, DB_TXN_NOT_DURABLE);
+     ADD_INT(d, DB_TXN_WRITE_NOSYNC);
+@@ -9698,9 +9958,8 @@
+     ADD_INT(d, DB_INIT_REP);
+     ADD_INT(d, DB_ENCRYPT);
+     ADD_INT(d, DB_CHKSUM);
+-#endif
+ 
+-#if (DBVER >= 42) && (DBVER < 47)
++#if (DBVER < 47)
+     ADD_INT(d, DB_LOG_AUTOREMOVE);
+     ADD_INT(d, DB_DIRECT_LOG);
+ #endif
+@@ -9733,6 +9992,20 @@
+     ADD_INT(d, DB_VERB_REPLICATION);
+     ADD_INT(d, DB_VERB_WAITSFOR);
+ 
++#if (DBVER >= 50)
++    ADD_INT(d, DB_VERB_REP_SYSTEM);
++#endif
++
++#if (DBVER >= 47)
++    ADD_INT(d, DB_VERB_REP_ELECT);
++    ADD_INT(d, DB_VERB_REP_LEASE);
++    ADD_INT(d, DB_VERB_REP_MISC);
++    ADD_INT(d, DB_VERB_REP_MSGS);
++    ADD_INT(d, DB_VERB_REP_SYNC);
++    ADD_INT(d, DB_VERB_REPMGR_CONNFAIL);
++    ADD_INT(d, DB_VERB_REPMGR_MISC);
++#endif
++
+ #if (DBVER >= 45)
+     ADD_INT(d, DB_EVENT_PANIC);
+     ADD_INT(d, DB_EVENT_REP_CLIENT);
+@@ -9748,16 +10021,48 @@
+     ADD_INT(d, DB_EVENT_WRITE_FAILED);
+ #endif
+ 
++#if (DBVER >= 50)
++    ADD_INT(d, DB_REPMGR_CONF_ELECTIONS);
++    ADD_INT(d, DB_EVENT_REP_MASTER_FAILURE);
++    ADD_INT(d, DB_EVENT_REP_DUPMASTER);
++    ADD_INT(d, DB_EVENT_REP_ELECTION_FAILED);
++#endif
++#if (DBVER >= 48)
++    ADD_INT(d, DB_EVENT_REG_ALIVE);
++    ADD_INT(d, DB_EVENT_REG_PANIC);
++#endif
++
++#if (DBVER >=52)
++    ADD_INT(d, DB_EVENT_REP_SITE_ADDED);
++    ADD_INT(d, DB_EVENT_REP_SITE_REMOVED);
++    ADD_INT(d, DB_EVENT_REP_LOCAL_SITE_REMOVED);
++    ADD_INT(d, DB_EVENT_REP_CONNECT_BROKEN);
++    ADD_INT(d, DB_EVENT_REP_CONNECT_ESTD);
++    ADD_INT(d, DB_EVENT_REP_CONNECT_TRY_FAILED);
++    ADD_INT(d, DB_EVENT_REP_INIT_DONE);
++
++    ADD_INT(d, DB_MEM_LOCK);
++    ADD_INT(d, DB_MEM_LOCKOBJECT);
++    ADD_INT(d, DB_MEM_LOCKER);
++    ADD_INT(d, DB_MEM_LOGID);
++    ADD_INT(d, DB_MEM_TRANSACTION);
++    ADD_INT(d, DB_MEM_THREAD);
++
++    ADD_INT(d, DB_BOOTSTRAP_HELPER);
++    ADD_INT(d, DB_GROUP_CREATOR);
++    ADD_INT(d, DB_LEGACY);
++    ADD_INT(d, DB_LOCAL_SITE);
++    ADD_INT(d, DB_REPMGR_PEER);
++#endif
++
+     ADD_INT(d, DB_REP_DUPMASTER);
+     ADD_INT(d, DB_REP_HOLDELECTION);
+ #if (DBVER >= 44)
+     ADD_INT(d, DB_REP_IGNORE);
+     ADD_INT(d, DB_REP_JOIN_FAILURE);
+ #endif
+-#if (DBVER >= 42)
+     ADD_INT(d, DB_REP_ISPERM);
+     ADD_INT(d, DB_REP_NOTPERM);
+-#endif
+     ADD_INT(d, DB_REP_NEWSITE);
+ 
+     ADD_INT(d, DB_REP_MASTER);
+@@ -9766,7 +10071,13 @@
      ADD_INT(d, DB_REP_PERMANENT);
  
--#if (DBVER >= 44)
-+#if (DBVER >= 44) && (DBVER < 50)
+ #if (DBVER >= 44)
++#if (DBVER >= 50)
++    ADD_INT(d, DB_REP_CONF_AUTOINIT);
++#else
      ADD_INT(d, DB_REP_CONF_NOAUTOINIT);
-+#endif
++#endif /* 5.0 */
++#endif /* 4.4 */
 +#if (DBVER >= 44)
      ADD_INT(d, DB_REP_CONF_DELAYCLIENT);
      ADD_INT(d, DB_REP_CONF_BULK);
      ADD_INT(d, DB_REP_CONF_NOWAIT);
+@@ -9774,9 +10085,7 @@
+     ADD_INT(d, DB_REP_REREQUEST);
+ #endif
+ 
+-#if (DBVER >= 42)
+     ADD_INT(d, DB_REP_NOBUFFER);
+-#endif
+ 
+ #if (DBVER >= 46)
+     ADD_INT(d, DB_REP_LEASE_EXPIRED);
+@@ -9819,14 +10128,34 @@
+     ADD_INT(d, DB_STAT_ALL);
+ #endif
+ 
+-#if (DBVER >= 43)
++#if (DBVER >= 51)
++    ADD_INT(d, DB_REPMGR_ACKS_ALL_AVAILABLE);
++#endif
++
++#if (DBVER >= 48)
++    ADD_INT(d, DB_REP_CONF_INMEM);
++#endif
++
++    ADD_INT(d, DB_TIMEOUT);
++
++#if (DBVER >= 50)
++    ADD_INT(d, DB_FORCESYNC);
++#endif
++
++#if (DBVER >= 48)
++    ADD_INT(d, DB_FAILCHK);
++#endif
++
++#if (DBVER >= 51)
++    ADD_INT(d, DB_HOTBACKUP_IN_PROGRESS);
++#endif
++
+     ADD_INT(d, DB_BUFFER_SMALL);
+     ADD_INT(d, DB_SEQ_DEC);
+     ADD_INT(d, DB_SEQ_INC);
+     ADD_INT(d, DB_SEQ_WRAP);
+-#endif
+ 
+-#if (DBVER >= 43) && (DBVER < 47)
++#if (DBVER < 47)
+     ADD_INT(d, DB_LOG_INMEMORY);
+     ADD_INT(d, DB_DSYNC_LOG);
+ #endif
+@@ -9856,6 +10185,10 @@
+     ADD_INT(d, DB_SET_LOCK_TIMEOUT);
+     ADD_INT(d, DB_SET_TXN_TIMEOUT);
+ 
++#if (DBVER >= 48)
++    ADD_INT(d, DB_SET_REG_TIMEOUT);
++#endif
++
+     /* The exception name must be correct for pickled exception *
+      * objects to unpickle properly.                            */
+ #ifdef PYBSDDB_STANDALONE  /* different value needed for standalone pybsddb */
+@@ -9878,7 +10211,7 @@
+      * using one base class. */
+     PyDict_SetItemString(d, "KeyError", PyExc_KeyError);
+     PyRun_String("class DBNotFoundError(DBError, KeyError): pass\n"
+-                 "class DBKeyEmptyError(DBError, KeyError): pass",
++	         "class DBKeyEmptyError(DBError, KeyError): pass",
+                  Py_file_input, d, d);
+     DBNotFoundError = PyDict_GetItemString(d, "DBNotFoundError");
+     DBKeyEmptyError = PyDict_GetItemString(d, "DBKeyEmptyError");
+@@ -9912,8 +10245,10 @@
+     MAKE_EX(DBRunRecoveryError);
+     MAKE_EX(DBVerifyBadError);
+     MAKE_EX(DBNoServerError);
++#if (DBVER < 52)
+     MAKE_EX(DBNoServerHomeError);
+     MAKE_EX(DBNoServerIDError);
++#endif
+     MAKE_EX(DBPageNotFoundError);
+     MAKE_EX(DBSecondaryBadError);
+ 
+@@ -9927,9 +10262,7 @@
+     MAKE_EX(DBNoSuchFileError);
+     MAKE_EX(DBPermissionsError);
+ 
+-#if (DBVER >= 42)
+     MAKE_EX(DBRepHandleDeadError);
+-#endif
+ #if (DBVER >= 44)
+     MAKE_EX(DBRepLockoutError);
+ #endif
+@@ -9947,27 +10280,30 @@
+ #undef MAKE_EX
+ 
+     /* Initialise the C API structure and add it to the module */
++    bsddb_api.api_version      = PYBSDDB_API_VERSION;
+     bsddb_api.db_type          = &DB_Type;
+     bsddb_api.dbcursor_type    = &DBCursor_Type;
+     bsddb_api.dblogcursor_type = &DBLogCursor_Type;
+     bsddb_api.dbenv_type       = &DBEnv_Type;
+     bsddb_api.dbtxn_type       = &DBTxn_Type;
+     bsddb_api.dblock_type      = &DBLock_Type;
+-#if (DBVER >= 43)
+     bsddb_api.dbsequence_type  = &DBSequence_Type;
+-#endif
+     bsddb_api.makeDBError      = makeDBError;
+ 
+     /*
+-    ** Capsules exist from Python 3.1, but I
+-    ** don't want to break the API compatibility
+-    ** for already published Python versions.
++    ** Capsules exist from Python 2.7 and 3.1.
++    ** We don't support Python 3.0 anymore, so...
++    ** #if (PY_VERSION_HEX < ((PY_MAJOR_VERSION < 3) ? 0x02070000 : 0x03020000))
+     */
+-#if (PY_VERSION_HEX < 0x03020000)
++#if (PY_VERSION_HEX < 0x02070000)
+     py_api = PyCObject_FromVoidPtr((void*)&bsddb_api, NULL);
+ #else
+     {
+-        char py_api_name[250];
++        /*
++        ** The data must outlive the call!!. So, the static definition.
++        ** The buffer must be big enough...
++        */
++        static char py_api_name[MODULE_NAME_MAX_LEN+10];
+ 
+         strcpy(py_api_name, _bsddbModuleName);
+         strcat(py_api_name, ".api");
+@@ -9985,7 +10321,7 @@
+     if (py_api) {
+         PyDict_SetItemString(d, "api", py_api);
+         Py_DECREF(py_api);
+-    } else { /* Something bad happened */
++    } else { /* Something bad happened! */
+         PyErr_WriteUnraisable(m);
+         if(PyErr_Warn(PyExc_RuntimeWarning,
+                 "_bsddb/_pybsddb C API will be not available")) {
+--- Python-2.7.3/Modules/bsddb.h	2012-04-10 01:07:33.000000000 +0200
++++ bsddb3-5.3.0/Modules/bsddb.h	2012-01-16 19:41:21.000000000 +0100
+@@ -61,7 +61,7 @@
+  *
+  * http://www.python.org/peps/pep-0291.html
+  *
+- * This module contains 6 types:
++ * This module contains 7 types:
+  *
+  * DB           (Database)
+  * DBCursor     (Database Cursor)
+@@ -69,6 +69,7 @@
+  * DBTxn        (An explicit database transaction)
+  * DBLock       (A lock handle)
+  * DBSequence   (Sequence)
++ * DBSite       (Site)
+  *
+  * New datatypes:
+  *
+@@ -109,7 +110,7 @@
+ #error "eek! DBVER can't handle minor versions > 9"
+ #endif
+ 
+-#define PY_BSDDB_VERSION "4.8.4.2"
++#define PY_BSDDB_VERSION "5.3.0"
+ 
+ /* Python object definitions */
+ 
+@@ -129,6 +130,9 @@
+ struct DBLogCursorObject; /* Forward declaration */
+ struct DBTxnObject;       /* Forward declaration */
+ struct DBSequenceObject;  /* Forward declaration */
++#if (DBVER >= 52)
++struct DBSiteObject;      /* Forward declaration */
++#endif
+ 
+ typedef struct {
+     PyObject_HEAD
+@@ -140,6 +144,9 @@
+     struct DBObject *children_dbs;
+     struct DBTxnObject *children_txns;
+     struct DBLogCursorObject *children_logcursors;
++#if (DBVER >= 52)
++    struct DBSiteObject *children_sites;
++#endif
+     PyObject        *private_obj;
+     PyObject        *rep_transport;
+     PyObject        *in_weakreflist; /* List of weak references */
+@@ -154,15 +161,14 @@
+     struct behaviourFlags moduleFlags;
+     struct DBTxnObject *txn;
+     struct DBCursorObject *children_cursors;
+-#if (DBVER >=43)
+     struct DBSequenceObject *children_sequences;
+-#endif
+     struct DBObject **sibling_prev_p;
+     struct DBObject *sibling_next;
+     struct DBObject **sibling_prev_p_txn;
+     struct DBObject *sibling_next_txn;
+     PyObject*       associateCallback;
+     PyObject*       btCompareCallback;
++    PyObject*       dupCompareCallback;	    
+     int             primaryDBType;
+     PyObject        *private_obj;
+     PyObject        *in_weakreflist; /* List of weak references */
+@@ -207,6 +213,16 @@
+     PyObject        *in_weakreflist; /* List of weak references */
+ } DBLogCursorObject;
+ 
++#if (DBVER >= 52)
++typedef struct DBSiteObject {
++    PyObject_HEAD
++    DB_SITE         *site;
++    DBEnvObject     *env;
++    struct DBSiteObject **sibling_prev_p;
++    struct DBSiteObject *sibling_next;
++    PyObject    *in_weakreflist; /* List of weak references */
++} DBSiteObject;
++#endif
+ 
+ typedef struct {
+     PyObject_HEAD
+@@ -216,7 +232,6 @@
+ } DBLockObject;
+ 
+ 
+-#if (DBVER >= 43)
+ typedef struct DBSequenceObject {
+     PyObject_HEAD
+     DB_SEQUENCE*     sequence;
+@@ -228,7 +243,6 @@
+     struct DBSequenceObject *sibling_next_txn;
+     PyObject        *in_weakreflist; /* List of weak references */
+ } DBSequenceObject;
+-#endif
+ 
+ 
+ /* API structure for use by C code */
+@@ -236,7 +250,7 @@
+ /* To access the structure from an external module, use code like the
+    following (error checking missed out for clarity):
+ 
+-     // If you are using Python before 3.2:
++     // If you are using Python before 2.7:
+      BSDDB_api* bsddb_api;
+      PyObject*  mod;
+      PyObject*  cobj;
+@@ -249,7 +263,7 @@
+      Py_DECREF(mod);
+ 
+ 
+-     // If you are using Python 3.2 or up:
++     // If you are using Python 2.7 or up: (except Python 3.0, unsupported)
+      BSDDB_api* bsddb_api;
+ 
+      // Use "bsddb3._pybsddb.api" if you're using
+@@ -257,10 +271,14 @@
+      bsddb_api = (void **)PyCapsule_Import("bsddb._bsddb.api", 1);
+ 
+ 
++   Check "api_version" number before trying to use the API.
++
+    The structure's members must not be changed.
+ */
+ 
++#define PYBSDDB_API_VERSION 1
+ typedef struct {
++    unsigned int api_version;
+     /* Type objects */
+     PyTypeObject* db_type;
+     PyTypeObject* dbcursor_type;
+@@ -268,9 +286,7 @@
+     PyTypeObject* dbenv_type;
+     PyTypeObject* dbtxn_type;
+     PyTypeObject* dblock_type;
+-#if (DBVER >= 43)
+     PyTypeObject* dbsequence_type;
+-#endif
+ 
+     /* Functions */
+     int (*makeDBError)(int err);
+@@ -289,9 +305,9 @@
+ #define DBEnvObject_Check(v)    ((v)->ob_type == bsddb_api->dbenv_type)
+ #define DBTxnObject_Check(v)    ((v)->ob_type == bsddb_api->dbtxn_type)
+ #define DBLockObject_Check(v)   ((v)->ob_type == bsddb_api->dblock_type)
+-#if (DBVER >= 43)
+-#define DBSequenceObject_Check(v)  ((v)->ob_type == bsddb_api->dbsequence_type)
+-#endif
++#define DBSequenceObject_Check(v)  \
++    ((bsddb_api->dbsequence_type) && \
++        ((v)->ob_type == bsddb_api->dbsequence_type))
+ 
+ #endif /* COMPILING_BSDDB_C */
+ 
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/python.git/commitdiff/70e6ca94edaa137222e08166e3a4e2ff24d790c1




More information about the pld-cvs-commit mailing list