]> granicus.if.org Git - python/commitdiff
Adds basic support for BerkeleyDB 4.2.x. Compiles and passes tests; new
authorGregory P. Smith <greg@mad-scientist.com>
Sun, 21 Sep 2003 00:08:14 +0000 (00:08 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Sun, 21 Sep 2003 00:08:14 +0000 (00:08 +0000)
features in BerkeleyDB not exposed.  notably: the DB_MPOOLFILE interface
has not yet been wrapped in an object.

Adds support for building and installing bsddb3 in python2.3 that has
an older version of this module installed as bsddb without conflicts.
The pybsddb.sf.net build/packaged version of the module uses a
dynamicly loadable module called _pybsddb rather than _bsddb.

21 files changed:
Lib/bsddb/__init__.py
Lib/bsddb/db.py
Lib/bsddb/dbshelve.py
Lib/bsddb/dbtables.py
Lib/bsddb/dbutils.py
Lib/bsddb/test/test_all.py
Lib/bsddb/test/test_associate.py
Lib/bsddb/test/test_basics.py
Lib/bsddb/test/test_compat.py
Lib/bsddb/test/test_dbobj.py
Lib/bsddb/test/test_dbshelve.py
Lib/bsddb/test/test_dbtables.py
Lib/bsddb/test/test_env_close.py
Lib/bsddb/test/test_get_none.py
Lib/bsddb/test/test_join.py
Lib/bsddb/test/test_lock.py
Lib/bsddb/test/test_misc.py
Lib/bsddb/test/test_queue.py
Lib/bsddb/test/test_recno.py
Lib/bsddb/test/test_thread.py
Modules/_bsddb.c

index 6b4f96518802b68c8106fec4b3d96d123bacf79a..4671acc3904c4346f7f6ffe86e5c53867a2acf15 100644 (file)
 #----------------------------------------------------------------------
 
 
-"""Support for BerkeleyDB 3.1 through 4.1.
+"""Support for BerkeleyDB 3.2 through 4.2.
 """
 
 try:
-    import _bsddb
+    if __name__ == 'bsddb3':
+        # import _pybsddb binary as it should be the more recent version from
+        # a standalone pybsddb addon package than the version included with
+        # python as bsddb._bsddb.
+        import _pybsddb
+        _bsddb = _pybsddb
+    else:
+        import _bsddb
 except ImportError:
     # Remove ourselves from sys.modules
     import sys
index c1749dfa0786ba771ede3c6d7adb242402f5bb8c..b2ee14e53754e61547dc71c4137928094588fd2c 100644 (file)
 # case we ever want to augment the stuff in _db in any way.  For now
 # it just simply imports everything from _db.
 
-from _bsddb import *
-from _bsddb import __version__
+if __name__[:len('bsddb3.')] == 'bsddb3.':
+    # import _pybsddb binary as it should be the more recent version from
+    # a standalone pybsddb addon package than the version included with
+    # python as bsddb._bsddb.
+    from _pybsddb import *
+    from _pybsddb import __version__
+else:
+    from _bsddb import *
+    from _bsddb import __version__
 
-if version() < (3, 1, 0):
-    raise ImportError, "BerkeleyDB 3.x symbols not found.  Perhaps python was statically linked with an older version?"
+if version() < (3, 2, 0):
+    raise ImportError, "correct BerkeleyDB symbols not found.  Perhaps python was statically linked with an older version?"
index fe4c4d197fb06f0686adf1b707e29b0092a1d1f1..003038ba56e6ead349936f83bf8fde1328b96652 100644 (file)
@@ -35,12 +35,7 @@ try:
 except ImportError:
     # DictMixin is new in Python 2.3
     class DictMixin: pass
-try:
-    # For Python 2.3
-    from bsddb import db
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db
+import db
 
 #------------------------------------------------------------------------
 
index d052ca5b937d37c9446f043b2da7a6ceb34c301c..6edfd29bce57b00470a0165cf0aac324a9d0ba47 100644 (file)
@@ -26,11 +26,11 @@ from types import ListType, StringType
 import cPickle as pickle
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3.db import *
+except ImportError:
     # For Python 2.3
     from bsddb.db import *
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3.db import *
 
 
 class TableDBError(StandardError):
index 3568b44a82b09f28d3425053bc7426ff199ffa66..3f6384279f3dab41c7cf293909558485b1b9270b 100644 (file)
 #
 from time import sleep as _sleep
 
-try:
-    # For Python 2.3
-    from bsddb import db
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db
+import db
 
 # always sleep at least N seconds between retrys
 _deadlock_MinSleepTime = 1.0/64
index 358f5d1e1e58ded2d9fce29ea651e88b4c9f76b6..3bf70d7db02c23c8394bac4ad504b077fa32c3d1 100644 (file)
@@ -17,11 +17,11 @@ if 'silent' in sys.argv:  # take care of old flag, just in case
 
 def print_versions():
     try:
+        # For Pythons w/distutils pybsddb
+        from bsddb3 import db
+    except ImportError:
         # For Python 2.3
         from bsddb import db
-    except ImportError:
-        # For earlier Pythons w/distutils pybsddb
-        from bsddb3 import db
     print
     print '-=' * 38
     print db.DB_VERSION_STRING
index 5fe41a93c4132f3a3ff2fa19ec311e7ee2464794..f810eb01465f9fbd5bf7e387b752736fdf9245ac 100644 (file)
@@ -17,11 +17,11 @@ import unittest
 from test_all import verbose
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db, dbshelve
+except ImportError:
     # For Python 2.3
     from bsddb import db, dbshelve
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db, dbshelve
 
 
 #----------------------------------------------------------------------
index dbab2313b08c66a8490e7fe31892deef4f4508c9..2e6b922b4dba71774b802018354daf424facf029 100644 (file)
@@ -13,11 +13,11 @@ from pprint import pprint
 import unittest
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db
+except ImportError:
     # For Python 2.3
     from bsddb import db
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db
 
 from test_all import verbose
 
index 645cbd7afb3251f806c9a96356937fd1e1899155..12464ca72da25ac684aae93bdd94dfc3e3fa911d 100644 (file)
@@ -10,11 +10,11 @@ import tempfile
 from test_all import verbose
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db, hashopen, btopen, rnopen
+except ImportError:
     # For Python 2.3
     from bsddb import db, hashopen, btopen, rnopen
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db, hashopen, btopen, rnopen
 
 
 class CompatibilityTestCase(unittest.TestCase):
index 93ea7ba84d8d23d510de8913626de2309e21557e..6799fc9c220a80c72123d025ad4f5e824dd9e343 100644 (file)
@@ -4,11 +4,11 @@ import unittest
 import glob
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db, dbobj
+except ImportError:
     # For Python 2.3
     from bsddb import db, dbobj
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db, dbobj
 
 
 #----------------------------------------------------------------------
index 7491cb77b5035cd39914b276f3f069363be623a0..722ee5b407d971441edbd5b91b18e3c58be1de83 100644 (file)
@@ -9,11 +9,11 @@ from types import *
 import unittest
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db, dbshelve
+except ImportError:
     # For Python 2.3
     from bsddb import db, dbshelve
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db, dbshelve
 
 from test_all import verbose
 
index 685b08d4ae6c69f00def0ebefb6c409da709456f..eb5758f94b8236e1641be3eefa2c9973b71dadea 100644 (file)
@@ -31,11 +31,11 @@ import unittest
 from test_all import verbose
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db, dbtables
+except ImportError:
     # For Python 2.3
     from bsddb import db, dbtables
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db, dbtables
 
 
 
index 105be44239057231eabd68b97d01d5e306040135..c1129417d1de75656e97bebc21e856fc5197baf3 100644 (file)
@@ -9,11 +9,11 @@ import glob
 import unittest
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db
+except ImportError:
     # For Python 2.3
     from bsddb import db
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db
 
 from test_all import verbose
 
index 40b224e864d7ae44e348a7273c860e9171aa6d07..5f09cecc6a39c6982954977b3c2c82e5b5418e55 100644 (file)
@@ -8,11 +8,11 @@ from pprint import pprint
 import unittest
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db
+except ImportError:
     # For Python 2.3
     from bsddb import db
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db
 
 from test_all import verbose
 
index 838ffe75900978fa145c675197a158bfb2b9e4aa..73edd114ee4afbcf445f542b2a1d4fdc9b23c71d 100644 (file)
@@ -16,11 +16,11 @@ import unittest
 from test_all import verbose
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db, dbshelve
+except ImportError:
     # For Python 2.3
     from bsddb import db, dbshelve
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db, dbshelve
 
 
 #----------------------------------------------------------------------
index 008f89da5f8a384fbc8bfa2c8b7eb79b4ae90cfb..4a5adc47fa6c94d40e65000165885b7ec75cafa3 100644 (file)
@@ -19,11 +19,11 @@ import unittest
 from test_all import verbose
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db
+except ImportError:
     # For Python 2.3
     from bsddb import db
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db
 
 
 #----------------------------------------------------------------------
index 43d194ad562860bf22fb201cf8d393499f775b27..a66b1de8a7c75c701a823755b4c24ba40a195630 100644 (file)
@@ -6,11 +6,11 @@ import sys
 import unittest
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db, dbshelve
+except ImportError:
     # For Python 2.3
     from bsddb import db, dbshelve
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db, dbshelve
 
 #----------------------------------------------------------------------
 
index 24b86cb927f578460513a5767696dbf33e540ac5..95cf20d0d2bb35a85eff7ec4545a9861ad046f43 100644 (file)
@@ -8,11 +8,11 @@ from pprint import pprint
 import unittest
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db
+except ImportError:
     # For Python 2.3
     from bsddb import db
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db
 
 from test_all import verbose
 
index 3e517c1cc9770cc9661760fc5dc90ee522944282..87446d3ff5fbf182fc76a7fc9887a37a1cd61d25 100644 (file)
@@ -11,11 +11,11 @@ import unittest
 from test_all import verbose
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db
+except ImportError:
     # For Python 2.3
     from bsddb import db
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db
 
 letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
 
index cf4237c3303981e38f497b04dc0cdf0404b3d7c3..59af027b8aa4796211be3c84c7be7b40f2444555 100644 (file)
@@ -28,11 +28,11 @@ import unittest
 from test_all import verbose
 
 try:
+    # For Pythons w/distutils pybsddb
+    from bsddb3 import db, dbutils
+except ImportError:
     # For Python 2.3
     from bsddb import db, dbutils
-except ImportError:
-    # For earlier Pythons w/distutils pybsddb
-    from bsddb3 import db, dbutils
 
 
 #----------------------------------------------------------------------
index dcbcdb37cee9dbe5b3a9c76d0a61f8d7f817273a..f24c71327ecdf4fc867249af0fd90612b6b7db4b 100644 (file)
@@ -36,7 +36,7 @@
 /*
  * Handwritten code to wrap version 3.x of the Berkeley DB library,
  * written to replace a SWIG-generated file.  It has since been updated
- * to compile with BerkeleyDB versions 3.2 through 4.1.
+ * to compile with BerkeleyDB versions 3.2 through 4.2.
  *
  * This module was started by Andrew Kuchling to remove the dependency
  * on SWIG in a package by Gregory P. Smith <greg@electricrain.com> who
@@ -93,7 +93,7 @@
 /* 40 = 4.0, 33 = 3.3; this will break if the second number is > 9 */
 #define DBVER (DB_VERSION_MAJOR * 10 + DB_VERSION_MINOR)
 
-#define PY_BSDDB_VERSION "4.1.6"
+#define PY_BSDDB_VERSION "4.2.0"
 static char *rcs_id = "$Id$";
 
 
@@ -2167,6 +2167,17 @@ DB_verify(DBObject* self, PyObject* args, PyObject* kwargs)
     MYDB_END_ALLOW_THREADS;
     if (outFileName)
         fclose(outFile);
+
+    /* DB.verify acts as a DB handle destructor (like close); this was
+     * documented in BerkeleyDB 4.2 but had the undocumented effect
+     * of not being safe in prior versions while still requiring an explicit
+     * DB.close call afterwards.  Lets call close for the user to emulate
+     * the safe 4.2 behaviour. */
+#if (DBVER <= 41)
+    self->db->close(self->db, 0);
+#endif
+    self->db = NULL;
+
     RETURN_IF_ERR();
     RETURN_NONE();
 }
@@ -4340,7 +4351,8 @@ static PyMethodDef bsddb_methods[] = {
  */
 #define ADD_INT(dict, NAME)         _addIntToDict(dict, #NAME, NAME)
 
-
+#define MODULE_NAME_MAX_LEN     11
+static char _bsddbModuleName[MODULE_NAME_MAX_LEN+1] = "_bsddb";
 
 DL_EXPORT(void) init_bsddb(void)
 {
@@ -4365,7 +4377,7 @@ DL_EXPORT(void) init_bsddb(void)
 #endif
 
     /* Create the module and add the functions */
-    m = Py_InitModule("_bsddb", bsddb_methods);
+    m = Py_InitModule(_bsddbModuleName, bsddb_methods);
 
     /* Add some symbolic constants to the module */
     d = PyModule_GetDict(m);
@@ -4386,7 +4398,13 @@ DL_EXPORT(void) init_bsddb(void)
     ADD_INT(d, DB_MAX_PAGES);
     ADD_INT(d, DB_MAX_RECORDS);
 
+#if (DBVER >= 42)
+    ADD_INT(d, DB_RPCCLIENT);
+#else
     ADD_INT(d, DB_CLIENT);
+    /* allow apps to be written using DB_RPCCLIENT on older BerkeleyDB */
+    _addIntToDict(d, "DB_RPCCLIENT", DB_CLIENT);
+#endif
     ADD_INT(d, DB_XA_CREATE);
 
     ADD_INT(d, DB_CREATE);
@@ -4535,7 +4553,7 @@ DL_EXPORT(void) init_bsddb(void)
     ADD_INT(d, DB_CHECKPOINT);
     ADD_INT(d, DB_CURLSN);
 #endif
-#if (DBVER >= 33)
+#if ((DBVER >= 33) && (DBVER <= 41))
     ADD_INT(d, DB_COMMIT);
 #endif
     ADD_INT(d, DB_CONSUME);
@@ -4610,6 +4628,18 @@ DL_EXPORT(void) init_bsddb(void)
     ADD_INT(d, DB_NOPANIC);
 #endif
 
+#if (DBVER >= 42)
+    ADD_INT(d, DB_TIME_NOTGRANTED);
+    ADD_INT(d, DB_TXN_NOT_DURABLE);
+    ADD_INT(d, DB_TXN_WRITE_NOSYNC);
+    ADD_INT(d, DB_LOG_AUTOREMOVE);
+    ADD_INT(d, DB_DIRECT_LOG);
+    ADD_INT(d, DB_DIRECT_DB);
+    ADD_INT(d, DB_INIT_REP);
+    ADD_INT(d, DB_ENCRYPT);
+    ADD_INT(d, DB_CHKSUM);
+#endif
+
 #if (DBVER >= 41)
     ADD_INT(d, DB_ENCRYPT_AES);
     ADD_INT(d, DB_AUTO_COMMIT);
@@ -4686,3 +4716,12 @@ DL_EXPORT(void) init_bsddb(void)
         Py_FatalError("can't initialize module _bsddb");
     }
 }
+
+/* allow this module to be named _pybsddb so that it can be installed
+ * and imported on top of python >= 2.3 that includes its own older
+ * copy of the library named _bsddb without importing the old version. */
+DL_EXPORT(void) init_pybsddb(void)
+{
+    strncpy(_bsddbModuleName, "_pybsddb", MODULE_NAME_MAX_LEN);
+    init_bsddb();
+}