annotate Lib/bsddb/__init__.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents c21bc80c83f6
children 83fd64c97296
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
59902
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
36 """Support for Berkeley DB 4.1 through 4.8 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
59902
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
45 if (sys.version_info >= (2, 6)) and (sys.version_info < (3, 0)) :
60268
da34d1f43cb0 remove deprecation warnings silence attempting
Benjamin Peterson <benjamin@python.org>
parents: 60261
diff changeset
46 import warnings
59902
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
47 if sys.py3kwarning and (__name__ != 'bsddb3') :
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
48 warnings.warnpy3k("in 3.x, the bsddb module has been removed; "
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
49 "please use the pybsddb project instead",
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
50 DeprecationWarning, 2)
60270
c21bc80c83f6 stop CObject deprecation warnings in test___all__
Benjamin Peterson <benjamin@python.org>
parents: 60268
diff changeset
51 warnings.filterwarnings("ignore", ".*CObject.*", DeprecationWarning,
c21bc80c83f6 stop CObject deprecation warnings in test___all__
Benjamin Peterson <benjamin@python.org>
parents: 60268
diff changeset
52 "bsddb.__init__")
49028
b45868fe489c Deprecate bsddb for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 48950
diff changeset
53
26390
a8cadfb0ff83 Delete bsddb from sys.modules if _bsddb cannot be imported.
Martin v. Löwis <martin@v.loewis.de>
parents: 26280
diff changeset
54 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
55 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
56 # 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
57 # 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
58 # python as bsddb._bsddb.
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
59 if absolute_import :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
60 # 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
61 exec("from . import _pybsddb")
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
62 else :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
63 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
64 _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
65 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
66 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
67 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
68 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
69 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
70 # 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
71 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
72 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
73 raise
28774
c9bee11eaa8b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27479
diff changeset
74
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
75 # 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
76 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
77 __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
78
27479
14b1758dfdde Everything worked in both the distutils distro and in Python 2.3cvs,
Barry Warsaw <barry@python.org>
parents: 26878
diff changeset
79 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
80
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
81 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
82
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
83 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
84
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
85 from weakref import ref
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
86
59902
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
87 if sys.version_info < (2, 6) :
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
88 import UserDict
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
89 MutableMapping = UserDict.DictMixin
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
90 else :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
91 import collections
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
92 MutableMapping = collections.MutableMapping
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
93
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
94 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
95 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
96 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
97 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
98 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
99 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
100
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 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
102 # 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
103 # 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
104 # 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
105 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
106
30474
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
107 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
108 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
109 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
110 try:
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
111 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
112 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
113
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
114 # 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
115 # 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
116
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
117 # 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
118 # 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
119 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
120 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
121
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
122 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
123 while 1:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
124 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
125 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
126 yield key
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
127 except _bsddb.DBCursorClosedError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
128 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
129 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
130 'during iteration.')
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
131 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
132 # 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
133 # 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
134 _DeadlockWrap(cur.set, key,0,0,0)
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
135 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
136 except _bsddb.DBNotFoundError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
137 pass
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
138 except _bsddb.DBCursorClosedError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
139 # 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
140 pass
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
141 # 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
142 except :
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
143 self._in_iter -= 1
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
144 raise
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
145
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
146 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
147
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
148 def iteritems(self):
36584
989aa285edb9 Add a unit test for bug fix #1396678.
Georg Brandl <georg@python.org>
parents: 36583
diff changeset
149 if not self.db:
989aa285edb9 Add a unit test for bug fix #1396678.
Georg Brandl <georg@python.org>
parents: 36583
diff changeset
150 return
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
151 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
152 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
153 try:
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
154 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
155 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
156
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
157 # 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
158 # 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
159
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
160 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
161 key = kv[0]
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
162 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
163
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
164 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
165 while 1:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
166 try:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
167 kv = _DeadlockWrap(next)
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
168 key = kv[0]
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
169 yield kv
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
170 except _bsddb.DBCursorClosedError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
171 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
172 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
173 'during iteration.')
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
174 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
175 # 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
176 # 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
177 _DeadlockWrap(cur.set, key,0,0,0)
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
178 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
179 except _bsddb.DBNotFoundError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
180 pass
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
181 except _bsddb.DBCursorClosedError:
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
182 # 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
183 pass
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
184 # 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
185 except :
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
186 self._in_iter -= 1
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
187 raise
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
188
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
189 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
190
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
191
8dd07f7d093b Maintain backwards compatibility with python < 2.3 by dynamically
Gregory P. Smith <greg@mad-scientist.com>
parents: 30422
diff changeset
192 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
193 """
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
194 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
195 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
196 """
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
197 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
198 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
199 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
200
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
201 # 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
202 # 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
203 # 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
204 # 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
205 # 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
206 # 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
207 # 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
208 # 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
209
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
210 # 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
211 # 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
212 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
213 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
214
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
215 # 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
216 # 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
217 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
218 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
219 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
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 __del__(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
222 self.close()
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
223
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
224 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
225 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
226 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
227 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
228 _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
229 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
230
e676c95e4844 * Fix the singlethreaded deadlocks occurring in the simple bsddb interface.
Gregory P. Smith <greg@mad-scientist.com>
parents: 30583
diff changeset
231 # 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
232 # 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
233 # 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
234 # 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
235 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
236 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
237 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
238 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
239 if save:
36626
1e3968fcac68 Bug #1210377: close bsddb cursor correctly after NotFoundError.
Georg Brandl <georg@python.org>
parents: 36584
diff changeset
240 try:
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
241 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
242 except db.DBError:
36630
eb0977932e2d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 36626
diff changeset
243 pass
38840
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
244 _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
245 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
246 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
247 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
248 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
249 _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
250
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
251 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
252 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
253 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
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 isOpen(self):
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
256 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
257
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
258 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
259 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
260 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
261
59902
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
262 if sys.version_info >= (2, 6) :
48054
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
263 def __repr__(self) :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
264 if self.isOpen() :
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
265 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
266 return repr(dict())
10f41adc0d24 bsddb module updated to version 4.7.2devel9.
Jesus Cea <jcea@jcea.es>
parents: 47257
diff changeset
267
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
268 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
269 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
270 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
271
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
272 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
273 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
274 self._closeCursors()
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
275 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
276 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
277 def wrapF():
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
278 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
279 _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
280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
281 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
282 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
283 self._closeCursors()
47257
967026257961 Fix issue2669: bsddb simple/legacy interface iteration silently fails
Gregory P. Smith <greg@mad-scientist.com>
parents: 46984
diff changeset
284 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
285 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
286 def wrapF():
9937f09d76e3 - bsddb: multithreaded DB access using the simple bsddb module interface
Gregory P. Smith <greg@mad-scientist.com>
parents: 38658
diff changeset
287 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
288 _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
289
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
290 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
291 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
292 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
293 _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
294 v = 0
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
295 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
296 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
297 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
298 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
299 return v
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
300
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
301 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
302 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
303 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
304
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
305 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
306 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
307 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
308
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
309 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
310 self._checkOpen()
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
311 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
312 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
313
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
314 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
315 self._checkOpen()
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
316 self._checkCursor()
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
317 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
318 return rv
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
319
48950
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
320 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
321 next = __next__
8c4f750661ec Improve compatibility with Python3.0 testsuite
Jesus Cea <jcea@jcea.es>
parents: 48054
diff changeset
322
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
323 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
324 self._checkOpen()
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
325 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
326 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
327 return rv
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
328
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
329 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
330 self._checkOpen()
42767
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 38840
diff changeset
331 # 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
332 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
333 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
334 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
335 return rv
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
336
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
337 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
338 self._checkOpen()
42767
05fe027e2d80 Fix bug 1725856.
Gregory P. Smith <greg@mad-scientist.com>
parents: 38840
diff changeset
339 # 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
340 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
341 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
342 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
343 return rv
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
344
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
345 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
346 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
347 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
348
30422
4d204fc3ad32 The previous change works much faster (one lookup per key) when
Raymond Hettinger <python@rcn.com>
parents: 30415
diff changeset
349
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
350 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
351 # 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
352
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
353 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
354 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
355
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
356 flags = _checkflag(flag, file)
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
357 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
358 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
359 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
360 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
361 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
362 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
363 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
364 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
365 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
366
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
367 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
368
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
369 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
370 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
371 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
372
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
373 flags = _checkflag(flag, file)
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
374 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
375 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
376 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
377 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
378 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
379 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
380 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
381 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
382 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
383
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
384 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
385
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
386
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
387 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
388 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
389 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
390
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
391 flags = _checkflag(flag, file)
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
392 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
393 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
394 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
395 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
396 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
397 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
398 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
399 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
400 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
401 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
402 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
403
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
404 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
405
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
406 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
407 e = db.DBEnv()
37645
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
408 if cachesize is not None:
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
409 if cachesize >= 20480:
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
410 e.set_cachesize(0, cachesize)
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
411 else:
2c06588ae69e Fixes bug #1117761
Gregory P. Smith <greg@mad-scientist.com>
parents: 37644
diff changeset
412 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
413 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
414 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
415 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
416
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
417 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
418 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
419 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
420 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
421 flags = 0
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
422 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
423 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
424 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
425 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
426 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
427 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
428 #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
429 # 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
430 # 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
431 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
432 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
433 else:
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
434 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
435 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
436
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
437 #----------------------------------------------------------------------
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
438
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
439
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
440 # 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
441 # 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
442 # 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
443 #
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
444 # 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
445 # 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
446
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
447 try:
59902
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
448 # 2to3 automatically changes "import thread" to "import _thread"
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
449 import thread as T
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
450 del T
96a241d4a0ab pybsddb 4.8.4 integration. Please, comment in issue #8156
Jesus Cea <jcea@jcea.es>
parents: 63528
diff changeset
451
26280
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
452 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
453 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
454
875140d30e17 Import PyBSDDB 3.4.0. Rename historical wrapper to bsddb185.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
455 #----------------------------------------------------------------------