Everything worked in both the distutils distro and in Python 2.3cvs,

so merge from the bsddb-bsddb3-schizo-branch back to the trunk.
This commit is contained in:
Barry Warsaw 2003-01-28 17:20:44 +00:00
parent a6ae9a2128
commit f71de3e9a0
18 changed files with 213 additions and 119 deletions

View file

@ -44,11 +44,11 @@ except ImportError:
del sys.modules[__name__]
raise
# bsddb3 calls it _db
_db = _bsddb
__version__ = _db.__version__
# bsddb3 calls it db, but provide _db for backwards compatibility
db = _db = _bsddb
__version__ = db.__version__
error = _db.DBError # So bsddb.error will mean something...
error = db.DBError # So bsddb.error will mean something...
#----------------------------------------------------------------------
@ -152,14 +152,14 @@ def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None,
cachesize=None, lorder=None, hflags=0):
flags = _checkflag(flag)
d = _db.DB()
d = db.DB()
d.set_flags(hflags)
if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
if ffactor is not None: d.set_h_ffactor(ffactor)
if nelem is not None: d.set_h_nelem(nelem)
d.open(file, _db.DB_HASH, flags, mode)
d.open(file, db.DB_HASH, flags, mode)
return _DBWithCursor(d)
#----------------------------------------------------------------------
@ -169,14 +169,14 @@ def btopen(file, flag='c', mode=0666,
pgsize=None, lorder=None):
flags = _checkflag(flag)
d = _db.DB()
d = db.DB()
if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
d.set_flags(btflags)
if minkeypage is not None: d.set_bt_minkey(minkeypage)
if maxkeypage is not None: d.set_bt_maxkey(maxkeypage)
d.open(file, _db.DB_BTREE, flags, mode)
d.open(file, db.DB_BTREE, flags, mode)
return _DBWithCursor(d)
#----------------------------------------------------------------------
@ -187,7 +187,7 @@ def rnopen(file, flag='c', mode=0666,
rlen=None, delim=None, source=None, pad=None):
flags = _checkflag(flag)
d = _db.DB()
d = db.DB()
if cachesize is not None: d.set_cachesize(0, cachesize)
if pgsize is not None: d.set_pagesize(pgsize)
if lorder is not None: d.set_lorder(lorder)
@ -196,7 +196,7 @@ def rnopen(file, flag='c', mode=0666,
if rlen is not None: d.set_re_len(rlen)
if source is not None: d.set_re_source(source)
if pad is not None: d.set_re_pad(pad)
d.open(file, _db.DB_RECNO, flags, mode)
d.open(file, db.DB_RECNO, flags, mode)
return _DBWithCursor(d)
#----------------------------------------------------------------------
@ -204,18 +204,18 @@ def rnopen(file, flag='c', mode=0666,
def _checkflag(flag):
if flag == 'r':
flags = _db.DB_RDONLY
flags = db.DB_RDONLY
elif flag == 'rw':
flags = 0
elif flag == 'w':
flags = _db.DB_CREATE
flags = db.DB_CREATE
elif flag == 'c':
flags = _db.DB_CREATE
flags = db.DB_CREATE
elif flag == 'n':
flags = _db.DB_CREATE | _db.DB_TRUNCATE
flags = db.DB_CREATE | db.DB_TRUNCATE
else:
raise error, "flags should be one of 'r', 'w', 'c' or 'n'"
return flags | _db.DB_THREAD
return flags | db.DB_THREAD
#----------------------------------------------------------------------
@ -231,7 +231,7 @@ try:
import thread
del thread
except ImportError:
_db.DB_THREAD = 0
db.DB_THREAD = 0
#----------------------------------------------------------------------

View file

@ -30,7 +30,12 @@ storage.
#------------------------------------------------------------------------
import cPickle
try:
# For Python 2.3
from bsddb import db
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db
#------------------------------------------------------------------------

View file

@ -17,23 +17,26 @@
#
_cvsid = '$Id$'
import string
import sys
try:
import cPickle
pickle = cPickle
except ImportError:
import pickle
import whrandom
import xdrlib
import re
import sys
import copy
import xdrlib
import whrandom
from types import ListType, StringType
import cPickle as pickle
try:
# For Python 2.3
from bsddb.db import *
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3.db import *
class TableDBError(StandardError): pass
class TableAlreadyExists(TableDBError): pass
class TableDBError(StandardError):
pass
class TableAlreadyExists(TableDBError):
pass
class Cond:
@ -72,9 +75,9 @@ class LikeCond(Cond):
# escape python re characters
chars_to_escape = '.*+()[]?'
for char in chars_to_escape :
likestr = string.replace(likestr, char, '\\'+char)
likestr = likestr.replace(char, '\\'+char)
# convert %s to wildcards
self.likestr = string.replace(likestr, '%', '.*')
self.likestr = likestr.replace('%', '.*')
self.re = re.compile('^'+self.likestr+'$', re_flags)
def __call__(self, s):
return self.re.match(s)
@ -84,7 +87,9 @@ class LikeCond(Cond):
#
_table_names_key = '__TABLE_NAMES__' # list of the tables in this db
_columns = '._COLUMNS__' # table_name+this key contains a list of columns
def _columns_key(table) : return table + _columns
def _columns_key(table):
return table + _columns
#
# these keys are found within table sub databases
@ -93,20 +98,31 @@ _data = '._DATA_.' # this+column+this+rowid key contains table data
_rowid = '._ROWID_.' # this+rowid+this key contains a unique entry for each
# row in the table. (no data is stored)
_rowid_str_len = 8 # length in bytes of the unique rowid strings
def _data_key(table, col, rowid) : return table + _data + col + _data + rowid
def _search_col_data_key(table, col) : return table + _data + col + _data
def _search_all_data_key(table) : return table + _data
def _rowid_key(table, rowid) : return table + _rowid + rowid + _rowid
def _search_rowid_key(table) : return table + _rowid
def _data_key(table, col, rowid):
return table + _data + col + _data + rowid
def _search_col_data_key(table, col):
return table + _data + col + _data
def _search_all_data_key(table):
return table + _data
def _rowid_key(table, rowid):
return table + _rowid + rowid + _rowid
def _search_rowid_key(table):
return table + _rowid
def contains_metastrings(s) :
"""Verify that the given string does not contain any
metadata strings that might interfere with dbtables database operation.
"""
if string.find(s, _table_names_key) >= 0 or \
string.find(s, _columns) >= 0 or \
string.find(s, _data) >= 0 or \
string.find(s, _rowid) >= 0 :
if (s.find(_table_names_key) >= 0 or
s.find(_columns) >= 0 or
s.find(_data) >= 0 or
s.find(_rowid) >= 0):
# Then
return 1
else:
return 0
@ -202,7 +218,7 @@ class bsdTableDB :
"""CreateTable(table, columns) - Create a new table in the database
raises TableDBError if it already exists or for other DB errors.
"""
assert type(columns) == type([])
assert isinstance(columns, ListType)
txn = None
try:
# checking sanity of the table and column names here on
@ -233,7 +249,6 @@ class bsdTableDB :
txn.commit()
txn = None
except DBError, dberror:
if txn:
txn.abort()
@ -244,7 +259,7 @@ class bsdTableDB :
"""Return a list of columns in the given table.
[] if the table doesn't exist.
"""
assert type(table) == type('')
assert isinstance(table, StringType)
if contains_metastrings(table):
raise ValueError, "bad table name: contains reserved metastrings"
@ -273,7 +288,7 @@ class bsdTableDB :
additional columns present in the given list as well as
all of its current columns.
"""
assert type(columns) == type([])
assert isinstance(columns, ListType)
try:
self.CreateTable(table, columns)
except TableAlreadyExists:
@ -476,7 +491,6 @@ class bsdTableDB :
if txn:
txn.abort()
raise
except DBError, dberror:
raise TableDBError, dberror[1]
@ -498,7 +512,6 @@ class bsdTableDB :
matching_rowids = self.__Select(table, columns, conditions)
except DBError, dberror:
raise TableDBError, dberror[1]
# return the matches as a list of dictionaries
return matching_rowids.values()
@ -524,15 +537,15 @@ class bsdTableDB :
# keyed on rows that match so far, containings dicts keyed on
# column names containing the data for that row and column.
matching_rowids = {}
rejected_rowids = {} # keys are rowids that do not match
# keys are rowids that do not match
rejected_rowids = {}
# attempt to sort the conditions in such a way as to minimize full
# column lookups
def cmp_conditions(atuple, btuple):
a = atuple[1]
b = btuple[1]
if type(a) == type(b) :
if type(a) is type(b):
if isinstance(a, PrefixCond) and isinstance(b, PrefixCond):
# longest prefix first
return cmp(len(b.prefix), len(a.prefix))
@ -617,8 +630,7 @@ class bsdTableDB :
def Drop(self, table):
"""Remove an entire table from the database
"""
"""Remove an entire table from the database"""
txn = None
try:
txn = self.env.txn_begin()

View file

@ -26,7 +26,12 @@
#
from time import sleep as _sleep
from bsddb import _db
try:
# For Python 2.3
from bsddb import db
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db
# always sleep at least N seconds between retrys
_deadlock_MinSleepTime = 1.0/64
@ -60,7 +65,7 @@ def DeadlockWrap(function, *_args, **_kwargs):
while 1:
try:
return function(*_args, **_kwargs)
except _db.DBLockDeadlockError:
except db.DBLockDeadlockError:
if _deadlock_VerboseFile:
_deadlock_VerboseFile.write(
'dbutils.DeadlockWrap: sleeping %1.3f\n' % sleeptime)

View file

@ -16,7 +16,12 @@ if 'silent' in sys.argv: # take care of old flag, just in case
def print_versions():
try:
# 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

View file

@ -16,7 +16,12 @@ except ImportError:
import unittest
from test_all import verbose
try:
# For Python 2.3
from bsddb import db, dbshelve
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db, dbshelve
#----------------------------------------------------------------------

View file

@ -12,7 +12,12 @@ import tempfile
from pprint import pprint
import unittest
try:
# 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

View file

@ -4,13 +4,18 @@ regression test suite.
"""
import sys, os, string
from bsddb import hashopen, btopen, rnopen
import bsddb
import unittest
import tempfile
from test_all import verbose
try:
# 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):
@ -126,7 +131,7 @@ class CompatibilityTestCase(unittest.TestCase):
if verbose: print "truth test: true"
else:
if verbose: print "truth test: false"
except bsddb.error:
except db.DBError:
pass
else:
self.fail("Exception expected")

View file

@ -3,7 +3,12 @@ import sys, os, string
import unittest
import glob
try:
# For Python 2.3
from bsddb import db, dbobj
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db, dbobj
#----------------------------------------------------------------------

View file

@ -8,7 +8,12 @@ from pprint import pprint
from types import *
import unittest
from bsddb import dbshelve, db
try:
# 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

View file

@ -30,7 +30,12 @@ except ImportError:
import unittest
from test_all import verbose
try:
# For Python 2.3
from bsddb import db, dbtables
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db, dbtables

View file

@ -8,7 +8,12 @@ import tempfile
import glob
import unittest
try:
# 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

View file

@ -7,7 +7,12 @@ import tempfile
from pprint import pprint
import unittest
try:
# 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

View file

@ -18,7 +18,12 @@ except ImportError:
import unittest
from test_all import verbose
try:
# For Python 2.3
from bsddb import db
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db
#----------------------------------------------------------------------

View file

@ -5,8 +5,12 @@ import os
import sys
import unittest
from bsddb import db
from bsddb import dbshelve
try:
# For Python 2.3
from bsddb import db, dbshelve
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db, dbshelve
from test.test_support import verbose

View file

@ -7,7 +7,12 @@ import tempfile
from pprint import pprint
import unittest
try:
# 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

View file

@ -8,9 +8,15 @@ import tempfile
from pprint import pprint
import unittest
from bsddb import db
from test_all import verbose
try:
# For Python 2.3
from bsddb import db
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

View file

@ -26,7 +26,14 @@ except ImportError:
import unittest
from test_all import verbose
try:
# For Python 2.3
from bsddb import db, dbutils
except ImportError:
# For earlier Pythons w/distutils pybsddb
from bsddb3 import db, dbutils
#----------------------------------------------------------------------