annotate Lib/bsddb/__init__.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents b45868fe489c
children 751c6dd71b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
1 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
2 # Copyright (c) 1999-2001, Digital Creations, Fredericksburg, VA, USA
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
3 # and Andrew Kuchling. All rights reserved.
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
4 #
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
5 # Redistribution and use in source and binary forms, with or without
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
6 # modification, are permitted provided that the following conditions are
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
7 # met:
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
8 #
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
9 # o Redistributions of source code must retain the above copyright
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
10 # notice, this list of conditions, and the disclaimer that follows.
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
11 #
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
12 # o Redistributions in binary form must reproduce the above copyright
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
13 # notice, this list of conditions, and the following disclaimer in
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
14 # the documentation and/or other materials provided with the
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
15 # distribution.
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
16 #
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
17 # o Neither the name of Digital Creations nor the names of its
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
18 # contributors may be used to endorse or promote products derived
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
19 # from this software without specific prior written permission.
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
20 #
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
21 # THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
22 # IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
23 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
24 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
25 # CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
28 # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
29 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
30 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
31 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
32 # DAMAGE.
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
33 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
34
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
35
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
36 """Support for Berkeley DB 4.0 through 4.7 with a simple interface.
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
37
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
38 For the full featured object oriented interface use the bsddb.db module
46984
e4e3b3eba226 Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents: 42767
diff changeset
39 instead. It mirrors the Oracle Berkeley DB C API.
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
40 """
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
41
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
42 import sys
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
43 absolute_import = (sys.version_info[0] >= 3)
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
44
49028
b45868fe489c Deprecate bsddb for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 48950
diff changeset
45 if sys.py3kwarning:
b45868fe489c Deprecate bsddb for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 48950
diff changeset
46 import warnings
b45868fe489c Deprecate bsddb for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 48950
diff changeset
47 warnings.warnpy3k("in 3.x, bsddb has been removed; "
b45868fe489c Deprecate bsddb for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 48950
diff changeset
48 "please use the pybsddb project instead",
b45868fe489c Deprecate bsddb for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 48950
diff changeset
49 DeprecationWarning, 2)
b45868fe489c Deprecate bsddb for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 48950
diff changeset
50
26390
a8cadfb0ff83 Delete bsddb from sys.modules if _bsddb cannot be imported.
Martin v. Löwis <martin@v.loewis.de>
parents: 26280
diff changeset
51 try:
30475
185c5f6b6157 Adds basic support for BerkeleyDB 4.2.x. Compiles and passes tests; new
Gregory P. Smith <greg@mad-scientist.com>
parents: 30474
diff changeset
52 if __name__ == 'bsddb3':
185c5f6b6157 Adds basic support for BerkeleyDB 4.2.x. Compiles and passes tests; new
Gregory P. Smith <greg@mad-scientist.com>
parents: 30474
diff changeset
53 # import _pybsddb binary as it should be the more recent version from
185c5f6b6157 Adds basic support for BerkeleyDB 4.2.x. Compiles and passes tests; new
Gregory P. Smith <greg@mad-scientist.com>
parents: 30474
diff changeset
54 # a standalone pybsddb addon package than the version included with
185c5f6b6157 Adds basic support for BerkeleyDB 4.2.x. Compiles and passes tests; new
Gregory P. Smith <greg@mad-scientist.com>
parents: 30474
diff changeset
55 # python as bsddb._bsddb.
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
56 if absolute_import :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
57 # Because this syntaxis is not valid before Python 2.5
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
58 exec("from . import _pybsddb")
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
59 else :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
60 import _pybsddb
30475
185c5f6b6157 Adds basic support for BerkeleyDB 4.2.x. Compiles and passes tests; new
Gregory P. Smith <greg@mad-scientist.com>
parents: 30474
diff changeset
61 _bsddb = _pybsddb
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
62 from bsddb3.dbutils import DeadlockWrap as _DeadlockWrap
30475
185c5f6b6157 Adds basic support for BerkeleyDB 4.2.x. Compiles and passes tests; new
Gregory P. Smith <greg@mad-scientist.com>
parents: 30474
diff changeset
63 else:
185c5f6b6157 Adds basic support for BerkeleyDB 4.2.x. Compiles and passes tests; new
Gregory P. Smith <greg@mad-scientist.com>
parents: 30474
diff changeset
64 import _bsddb
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
65 from bsddb.dbutils import DeadlockWrap as _DeadlockWrap
26390
a8cadfb0ff83 Delete bsddb from sys.modules if _bsddb cannot be imported.
Martin v. Löwis <martin@v.loewis.de>
parents: 26280
diff changeset
66 except ImportError:
a8cadfb0ff83 Delete bsddb from sys.modules if _bsddb cannot be imported.
Martin v. Löwis <martin@v.loewis.de>
parents: 26280
diff changeset
67 # Remove ourselves from sys.modules
a8cadfb0ff83 Delete bsddb from sys.modules if _bsddb cannot be imported.
Martin v. Löwis <martin@v.loewis.de>
parents: 26280
diff changeset
68 import sys
a8cadfb0ff83 Delete bsddb from sys.modules if _bsddb cannot be imported.
Martin v. Löwis <martin@v.loewis.de>
parents: 26280
diff changeset
69 del sys.modules[__name__]
a8cadfb0ff83 Delete bsddb from sys.modules if _bsddb cannot be imported.
Martin v. Löwis <martin@v.loewis.de>
parents: 26280
diff changeset
70 raise
28774
c9bee11eaa8b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27479
diff changeset
71
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
72 # bsddb3 calls it db, but provide _db for backwards compatibility
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
73 db = _db = _bsddb
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
74 __version__ = db.__version__
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
75
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
76 error = db.DBError # So bsddb.error will mean something...
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
77
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
78 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
79
32424
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
80 import sys, os
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
81
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
82 from weakref import ref
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
83
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
84 if sys.version_info[0:2] <= (2, 5) :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
85 import UserDict
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
86 MutableMapping = UserDict.DictMixin
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
87 else :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
88 import collections
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
89 MutableMapping = collections.MutableMapping
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
90
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
91 class _iter_mixin(MutableMapping):
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
92 def _make_iter_cursor(self):
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
93 cur = _DeadlockWrap(self.db.cursor)
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
94 key = id(cur)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
95 self._cursor_refs[key] = ref(cur, self._gen_cref_cleaner(key))
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
96 return cur
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
97
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
98 def _gen_cref_cleaner(self, key):
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
99 # use generate the function for the weakref callback here
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
100 # to ensure that we do not hold a strict reference to cur
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
101 # in the callback.
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
102 return lambda ref: self._cursor_refs.pop(key, None)
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
103
30474
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
104 def __iter__(self):
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
105 self._kill_iteration = False
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
106 self._in_iter += 1
30474
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
107 try:
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
108 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
109 cur = self._make_iter_cursor()
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
110
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
111 # FIXME-20031102-greg: race condition. cursor could
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
112 # be closed by another thread before this call.
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
113
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
114 # since we're only returning keys, we call the cursor
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
115 # methods with flags=0, dlen=0, dofs=0
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
116 key = _DeadlockWrap(cur.first, 0,0,0)[0]
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
117 yield key
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
118
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
119 next = getattr(cur, "next")
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
120 while 1:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
121 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
122 key = _DeadlockWrap(next, 0,0,0)[0]
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
123 yield key
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
124 except _bsddb.DBCursorClosedError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
125 if self._kill_iteration:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
126 raise RuntimeError('Database changed size '
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
127 'during iteration.')
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
128 cur = self._make_iter_cursor()
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
129 # FIXME-20031101-greg: race condition. cursor could
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
130 # be closed by another thread before this call.
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
131 _DeadlockWrap(cur.set, key,0,0,0)
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
132 next = getattr(cur, "next")
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
133 except _bsddb.DBNotFoundError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
134 pass
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
135 except _bsddb.DBCursorClosedError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
136 # the database was modified during iteration. abort.
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
137 pass
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
138 # When Python 2.3 not supported in bsddb3, we can change this to "finally"
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
139 except :
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
140 self._in_iter -= 1
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
141 raise
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
142
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
143 self._in_iter -= 1
30474
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
144
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
145 def iteritems(self):
36584
989aa285edb9 Add a unit test for bug fix #1396678.
Georg Brandl <georg@python.org>
parents: 36583
diff changeset
146 if not self.db:
989aa285edb9 Add a unit test for bug fix #1396678.
Georg Brandl <georg@python.org>
parents: 36583
diff changeset
147 return
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
148 self._kill_iteration = False
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
149 self._in_iter += 1
30474
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
150 try:
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
151 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
152 cur = self._make_iter_cursor()
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
153
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
154 # FIXME-20031102-greg: race condition. cursor could
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
155 # be closed by another thread before this call.
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
156
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
157 kv = _DeadlockWrap(cur.first)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
158 key = kv[0]
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
159 yield kv
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
160
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
161 next = getattr(cur, "next")
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
162 while 1:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
163 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
164 kv = _DeadlockWrap(next)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
165 key = kv[0]
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
166 yield kv
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
167 except _bsddb.DBCursorClosedError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
168 if self._kill_iteration:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
169 raise RuntimeError('Database changed size '
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
170 'during iteration.')
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
171 cur = self._make_iter_cursor()
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
172 # FIXME-20031101-greg: race condition. cursor could
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
173 # be closed by another thread before this call.
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
174 _DeadlockWrap(cur.set, key,0,0,0)
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
175 next = getattr(cur, "next")
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
176 except _bsddb.DBNotFoundError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
177 pass
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
178 except _bsddb.DBCursorClosedError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
179 # the database was modified during iteration. abort.
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
180 pass
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
181 # When Python 2.3 not supported in bsddb3, we can change this to "finally"
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
182 except :
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
183 self._in_iter -= 1
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
184 raise
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
185
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
186 self._in_iter -= 1
30474
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
187
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
188
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
189 class _DBWithCursor(_iter_mixin):
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
190 """
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
191 A simple wrapper around DB that makes it look like the bsddbobject in
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
192 the old module. It uses a cursor as needed to provide DB traversal.
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
193 """
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
194 def __init__(self, db):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
195 self.db = db
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
196 self.db.set_get_returns_none(0)
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
197
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
198 # FIXME-20031101-greg: I believe there is still the potential
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
199 # for deadlocks in a multithreaded environment if someone
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
200 # attempts to use the any of the cursor interfaces in one
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
201 # thread while doing a put or delete in another thread. The
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
202 # reason is that _checkCursor and _closeCursors are not atomic
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
203 # operations. Doing our own locking around self.dbc,
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
204 # self.saved_dbc_key and self._cursor_refs could prevent this.
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
205 # TODO: A test case demonstrating the problem needs to be written.
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
206
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
207 # self.dbc is a DBCursor object used to implement the
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
208 # first/next/previous/last/set_location methods.
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
209 self.dbc = None
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
210 self.saved_dbc_key = None
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
211
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
212 # a collection of all DBCursor objects currently allocated
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
213 # by the _iter_mixin interface.
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
214 self._cursor_refs = {}
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
215 self._in_iter = 0
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
216 self._kill_iteration = False
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
217
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
218 def __del__(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
219 self.close()
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
220
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
221 def _checkCursor(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
222 if self.dbc is None:
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
223 self.dbc = _DeadlockWrap(self.db.cursor)
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
224 if self.saved_dbc_key is not None:
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
225 _DeadlockWrap(self.dbc.set, self.saved_dbc_key)
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
226 self.saved_dbc_key = None
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
227
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
228 # This method is needed for all non-cursor DB calls to avoid
46984
e4e3b3eba226 Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents: 42767
diff changeset
229 # Berkeley DB deadlocks (due to being opened with DB_INIT_LOCK
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
230 # and DB_THREAD to be thread safe) when intermixing database
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
231 # operations that use the cursor internally with those that don't.
31371
f84d2bc6831d __init__.py: keep it compatible with older python (True and False == 1 and 0)
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
232 def _closeCursors(self, save=1):
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
233 if self.dbc:
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
234 c = self.dbc
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
235 self.dbc = None
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
236 if save:
36626
1e3968fcac68 Bug #1210377: close bsddb cursor correctly after NotFoundError.
Georg Brandl <georg@python.org>
parents: 36584
diff changeset
237 try:
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
238 self.saved_dbc_key = _DeadlockWrap(c.current, 0,0,0)[0]
36626
1e3968fcac68 Bug #1210377: close bsddb cursor correctly after NotFoundError.
Georg Brandl <georg@python.org>
parents: 36584
diff changeset
239 except db.DBError:
36630
eb0977932e2d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 36626
diff changeset
240 pass
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
241 _DeadlockWrap(c.close)
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
242 del c
30848
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
243 for cref in self._cursor_refs.values():
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
244 c = cref()
931a58f27ebb * Use weakref's of DBCursor objects for the iterator cursors to avoid a
Gregory P. Smith <greg@mad-scientist.com>
parents: 30837
diff changeset
245 if c is not None:
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
246 _DeadlockWrap(c.close)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
247
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
248 def _checkOpen(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
249 if self.db is None:
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
250 raise error, "BSDDB object has already been closed"
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
251
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
252 def isOpen(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
253 return self.db is not None
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
254
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
255 def __len__(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
256 self._checkOpen()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
257 return _DeadlockWrap(lambda: len(self.db)) # len(self.db)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
258
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
259 if sys.version_info[0:2] >= (2, 6) :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
260 def __repr__(self) :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
261 if self.isOpen() :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
262 return repr(dict(_DeadlockWrap(self.db.items)))
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
263 return repr(dict())
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
264
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
265 def __getitem__(self, key):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
266 self._checkOpen()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
267 return _DeadlockWrap(lambda: self.db[key]) # self.db[key]
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
268
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
269 def __setitem__(self, key, value):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
270 self._checkOpen()
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
271 self._closeCursors()
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
272 if self._in_iter and key not in self:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
273 self._kill_iteration = True
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
274 def wrapF():
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
275 self.db[key] = value
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
276 _DeadlockWrap(wrapF) # self.db[key] = value
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
277
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
278 def __delitem__(self, key):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
279 self._checkOpen()
30837
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
280 self._closeCursors()
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
281 if self._in_iter and key in self:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
282 self._kill_iteration = True
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
283 def wrapF():
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
284 del self.db[key]
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
285 _DeadlockWrap(wrapF) # del self.db[key]
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
286
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
287 def close(self):
31371
f84d2bc6831d __init__.py: keep it compatible with older python (True and False == 1 and 0)
Gregory P. Smith <greg@mad-scientist.com>
parents: 30848
diff changeset
288 self._closeCursors(save=0)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
289 if self.dbc is not None:
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
290 _DeadlockWrap(self.dbc.close)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
291 v = 0
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
292 if self.db is not None:
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
293 v = _DeadlockWrap(self.db.close)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
294 self.dbc = None
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
295 self.db = None
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
296 return v
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
297
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
298 def keys(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
299 self._checkOpen()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
300 return _DeadlockWrap(self.db.keys)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
301
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
302 def has_key(self, key):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
303 self._checkOpen()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
304 return _DeadlockWrap(self.db.has_key, key)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
305
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
306 def set_location(self, key):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
307 self._checkOpen()
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
308 self._checkCursor()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
309 return _DeadlockWrap(self.dbc.set_range, key)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
310
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
311 def next(self): # Renamed by "2to3"
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
312 self._checkOpen()
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
313 self._checkCursor()
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
314 rv = _DeadlockWrap(getattr(self.dbc, "next"))
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
315 return rv
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
316
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
317 if sys.version_info[0] >= 3 : # For "2to3" conversion
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
318 next = __next__
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
319
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
320 def previous(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
321 self._checkOpen()
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
322 self._checkCursor()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
323 rv = _DeadlockWrap(self.dbc.prev)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
324 return rv
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
325
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
326 def first(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
327 self._checkOpen()
42767
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 38840
diff changeset
328 # fix 1725856: don't needlessly try to restore our cursor position
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 38840
diff changeset
329 self.saved_dbc_key = None
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
330 self._checkCursor()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
331 rv = _DeadlockWrap(self.dbc.first)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
332 return rv
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
333
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
334 def last(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
335 self._checkOpen()
42767
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 38840
diff changeset
336 # fix 1725856: don't needlessly try to restore our cursor position
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 38840
diff changeset
337 self.saved_dbc_key = None
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
338 self._checkCursor()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
339 rv = _DeadlockWrap(self.dbc.last)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
340 return rv
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
341
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
342 def sync(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
343 self._checkOpen()
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
344 return _DeadlockWrap(self.db.sync)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
345
30422
4d204fc3ad32 The previous change works much faster (one lookup per key) when
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
346
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
347 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
348 # Compatibility object factory functions
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
349
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
350 def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None,
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
351 cachesize=None, lorder=None, hflags=0):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
352
32424
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
353 flags = _checkflag(flag, file)
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
354 e = _openDBEnv(cachesize)
30583
d34b6f92dd32 Use a threadsafe private DBEnv for each bsddb compatibility interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 30475
diff changeset
355 d = db.DB(e)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
356 d.set_flags(hflags)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
357 if pgsize is not None: d.set_pagesize(pgsize)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
358 if lorder is not None: d.set_lorder(lorder)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
359 if ffactor is not None: d.set_h_ffactor(ffactor)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
360 if nelem is not None: d.set_h_nelem(nelem)
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
361 d.open(file, db.DB_HASH, flags, mode)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
362 return _DBWithCursor(d)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
363
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
364 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
365
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
366 def btopen(file, flag='c', mode=0666,
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
367 btflags=0, cachesize=None, maxkeypage=None, minkeypage=None,
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
368 pgsize=None, lorder=None):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
369
32424
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
370 flags = _checkflag(flag, file)
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
371 e = _openDBEnv(cachesize)
30583
d34b6f92dd32 Use a threadsafe private DBEnv for each bsddb compatibility interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 30475
diff changeset
372 d = db.DB(e)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
373 if pgsize is not None: d.set_pagesize(pgsize)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
374 if lorder is not None: d.set_lorder(lorder)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
375 d.set_flags(btflags)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
376 if minkeypage is not None: d.set_bt_minkey(minkeypage)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
377 if maxkeypage is not None: d.set_bt_maxkey(maxkeypage)
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
378 d.open(file, db.DB_BTREE, flags, mode)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
379 return _DBWithCursor(d)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
380
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
381 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
382
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
383
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
384 def rnopen(file, flag='c', mode=0666,
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
385 rnflags=0, cachesize=None, pgsize=None, lorder=None,
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
386 rlen=None, delim=None, source=None, pad=None):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
387
32424
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
388 flags = _checkflag(flag, file)
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
389 e = _openDBEnv(cachesize)
30583
d34b6f92dd32 Use a threadsafe private DBEnv for each bsddb compatibility interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 30475
diff changeset
390 d = db.DB(e)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
391 if pgsize is not None: d.set_pagesize(pgsize)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
392 if lorder is not None: d.set_lorder(lorder)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
393 d.set_flags(rnflags)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
394 if delim is not None: d.set_re_delim(delim)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
395 if rlen is not None: d.set_re_len(rlen)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
396 if source is not None: d.set_re_source(source)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
397 if pad is not None: d.set_re_pad(pad)
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
398 d.open(file, db.DB_RECNO, flags, mode)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
399 return _DBWithCursor(d)
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
400
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
401 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
402
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
403 def _openDBEnv(cachesize):
30583
d34b6f92dd32 Use a threadsafe private DBEnv for each bsddb compatibility interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 30475
diff changeset
404 e = db.DBEnv()
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
405 if cachesize is not None:
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
406 if cachesize >= 20480:
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
407 e.set_cachesize(0, cachesize)
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
408 else:
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
409 raise error, "cachesize must be >= 20480"
38658
1e0704cd9ee8 pasted set_lk_detect line in wrong spot in previous commit. fixed. passes tests this time.
Gregory P. Smith <greg@mad-scientist.com>
parents: 38657
diff changeset
410 e.set_lk_detect(db.DB_LOCK_DEFAULT)
30583
d34b6f92dd32 Use a threadsafe private DBEnv for each bsddb compatibility interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 30475
diff changeset
411 e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL)
d34b6f92dd32 Use a threadsafe private DBEnv for each bsddb compatibility interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 30475
diff changeset
412 return e
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
413
32424
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
414 def _checkflag(flag, file):
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
415 if flag == 'r':
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
416 flags = db.DB_RDONLY
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
417 elif flag == 'rw':
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
418 flags = 0
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
419 elif flag == 'w':
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
420 flags = db.DB_CREATE
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
421 elif flag == 'c':
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
422 flags = db.DB_CREATE
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
423 elif flag == 'n':
32424
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
424 flags = db.DB_CREATE
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
425 #flags = db.DB_CREATE | db.DB_TRUNCATE
46984
e4e3b3eba226 Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents: 42767
diff changeset
426 # we used db.DB_TRUNCATE flag for this before but Berkeley DB
32424
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
427 # 4.2.52 changed to disallowed truncate with txn environments.
37644
c6e11f804d00 Closes bug #1149413
Gregory P. Smith <greg@mad-scientist.com>
parents: 36630
diff changeset
428 if file is not None and os.path.isfile(file):
32424
3ddc7a23176b Fix SF bug # 897820 - we can no longer use the DB_TRUNCATE flag when
Gregory P. Smith <greg@mad-scientist.com>
parents: 31587
diff changeset
429 os.unlink(file)
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
430 else:
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
431 raise error, "flags should be one of 'r', 'w', 'c' or 'n'"
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
432 return flags | db.DB_THREAD
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
433
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
434 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
435
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
436
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
437 # This is a silly little hack that allows apps to continue to use the
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
438 # DB_THREAD flag even on systems without threads without freaking out
46984
e4e3b3eba226 Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents: 42767
diff changeset
439 # Berkeley DB.
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
440 #
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
441 # This assumes that if Python was built with thread support then
46984
e4e3b3eba226 Testsuite for bsddb module, version 4.6.4
Jesus Cea <jcea@jcea.es>
parents: 42767
diff changeset
442 # Berkeley DB was too.
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
443
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
444 try:
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
445 import thread
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
446 del thread
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
447 except ImportError:
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
448 db.DB_THREAD = 0
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
449
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
450 #----------------------------------------------------------------------