Skip to content

Commit cd0903f

Browse files
committed
pybsddb 4.8.4 integration. Please, comment in issue #8156
1 parent 6d26f3e commit cd0903f

23 files changed

Lines changed: 3534 additions & 629 deletions

Lib/bsddb/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#----------------------------------------------------------------------
3434

3535

36-
"""Support for Berkeley DB 4.0 through 4.7 with a simple interface.
36+
"""Support for Berkeley DB 4.1 through 4.8 with a simple interface.
3737
3838
For the full featured object oriented interface use the bsddb.db module
3939
instead. It mirrors the Oracle Berkeley DB C API.
@@ -42,11 +42,12 @@
4242
import sys
4343
absolute_import = (sys.version_info[0] >= 3)
4444

45-
if sys.py3kwarning:
46-
import warnings
47-
warnings.warnpy3k("in 3.x, the bsddb module has been removed; "
48-
"please use the pybsddb project instead",
49-
DeprecationWarning, 2)
45+
if (sys.version_info >= (2, 6)) and (sys.version_info < (3, 0)) :
46+
if sys.py3kwarning and (__name__ != 'bsddb3') :
47+
import warnings
48+
warnings.warnpy3k("in 3.x, the bsddb module has been removed; "
49+
"please use the pybsddb project instead",
50+
DeprecationWarning, 2)
5051

5152
try:
5253
if __name__ == 'bsddb3':
@@ -81,7 +82,7 @@
8182

8283
from weakref import ref
8384

84-
if sys.version_info[0:2] <= (2, 5) :
85+
if sys.version_info < (2, 6) :
8586
import UserDict
8687
MutableMapping = UserDict.DictMixin
8788
else :
@@ -256,7 +257,7 @@ def __len__(self):
256257
self._checkOpen()
257258
return _DeadlockWrap(lambda: len(self.db)) # len(self.db)
258259

259-
if sys.version_info[0:2] >= (2, 6) :
260+
if sys.version_info >= (2, 6) :
260261
def __repr__(self) :
261262
if self.isOpen() :
262263
return repr(dict(_DeadlockWrap(self.db.items)))
@@ -442,8 +443,10 @@ def _checkflag(flag, file):
442443
# Berkeley DB was too.
443444

444445
try:
445-
import thread
446-
del thread
446+
# 2to3 automatically changes "import thread" to "import _thread"
447+
import thread as T
448+
del T
449+
447450
except ImportError:
448451
db.DB_THREAD = 0
449452

Lib/bsddb/dbobj.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
else :
3030
import db
3131

32-
if sys.version_info[0:2] <= (2, 5) :
32+
if sys.version_info < (2, 6) :
3333
try:
3434
from UserDict import DictMixin
3535
except ImportError:
@@ -110,15 +110,17 @@ def set_get_returns_none(self, *args, **kwargs):
110110
def log_stat(self, *args, **kwargs):
111111
return self._cobj.log_stat(*args, **kwargs)
112112

113-
if db.version() >= (4,1):
114-
def dbremove(self, *args, **kwargs):
115-
return self._cobj.dbremove(*args, **kwargs)
116-
def dbrename(self, *args, **kwargs):
117-
return self._cobj.dbrename(*args, **kwargs)
118-
def set_encrypt(self, *args, **kwargs):
119-
return self._cobj.set_encrypt(*args, **kwargs)
113+
def dbremove(self, *args, **kwargs):
114+
return self._cobj.dbremove(*args, **kwargs)
115+
def dbrename(self, *args, **kwargs):
116+
return self._cobj.dbrename(*args, **kwargs)
117+
def set_encrypt(self, *args, **kwargs):
118+
return self._cobj.set_encrypt(*args, **kwargs)
120119

121120
if db.version() >= (4,4):
121+
def fileid_reset(self, *args, **kwargs):
122+
return self._cobj.fileid_reset(*args, **kwargs)
123+
122124
def lsn_reset(self, *args, **kwargs):
123125
return self._cobj.lsn_reset(*args, **kwargs)
124126

@@ -138,7 +140,7 @@ def __setitem__(self, key, value):
138140
def __delitem__(self, arg):
139141
del self._cobj[arg]
140142

141-
if sys.version_info[0:2] >= (2, 6) :
143+
if sys.version_info >= (2, 6) :
142144
def __iter__(self) :
143145
return self._cobj.__iter__()
144146

@@ -229,9 +231,8 @@ def verify(self, *args, **kwargs):
229231
def set_get_returns_none(self, *args, **kwargs):
230232
return self._cobj.set_get_returns_none(*args, **kwargs)
231233

232-
if db.version() >= (4,1):
233-
def set_encrypt(self, *args, **kwargs):
234-
return self._cobj.set_encrypt(*args, **kwargs)
234+
def set_encrypt(self, *args, **kwargs):
235+
return self._cobj.set_encrypt(*args, **kwargs)
235236

236237

237238
class DBSequence:

Lib/bsddb/dbshelve.py

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
#------------------------------------------------------------------------
3131

32-
import cPickle
33-
import sys
34-
3532
import sys
3633
absolute_import = (sys.version_info[0] >= 3)
3734
if absolute_import :
@@ -40,13 +37,41 @@
4037
else :
4138
import db
4239

40+
if sys.version_info[0] >= 3 :
41+
import cPickle # Will be converted to "pickle" by "2to3"
42+
else :
43+
if sys.version_info < (2, 6) :
44+
import cPickle
45+
else :
46+
# When we drop support for python 2.3 and 2.4
47+
# we could use: (in 2.5 we need a __future__ statement)
48+
#
49+
# with warnings.catch_warnings():
50+
# warnings.filterwarnings(...)
51+
# ...
52+
#
53+
# We can not use "with" as is, because it would be invalid syntax
54+
# in python 2.3, 2.4 and (with no __future__) 2.5.
55+
# Here we simulate "with" following PEP 343 :
56+
import warnings
57+
w = warnings.catch_warnings()
58+
w.__enter__()
59+
try :
60+
warnings.filterwarnings('ignore',
61+
message='the cPickle module has been removed in Python 3.0',
62+
category=DeprecationWarning)
63+
import cPickle
64+
finally :
65+
w.__exit__()
66+
del w
67+
4368
#At version 2.3 cPickle switched to using protocol instead of bin
44-
if sys.version_info[:3] >= (2, 3, 0):
69+
if sys.version_info >= (2, 3):
4570
HIGHEST_PROTOCOL = cPickle.HIGHEST_PROTOCOL
4671
# In python 2.3.*, "cPickle.dumps" accepts no
4772
# named parameters. "pickle.dumps" accepts them,
4873
# so this seems a bug.
49-
if sys.version_info[:3] < (2, 4, 0):
74+
if sys.version_info < (2, 4):
5075
def _dumps(object, protocol):
5176
return cPickle.dumps(object, protocol)
5277
else :
@@ -59,11 +84,16 @@ def _dumps(object, protocol):
5984
return cPickle.dumps(object, bin=protocol)
6085

6186

62-
try:
63-
from UserDict import DictMixin
64-
except ImportError:
65-
# DictMixin is new in Python 2.3
66-
class DictMixin: pass
87+
if sys.version_info < (2, 6) :
88+
try:
89+
from UserDict import DictMixin
90+
except ImportError:
91+
# DictMixin is new in Python 2.3
92+
class DictMixin: pass
93+
MutableMapping = DictMixin
94+
else :
95+
import collections
96+
MutableMapping = collections.MutableMapping
6797

6898
#------------------------------------------------------------------------
6999

@@ -106,7 +136,7 @@ def open(filename, flags=db.DB_CREATE, mode=0660, filetype=db.DB_HASH,
106136
class DBShelveError(db.DBError): pass
107137

108138

109-
class DBShelf(DictMixin):
139+
class DBShelf(MutableMapping):
110140
"""A shelf to hold pickled objects, built upon a bsddb DB object. It
111141
automatically pickles/unpickles data objects going to/from the DB.
112142
"""
@@ -157,6 +187,17 @@ def keys(self, txn=None):
157187
else:
158188
return self.db.keys()
159189

190+
if sys.version_info >= (2, 6) :
191+
def __iter__(self) : # XXX: Load all keys in memory :-(
192+
for k in self.db.keys() :
193+
yield k
194+
195+
# Do this when "DB" support iteration
196+
# Or is it enough to pass thru "getattr"?
197+
#
198+
# def __iter__(self) :
199+
# return self.db.__iter__()
200+
160201

161202
def open(self, *args, **kwargs):
162203
self.db.open(*args, **kwargs)

Lib/bsddb/dbtables.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,35 @@
2222
import copy
2323
import random
2424
import struct
25-
import cPickle as pickle
25+
26+
27+
if sys.version_info[0] >= 3 :
28+
import pickle
29+
else :
30+
if sys.version_info < (2, 6) :
31+
import cPickle as pickle
32+
else :
33+
# When we drop support for python 2.3 and 2.4
34+
# we could use: (in 2.5 we need a __future__ statement)
35+
#
36+
# with warnings.catch_warnings():
37+
# warnings.filterwarnings(...)
38+
# ...
39+
#
40+
# We can not use "with" as is, because it would be invalid syntax
41+
# in python 2.3, 2.4 and (with no __future__) 2.5.
42+
# Here we simulate "with" following PEP 343 :
43+
import warnings
44+
w = warnings.catch_warnings()
45+
w.__enter__()
46+
try :
47+
warnings.filterwarnings('ignore',
48+
message='the cPickle module has been removed in Python 3.0',
49+
category=DeprecationWarning)
50+
import cPickle as pickle
51+
finally :
52+
w.__exit__()
53+
del w
2654

2755
try:
2856
# For Pythons w/distutils pybsddb
@@ -31,12 +59,6 @@
3159
# For Python 2.3
3260
from bsddb import db
3361

34-
# XXX(nnorwitz): is this correct? DBIncompleteError is conditional in _bsddb.c
35-
if not hasattr(db,"DBIncompleteError") :
36-
class DBIncompleteError(Exception):
37-
pass
38-
db.DBIncompleteError = DBIncompleteError
39-
4062
class TableDBError(StandardError):
4163
pass
4264
class TableAlreadyExists(TableDBError):
@@ -261,16 +283,10 @@ def close(self):
261283
self.env = None
262284

263285
def checkpoint(self, mins=0):
264-
try:
265-
self.env.txn_checkpoint(mins)
266-
except db.DBIncompleteError:
267-
pass
286+
self.env.txn_checkpoint(mins)
268287

269288
def sync(self):
270-
try:
271-
self.db.sync()
272-
except db.DBIncompleteError:
273-
pass
289+
self.db.sync()
274290

275291
def _db_print(self) :
276292
"""Print the database to stdout for debugging"""
@@ -659,6 +675,13 @@ def cmp_conditions(atuple, btuple):
659675
a = atuple[1]
660676
b = btuple[1]
661677
if type(a) is type(b):
678+
679+
# Needed for python 3. "cmp" vanished in 3.0.1
680+
def cmp(a, b) :
681+
if a==b : return 0
682+
if a<b : return -1
683+
return 1
684+
662685
if isinstance(a, PrefixCond) and isinstance(b, PrefixCond):
663686
# longest prefix first
664687
return cmp(len(b.prefix), len(a.prefix))

0 commit comments

Comments
 (0)