1 #------------------------------------------------------------------------- 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 18 # 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 24 import sys 25 absolute_import = (sys.version_info[0] >= 3) 26 if absolute_import : 27 # Because this syntaxis is not valid before Python 2.5 28 exec("from . import db") 29 else : 30 import db 31 32 if sys.version_info < (2, 6) : 33 from UserDict import DictMixin as MutableMapping 34 else : 35 import collections 36 MutableMapping = collections.MutableMapping 37 38 class DBEnv: 39 def __init__(self, *args, **kwargs): 40 self._cobj = db.DBEnv(*args, **kwargs) 41 42 def close(self, *args, **kwargs): 43 return self._cobj.close(*args, **kwargs) 44 def open(self, *args, **kwargs): 45 return self._cobj.open(*args, **kwargs) 46 def remove(self, *args, **kwargs): 47 return self._cobj.remove(*args, **kwargs) 48 def set_shm_key(self, *args, **kwargs): 49 return self._cobj.set_shm_key(*args, **kwargs) 50 def set_cachesize(self, *args, **kwargs): 51 return self._cobj.set_cachesize(*args, **kwargs) 52 def set_data_dir(self, *args, **kwargs): 53 return self._cobj.set_data_dir(*args, **kwargs) 54 def set_flags(self, *args, **kwargs): 55 return self._cobj.set_flags(*args, **kwargs) 56 def set_lg_bsize(self, *args, **kwargs): 57 return self._cobj.set_lg_bsize(*args, **kwargs) 58 def set_lg_dir(self, *args, **kwargs): 59 return self._cobj.set_lg_dir(*args, **kwargs) 60 def set_lg_max(self, *args, **kwargs): 61 return self._cobj.set_lg_max(*args, **kwargs) 62 def set_lk_detect(self, *args, **kwargs): 63 return self._cobj.set_lk_detect(*args, **kwargs) 64 if db.version() < (4,5): 65 def set_lk_max(self, *args, **kwargs): 66 return self._cobj.set_lk_max(*args, **kwargs) 67 def set_lk_max_locks(self, *args, **kwargs): 68 return self._cobj.set_lk_max_locks(*args, **kwargs) 69 def set_lk_max_lockers(self, *args, **kwargs): 70 return self._cobj.set_lk_max_lockers(*args, **kwargs) 71 def set_lk_max_objects(self, *args, **kwargs): 72 return self._cobj.set_lk_max_objects(*args, **kwargs) 73 def set_mp_mmapsize(self, *args, **kwargs): 74 return self._cobj.set_mp_mmapsize(*args, **kwargs) 75 def set_timeout(self, *args, **kwargs): 76 return self._cobj.set_timeout(*args, **kwargs) 77 def set_tmp_dir(self, *args, **kwargs): 78 return self._cobj.set_tmp_dir(*args, **kwargs) 79 def txn_begin(self, *args, **kwargs): 80 return self._cobj.txn_begin(*args, **kwargs) 81 def txn_checkpoint(self, *args, **kwargs): 82 return self._cobj.txn_checkpoint(*args, **kwargs) 83 def txn_stat(self, *args, **kwargs): 84 return self._cobj.txn_stat(*args, **kwargs) 85 def set_tx_max(self, *args, **kwargs): 86 return self._cobj.set_tx_max(*args, **kwargs) 87 def set_tx_timestamp(self, *args, **kwargs): 88 return self._cobj.set_tx_timestamp(*args, **kwargs) 89 def lock_detect(self, *args, **kwargs): 90 return self._cobj.lock_detect(*args, **kwargs) 91 def lock_get(self, *args, **kwargs): 92 return self._cobj.lock_get(*args, **kwargs) 93 def lock_id(self, *args, **kwargs): 94 return self._cobj.lock_id(*args, **kwargs) 95 def lock_put(self, *args, **kwargs): 96 return self._cobj.lock_put(*args, **kwargs) 97 def lock_stat(self, *args, **kwargs): 98 return self._cobj.lock_stat(*args, **kwargs) 99 def log_archive(self, *args, **kwargs): 100 return self._cobj.log_archive(*args, **kwargs) 101 102 def set_get_returns_none(self, *args, **kwargs): 103 return self._cobj.set_get_returns_none(*args, **kwargs) 104 105 def log_stat(self, *args, **kwargs): 106 return self._cobj.log_stat(*args, **kwargs) 107 108 def dbremove(self, *args, **kwargs): 109 return self._cobj.dbremove(*args, **kwargs) 110 def dbrename(self, *args, **kwargs): 111 return self._cobj.dbrename(*args, **kwargs) 112 def set_encrypt(self, *args, **kwargs): 113 return self._cobj.set_encrypt(*args, **kwargs) 114 115 if db.version() >= (4,4): 116 def fileid_reset(self, *args, **kwargs): 117 return self._cobj.fileid_reset(*args, **kwargs) 118 119 def lsn_reset(self, *args, **kwargs): 120 return self._cobj.lsn_reset(*args, **kwargs) 121 122 123 class DB(MutableMapping): 124 def __init__(self, dbenv, *args, **kwargs): 125 # give it the proper DBEnv C object that its expecting 126 self._cobj = db.DB(*((dbenv._cobj,) + args), **kwargs) 127 128 # TODO are there other dict methods that need to be overridden? 129 def __len__(self): 130 return len(self._cobj) 131 def __getitem__(self, arg): 132 return self._cobj[arg] 133 def __setitem__(self, key, value): 134 self._cobj[key] = value 135 def __delitem__(self, arg): 136 del self._cobj[arg] 137 138 if sys.version_info >= (2, 6) : 139 def __iter__(self) : 140 return self._cobj.__iter__() 141 142 def append(self, *args, **kwargs): 143 return self._cobj.append(*args, **kwargs) 144 def associate(self, *args, **kwargs): 145 return self._cobj.associate(*args, **kwargs) 146 def close(self, *args, **kwargs): 147 return self._cobj.close(*args, **kwargs) 148 def consume(self, *args, **kwargs): 149 return self._cobj.consume(*args, **kwargs) 150 def consume_wait(self, *args, **kwargs): 151 return self._cobj.consume_wait(*args, **kwargs) 152 def cursor(self, *args, **kwargs): 153 return self._cobj.cursor(*args, **kwargs) 154 def delete(self, *args, **kwargs): 155 return self._cobj.delete(*args, **kwargs) 156 def fd(self, *args, **kwargs): 157 return self._cobj.fd(*args, **kwargs) 158 def get(self, *args, **kwargs): 159 return self._cobj.get(*args, **kwargs) 160 def pget(self, *args, **kwargs): 161 return self._cobj.pget(*args, **kwargs) 162 def get_both(self, *args, **kwargs): 163 return self._cobj.get_both(*args, **kwargs) 164 def get_byteswapped(self, *args, **kwargs): 165 return self._cobj.get_byteswapped(*args, **kwargs) 166 def get_size(self, *args, **kwargs): 167 return self._cobj.get_size(*args, **kwargs) 168 def get_type(self, *args, **kwargs): 169 return self._cobj.get_type(*args, **kwargs) 170 def join(self, *args, **kwargs): 171 return self._cobj.join(*args, **kwargs) 172 def key_range(self, *args, **kwargs): 173 return self._cobj.key_range(*args, **kwargs) 174 def has_key(self, *args, **kwargs): 175 return self._cobj.has_key(*args, **kwargs) 176 def items(self, *args, **kwargs): 177 return self._cobj.items(*args, **kwargs) 178 def keys(self, *args, **kwargs): 179 return self._cobj.keys(*args, **kwargs) 180 def open(self, *args, **kwargs): 181 return self._cobj.open(*args, **kwargs) 182 def put(self, *args, **kwargs): 183 return self._cobj.put(*args, **kwargs) 184 def remove(self, *args, **kwargs): 185 return self._cobj.remove(*args, **kwargs) 186 def rename(self, *args, **kwargs): 187 return self._cobj.rename(*args, **kwargs) 188 def set_bt_minkey(self, *args, **kwargs): 189 return self._cobj.set_bt_minkey(*args, **kwargs) 190 def set_bt_compare(self, *args, **kwargs): 191 return self._cobj.set_bt_compare(*args, **kwargs) 192 def set_cachesize(self, *args, **kwargs): 193 return self._cobj.set_cachesize(*args, **kwargs) 194 def set_dup_compare(self, *args, **kwargs) : 195 return self._cobj.set_dup_compare(*args, **kwargs) 196 def set_flags(self, *args, **kwargs): 197 return self._cobj.set_flags(*args, **kwargs) 198 def set_h_ffactor(self, *args, **kwargs): 199 return self._cobj.set_h_ffactor(*args, **kwargs) 200 def set_h_nelem(self, *args, **kwargs): 201 return self._cobj.set_h_nelem(*args, **kwargs) 202 def set_lorder(self, *args, **kwargs): 203 return self._cobj.set_lorder(*args, **kwargs) 204 def set_pagesize(self, *args, **kwargs): 205 return self._cobj.set_pagesize(*args, **kwargs) 206 def set_re_delim(self, *args, **kwargs): 207 return self._cobj.set_re_delim(*args, **kwargs) 208 def set_re_len(self, *args, **kwargs): 209 return self._cobj.set_re_len(*args, **kwargs) 210 def set_re_pad(self, *args, **kwargs): 211 return self._cobj.set_re_pad(*args, **kwargs) 212 def set_re_source(self, *args, **kwargs): 213 return self._cobj.set_re_source(*args, **kwargs) 214 def set_q_extentsize(self, *args, **kwargs): 215 return self._cobj.set_q_extentsize(*args, **kwargs) 216 def stat(self, *args, **kwargs): 217 return self._cobj.stat(*args, **kwargs) 218 def sync(self, *args, **kwargs): 219 return self._cobj.sync(*args, **kwargs) 220 def type(self, *args, **kwargs): 221 return self._cobj.type(*args, **kwargs) 222 def upgrade(self, *args, **kwargs): 223 return self._cobj.upgrade(*args, **kwargs) 224 def values(self, *args, **kwargs): 225 return self._cobj.values(*args, **kwargs) 226 def verify(self, *args, **kwargs): 227 return self._cobj.verify(*args, **kwargs) 228 def set_get_returns_none(self, *args, **kwargs): 229 return self._cobj.set_get_returns_none(*args, **kwargs) 230 231 def set_encrypt(self, *args, **kwargs): 232 return self._cobj.set_encrypt(*args, **kwargs) 233 234 235 class DBSequence: 236 def __init__(self, *args, **kwargs): 237 self._cobj = db.DBSequence(*args, **kwargs) 238 239 def close(self, *args, **kwargs): 240 return self._cobj.close(*args, **kwargs) 241 def get(self, *args, **kwargs): 242 return self._cobj.get(*args, **kwargs) 243 def get_dbp(self, *args, **kwargs): 244 return self._cobj.get_dbp(*args, **kwargs) 245 def get_key(self, *args, **kwargs): 246 return self._cobj.get_key(*args, **kwargs) 247 def init_value(self, *args, **kwargs): 248 return self._cobj.init_value(*args, **kwargs) 249 def open(self, *args, **kwargs): 250 return self._cobj.open(*args, **kwargs) 251 def remove(self, *args, **kwargs): 252 return self._cobj.remove(*args, **kwargs) 253 def stat(self, *args, **kwargs): 254 return self._cobj.stat(*args, **kwargs) 255 def set_cachesize(self, *args, **kwargs): 256 return self._cobj.set_cachesize(*args, **kwargs) 257 def set_flags(self, *args, **kwargs): 258 return self._cobj.set_flags(*args, **kwargs) 259 def set_range(self, *args, **kwargs): 260 return self._cobj.set_range(*args, **kwargs) 261 def get_cachesize(self, *args, **kwargs): 262 return self._cobj.get_cachesize(*args, **kwargs) 263 def get_flags(self, *args, **kwargs): 264 return self._cobj.get_flags(*args, **kwargs) 265 def get_range(self, *args, **kwargs): 266 return self._cobj.get_range(*args, **kwargs) 267