#----------------------------------------------------------------------
-"""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
# 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?"
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
#------------------------------------------------------------------------
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):
#
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
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
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
#----------------------------------------------------------------------
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
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):
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
#----------------------------------------------------------------------
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
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
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
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
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
#----------------------------------------------------------------------
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
#----------------------------------------------------------------------
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
#----------------------------------------------------------------------
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
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'
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
#----------------------------------------------------------------------
/*
* 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
/* 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$";
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();
}
*/
#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)
{
#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);
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);
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);
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);
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();
+}