blob: b74ee72f76b5307469e882663b1fe5b1d495331b [file] [log] [blame]
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +00001#-------------------------------------------------------------------------
2# This file contains real Python object wrappers for DB and DBEnv
3# C "objects" that can be usefully subclassed. The previous SWIG
4# based interface allowed this thanks to SWIG's shadow classes.
5# -- Gregory P. Smith
6#-------------------------------------------------------------------------
7#
8# (C) Copyright 2001 Autonomous Zone Industries
9#
10# License: This is free software. You may use this software for any
11# purpose including modification/redistribution, so long as
12# this header remains intact and that you do not claim any
13# rights of ownership or authorship of this software. This
14# software has been tested, but no warranty is expressed or
15# implied.
16#
17
Gregory P. Smith455d46f2003-07-09 04:45:59 +000018#
19# TODO it would be *really nice* to have an automatic shadow class populator
20# so that new methods don't need to be added here manually after being
21# added to _bsddb.c.
22#
23
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +000024import db
Barry Warsaw99142272003-02-08 03:18:58 +000025
26try:
27 from UserDict import DictMixin
28except ImportError:
29 # DictMixin is new in Python 2.3
30 class DictMixin: pass
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +000031
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +000032class DBEnv:
33 def __init__(self, *args, **kwargs):
34 self._cobj = apply(db.DBEnv, args, kwargs)
35
36 def close(self, *args, **kwargs):
37 return apply(self._cobj.close, args, kwargs)
38 def open(self, *args, **kwargs):
39 return apply(self._cobj.open, args, kwargs)
40 def remove(self, *args, **kwargs):
41 return apply(self._cobj.remove, args, kwargs)
Gregory P. Smith6676f6e2003-08-28 21:50:30 +000042 def set_shm_key(self, *args, **kwargs):
43 return apply(self._cobj.set_shm_key, args, kwargs)
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +000044 def set_cachesize(self, *args, **kwargs):
45 return apply(self._cobj.set_cachesize, args, kwargs)
46 def set_data_dir(self, *args, **kwargs):
47 return apply(self._cobj.set_data_dir, args, kwargs)
48 def set_flags(self, *args, **kwargs):
49 return apply(self._cobj.set_flags, args, kwargs)
50 def set_lg_bsize(self, *args, **kwargs):
51 return apply(self._cobj.set_lg_bsize, args, kwargs)
52 def set_lg_dir(self, *args, **kwargs):
53 return apply(self._cobj.set_lg_dir, args, kwargs)
54 def set_lg_max(self, *args, **kwargs):
55 return apply(self._cobj.set_lg_max, args, kwargs)
56 def set_lk_detect(self, *args, **kwargs):
57 return apply(self._cobj.set_lk_detect, args, kwargs)
Gregory P. Smith8b96a352007-01-05 01:59:42 +000058 if db.version() < (4,5):
59 def set_lk_max(self, *args, **kwargs):
60 return apply(self._cobj.set_lk_max, args, kwargs)
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +000061 def set_lk_max_locks(self, *args, **kwargs):
62 return apply(self._cobj.set_lk_max_locks, args, kwargs)
63 def set_lk_max_lockers(self, *args, **kwargs):
64 return apply(self._cobj.set_lk_max_lockers, args, kwargs)
65 def set_lk_max_objects(self, *args, **kwargs):
66 return apply(self._cobj.set_lk_max_objects, args, kwargs)
67 def set_mp_mmapsize(self, *args, **kwargs):
68 return apply(self._cobj.set_mp_mmapsize, args, kwargs)
Gregory P. Smith455d46f2003-07-09 04:45:59 +000069 def set_timeout(self, *args, **kwargs):
70 return apply(self._cobj.set_timeout, args, kwargs)
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +000071 def set_tmp_dir(self, *args, **kwargs):
72 return apply(self._cobj.set_tmp_dir, args, kwargs)
73 def txn_begin(self, *args, **kwargs):
74 return apply(self._cobj.txn_begin, args, kwargs)
75 def txn_checkpoint(self, *args, **kwargs):
76 return apply(self._cobj.txn_checkpoint, args, kwargs)
77 def txn_stat(self, *args, **kwargs):
78 return apply(self._cobj.txn_stat, args, kwargs)
79 def set_tx_max(self, *args, **kwargs):
80 return apply(self._cobj.set_tx_max, args, kwargs)
Gregory P. Smith3d344e82006-01-27 07:06:15 +000081 def set_tx_timestamp(self, *args, **kwargs):
82 return apply(self._cobj.set_tx_timestamp, args, kwargs)
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +000083 def lock_detect(self, *args, **kwargs):
84 return apply(self._cobj.lock_detect, args, kwargs)
85 def lock_get(self, *args, **kwargs):
86 return apply(self._cobj.lock_get, args, kwargs)
87 def lock_id(self, *args, **kwargs):
88 return apply(self._cobj.lock_id, args, kwargs)
89 def lock_put(self, *args, **kwargs):
90 return apply(self._cobj.lock_put, args, kwargs)
91 def lock_stat(self, *args, **kwargs):
92 return apply(self._cobj.lock_stat, args, kwargs)
93 def log_archive(self, *args, **kwargs):
94 return apply(self._cobj.log_archive, args, kwargs)
Gregory P. Smithdb8a8072006-06-05 01:56:15 +000095
96 def set_get_returns_none(self, *args, **kwargs):
97 return apply(self._cobj.set_get_returns_none, args, kwargs)
98
Gregory P. Smith76a82e82006-06-05 01:39:52 +000099 if db.version() >= (4,0):
Tim Peters7140de02006-06-05 01:47:24 +0000100 def log_stat(self, *args, **kwargs):
101 return apply(self._cobj.log_stat, args, kwargs)
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000102
Barry Warsaw9a0d7792002-12-30 20:53:52 +0000103 if db.version() >= (4,1):
104 def dbremove(self, *args, **kwargs):
105 return apply(self._cobj.dbremove, args, kwargs)
106 def dbrename(self, *args, **kwargs):
107 return apply(self._cobj.dbrename, args, kwargs)
108 def set_encrypt(self, *args, **kwargs):
109 return apply(self._cobj.set_encrypt, args, kwargs)
110
Gregory P. Smithdb8a8072006-06-05 01:56:15 +0000111 if db.version() >= (4,4):
Tim Petersd6024d32006-06-05 18:36:12 +0000112 def lsn_reset(self, *args, **kwargs):
113 return apply(self._cobj.lsn_reset, args, kwargs)
Gregory P. Smithdb8a8072006-06-05 01:56:15 +0000114
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000115
Raymond Hettinger30a634e2003-02-05 04:12:41 +0000116class DB(DictMixin):
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000117 def __init__(self, dbenv, *args, **kwargs):
118 # give it the proper DBEnv C object that its expecting
119 self._cobj = apply(db.DB, (dbenv._cobj,) + args, kwargs)
120
121 # TODO are there other dict methods that need to be overridden?
122 def __len__(self):
123 return len(self._cobj)
124 def __getitem__(self, arg):
125 return self._cobj[arg]
126 def __setitem__(self, key, value):
127 self._cobj[key] = value
128 def __delitem__(self, arg):
129 del self._cobj[arg]
130
131 def append(self, *args, **kwargs):
132 return apply(self._cobj.append, args, kwargs)
133 def associate(self, *args, **kwargs):
134 return apply(self._cobj.associate, args, kwargs)
135 def close(self, *args, **kwargs):
136 return apply(self._cobj.close, args, kwargs)
137 def consume(self, *args, **kwargs):
138 return apply(self._cobj.consume, args, kwargs)
139 def consume_wait(self, *args, **kwargs):
140 return apply(self._cobj.consume_wait, args, kwargs)
141 def cursor(self, *args, **kwargs):
142 return apply(self._cobj.cursor, args, kwargs)
143 def delete(self, *args, **kwargs):
144 return apply(self._cobj.delete, args, kwargs)
145 def fd(self, *args, **kwargs):
146 return apply(self._cobj.fd, args, kwargs)
147 def get(self, *args, **kwargs):
148 return apply(self._cobj.get, args, kwargs)
Gregory P. Smith19699a92004-06-28 04:06:49 +0000149 def pget(self, *args, **kwargs):
150 return apply(self._cobj.pget, args, kwargs)
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000151 def get_both(self, *args, **kwargs):
152 return apply(self._cobj.get_both, args, kwargs)
153 def get_byteswapped(self, *args, **kwargs):
154 return apply(self._cobj.get_byteswapped, args, kwargs)
155 def get_size(self, *args, **kwargs):
156 return apply(self._cobj.get_size, args, kwargs)
157 def get_type(self, *args, **kwargs):
158 return apply(self._cobj.get_type, args, kwargs)
159 def join(self, *args, **kwargs):
160 return apply(self._cobj.join, args, kwargs)
161 def key_range(self, *args, **kwargs):
162 return apply(self._cobj.key_range, args, kwargs)
163 def has_key(self, *args, **kwargs):
164 return apply(self._cobj.has_key, args, kwargs)
165 def items(self, *args, **kwargs):
166 return apply(self._cobj.items, args, kwargs)
167 def keys(self, *args, **kwargs):
168 return apply(self._cobj.keys, args, kwargs)
169 def open(self, *args, **kwargs):
170 return apply(self._cobj.open, args, kwargs)
171 def put(self, *args, **kwargs):
172 return apply(self._cobj.put, args, kwargs)
173 def remove(self, *args, **kwargs):
174 return apply(self._cobj.remove, args, kwargs)
175 def rename(self, *args, **kwargs):
176 return apply(self._cobj.rename, args, kwargs)
177 def set_bt_minkey(self, *args, **kwargs):
178 return apply(self._cobj.set_bt_minkey, args, kwargs)
Gregory P. Smithe4ed2de2005-06-03 07:03:07 +0000179 def set_bt_compare(self, *args, **kwargs):
180 return apply(self._cobj.set_bt_compare, args, kwargs)
Martin v. Löwis6aa4a1f2002-11-19 08:09:52 +0000181 def set_cachesize(self, *args, **kwargs):
182 return apply(self._cobj.set_cachesize, args, kwargs)
183 def set_flags(self, *args, **kwargs):
184 return apply(self._cobj.set_flags, args, kwargs)
185 def set_h_ffactor(self, *args, **kwargs):
186 return apply(self._cobj.set_h_ffactor, args, kwargs)
187 def set_h_nelem(self, *args, **kwargs):
188 return apply(self._cobj.set_h_nelem, args, kwargs)
189 def set_lorder(self, *args, **kwargs):
190 return apply(self._cobj.set_lorder, args, kwargs)
191 def set_pagesize(self, *args, **kwargs):
192 return apply(self._cobj.set_pagesize, args, kwargs)
193 def set_re_delim(self, *args, **kwargs):
194 return apply(self._cobj.set_re_delim, args, kwargs)
195 def set_re_len(self, *args, **kwargs):
196 return apply(self._cobj.set_re_len, args, kwargs)
197 def set_re_pad(self, *args, **kwargs):
198 return apply(self._cobj.set_re_pad, args, kwargs)
199 def set_re_source(self, *args, **kwargs):
200 return apply(self._cobj.set_re_source, args, kwargs)
201 def set_q_extentsize(self, *args, **kwargs):
202 return apply(self._cobj.set_q_extentsize, args, kwargs)
203 def stat(self, *args, **kwargs):
204 return apply(self._cobj.stat, args, kwargs)
205 def sync(self, *args, **kwargs):
206 return apply(self._cobj.sync, args, kwargs)
207 def type(self, *args, **kwargs):
208 return apply(self._cobj.type, args, kwargs)
209 def upgrade(self, *args, **kwargs):
210 return apply(self._cobj.upgrade, args, kwargs)
211 def values(self, *args, **kwargs):
212 return apply(self._cobj.values, args, kwargs)
213 def verify(self, *args, **kwargs):
214 return apply(self._cobj.verify, args, kwargs)
215 def set_get_returns_none(self, *args, **kwargs):
216 return apply(self._cobj.set_get_returns_none, args, kwargs)
Barry Warsaw9a0d7792002-12-30 20:53:52 +0000217
218 if db.version() >= (4,1):
219 def set_encrypt(self, *args, **kwargs):
220 return apply(self._cobj.set_encrypt, args, kwargs)
Gregory P. Smithf0547d02006-06-05 17:38:04 +0000221
222
223class DBSequence:
224 def __init__(self, *args, **kwargs):
225 self._cobj = apply(db.DBSequence, args, kwargs)
226
227 def close(self, *args, **kwargs):
228 return apply(self._cobj.close, args, kwargs)
229 def get(self, *args, **kwargs):
230 return apply(self._cobj.get, args, kwargs)
231 def get_dbp(self, *args, **kwargs):
232 return apply(self._cobj.get_dbp, args, kwargs)
233 def get_key(self, *args, **kwargs):
234 return apply(self._cobj.get_key, args, kwargs)
235 def init_value(self, *args, **kwargs):
236 return apply(self._cobj.init_value, args, kwargs)
237 def open(self, *args, **kwargs):
238 return apply(self._cobj.open, args, kwargs)
239 def remove(self, *args, **kwargs):
240 return apply(self._cobj.remove, args, kwargs)
241 def stat(self, *args, **kwargs):
242 return apply(self._cobj.stat, args, kwargs)
243 def set_cachesize(self, *args, **kwargs):
244 return apply(self._cobj.set_cachesize, args, kwargs)
245 def set_flags(self, *args, **kwargs):
246 return apply(self._cobj.set_flags, args, kwargs)
247 def set_range(self, *args, **kwargs):
248 return apply(self._cobj.set_range, args, kwargs)
249 def get_cachesize(self, *args, **kwargs):
250 return apply(self._cobj.get_cachesize, args, kwargs)
251 def get_flags(self, *args, **kwargs):
252 return apply(self._cobj.get_flags, args, kwargs)
253 def get_range(self, *args, **kwargs):
254 return apply(self._cobj.get_range, args, kwargs)