| 1 | n/a | """Run all test cases. |
|---|
| 2 | n/a | """ |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | import sys |
|---|
| 5 | n/a | import os |
|---|
| 6 | n/a | import unittest |
|---|
| 7 | n/a | try: |
|---|
| 8 | n/a | # For Pythons w/distutils pybsddb |
|---|
| 9 | n/a | import bsddb3 as bsddb |
|---|
| 10 | n/a | except ImportError: |
|---|
| 11 | n/a | # For Python 2.3 |
|---|
| 12 | n/a | import bsddb |
|---|
| 13 | n/a | |
|---|
| 14 | n/a | |
|---|
| 15 | n/a | if sys.version_info[0] >= 3 : |
|---|
| 16 | n/a | charset = "iso8859-1" # Full 8 bit |
|---|
| 17 | n/a | |
|---|
| 18 | n/a | class logcursor_py3k(object) : |
|---|
| 19 | n/a | def __init__(self, env) : |
|---|
| 20 | n/a | self._logcursor = env.log_cursor() |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | def __getattr__(self, v) : |
|---|
| 23 | n/a | return getattr(self._logcursor, v) |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | def __next__(self) : |
|---|
| 26 | n/a | v = getattr(self._logcursor, "next")() |
|---|
| 27 | n/a | if v is not None : |
|---|
| 28 | n/a | v = (v[0], v[1].decode(charset)) |
|---|
| 29 | n/a | return v |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | next = __next__ |
|---|
| 32 | n/a | |
|---|
| 33 | n/a | def first(self) : |
|---|
| 34 | n/a | v = self._logcursor.first() |
|---|
| 35 | n/a | if v is not None : |
|---|
| 36 | n/a | v = (v[0], v[1].decode(charset)) |
|---|
| 37 | n/a | return v |
|---|
| 38 | n/a | |
|---|
| 39 | n/a | def last(self) : |
|---|
| 40 | n/a | v = self._logcursor.last() |
|---|
| 41 | n/a | if v is not None : |
|---|
| 42 | n/a | v = (v[0], v[1].decode(charset)) |
|---|
| 43 | n/a | return v |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | def prev(self) : |
|---|
| 46 | n/a | v = self._logcursor.prev() |
|---|
| 47 | n/a | if v is not None : |
|---|
| 48 | n/a | v = (v[0], v[1].decode(charset)) |
|---|
| 49 | n/a | return v |
|---|
| 50 | n/a | |
|---|
| 51 | n/a | def current(self) : |
|---|
| 52 | n/a | v = self._logcursor.current() |
|---|
| 53 | n/a | if v is not None : |
|---|
| 54 | n/a | v = (v[0], v[1].decode(charset)) |
|---|
| 55 | n/a | return v |
|---|
| 56 | n/a | |
|---|
| 57 | n/a | def set(self, lsn) : |
|---|
| 58 | n/a | v = self._logcursor.set(lsn) |
|---|
| 59 | n/a | if v is not None : |
|---|
| 60 | n/a | v = (v[0], v[1].decode(charset)) |
|---|
| 61 | n/a | return v |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | class cursor_py3k(object) : |
|---|
| 64 | n/a | def __init__(self, db, *args, **kwargs) : |
|---|
| 65 | n/a | self._dbcursor = db.cursor(*args, **kwargs) |
|---|
| 66 | n/a | |
|---|
| 67 | n/a | def __getattr__(self, v) : |
|---|
| 68 | n/a | return getattr(self._dbcursor, v) |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | def _fix(self, v) : |
|---|
| 71 | n/a | if v is None : return None |
|---|
| 72 | n/a | key, value = v |
|---|
| 73 | n/a | if isinstance(key, bytes) : |
|---|
| 74 | n/a | key = key.decode(charset) |
|---|
| 75 | n/a | return (key, value.decode(charset)) |
|---|
| 76 | n/a | |
|---|
| 77 | n/a | def __next__(self) : |
|---|
| 78 | n/a | v = getattr(self._dbcursor, "next")() |
|---|
| 79 | n/a | return self._fix(v) |
|---|
| 80 | n/a | |
|---|
| 81 | n/a | next = __next__ |
|---|
| 82 | n/a | |
|---|
| 83 | n/a | def previous(self) : |
|---|
| 84 | n/a | v = self._dbcursor.previous() |
|---|
| 85 | n/a | return self._fix(v) |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | def last(self) : |
|---|
| 88 | n/a | v = self._dbcursor.last() |
|---|
| 89 | n/a | return self._fix(v) |
|---|
| 90 | n/a | |
|---|
| 91 | n/a | def set(self, k) : |
|---|
| 92 | n/a | if isinstance(k, str) : |
|---|
| 93 | n/a | k = bytes(k, charset) |
|---|
| 94 | n/a | v = self._dbcursor.set(k) |
|---|
| 95 | n/a | return self._fix(v) |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | def set_recno(self, num) : |
|---|
| 98 | n/a | v = self._dbcursor.set_recno(num) |
|---|
| 99 | n/a | return self._fix(v) |
|---|
| 100 | n/a | |
|---|
| 101 | n/a | def set_range(self, k, dlen=-1, doff=-1) : |
|---|
| 102 | n/a | if isinstance(k, str) : |
|---|
| 103 | n/a | k = bytes(k, charset) |
|---|
| 104 | n/a | v = self._dbcursor.set_range(k, dlen=dlen, doff=doff) |
|---|
| 105 | n/a | return self._fix(v) |
|---|
| 106 | n/a | |
|---|
| 107 | n/a | def dup(self, flags=0) : |
|---|
| 108 | n/a | cursor = self._dbcursor.dup(flags) |
|---|
| 109 | n/a | return dup_cursor_py3k(cursor) |
|---|
| 110 | n/a | |
|---|
| 111 | n/a | def next_dup(self) : |
|---|
| 112 | n/a | v = self._dbcursor.next_dup() |
|---|
| 113 | n/a | return self._fix(v) |
|---|
| 114 | n/a | |
|---|
| 115 | n/a | def next_nodup(self) : |
|---|
| 116 | n/a | v = self._dbcursor.next_nodup() |
|---|
| 117 | n/a | return self._fix(v) |
|---|
| 118 | n/a | |
|---|
| 119 | n/a | def put(self, key, data, flags=0, dlen=-1, doff=-1) : |
|---|
| 120 | n/a | if isinstance(key, str) : |
|---|
| 121 | n/a | key = bytes(key, charset) |
|---|
| 122 | n/a | if isinstance(data, str) : |
|---|
| 123 | n/a | value = bytes(data, charset) |
|---|
| 124 | n/a | return self._dbcursor.put(key, data, flags=flags, dlen=dlen, |
|---|
| 125 | n/a | doff=doff) |
|---|
| 126 | n/a | |
|---|
| 127 | n/a | def current(self, flags=0, dlen=-1, doff=-1) : |
|---|
| 128 | n/a | v = self._dbcursor.current(flags=flags, dlen=dlen, doff=doff) |
|---|
| 129 | n/a | return self._fix(v) |
|---|
| 130 | n/a | |
|---|
| 131 | n/a | def first(self) : |
|---|
| 132 | n/a | v = self._dbcursor.first() |
|---|
| 133 | n/a | return self._fix(v) |
|---|
| 134 | n/a | |
|---|
| 135 | n/a | def pget(self, key=None, data=None, flags=0) : |
|---|
| 136 | n/a | # Incorrect because key can be a bare number, |
|---|
| 137 | n/a | # but enough to pass testsuite |
|---|
| 138 | n/a | if isinstance(key, int) and (data is None) and (flags == 0) : |
|---|
| 139 | n/a | flags = key |
|---|
| 140 | n/a | key = None |
|---|
| 141 | n/a | if isinstance(key, str) : |
|---|
| 142 | n/a | key = bytes(key, charset) |
|---|
| 143 | n/a | if isinstance(data, int) and (flags==0) : |
|---|
| 144 | n/a | flags = data |
|---|
| 145 | n/a | data = None |
|---|
| 146 | n/a | if isinstance(data, str) : |
|---|
| 147 | n/a | data = bytes(data, charset) |
|---|
| 148 | n/a | v=self._dbcursor.pget(key=key, data=data, flags=flags) |
|---|
| 149 | n/a | if v is not None : |
|---|
| 150 | n/a | v1, v2, v3 = v |
|---|
| 151 | n/a | if isinstance(v1, bytes) : |
|---|
| 152 | n/a | v1 = v1.decode(charset) |
|---|
| 153 | n/a | if isinstance(v2, bytes) : |
|---|
| 154 | n/a | v2 = v2.decode(charset) |
|---|
| 155 | n/a | |
|---|
| 156 | n/a | v = (v1, v2, v3.decode(charset)) |
|---|
| 157 | n/a | |
|---|
| 158 | n/a | return v |
|---|
| 159 | n/a | |
|---|
| 160 | n/a | def join_item(self) : |
|---|
| 161 | n/a | v = self._dbcursor.join_item() |
|---|
| 162 | n/a | if v is not None : |
|---|
| 163 | n/a | v = v.decode(charset) |
|---|
| 164 | n/a | return v |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | def get(self, *args, **kwargs) : |
|---|
| 167 | n/a | l = len(args) |
|---|
| 168 | n/a | if l == 2 : |
|---|
| 169 | n/a | k, f = args |
|---|
| 170 | n/a | if isinstance(k, str) : |
|---|
| 171 | n/a | k = bytes(k, "iso8859-1") |
|---|
| 172 | n/a | args = (k, f) |
|---|
| 173 | n/a | elif l == 3 : |
|---|
| 174 | n/a | k, d, f = args |
|---|
| 175 | n/a | if isinstance(k, str) : |
|---|
| 176 | n/a | k = bytes(k, charset) |
|---|
| 177 | n/a | if isinstance(d, str) : |
|---|
| 178 | n/a | d = bytes(d, charset) |
|---|
| 179 | n/a | args =(k, d, f) |
|---|
| 180 | n/a | |
|---|
| 181 | n/a | v = self._dbcursor.get(*args, **kwargs) |
|---|
| 182 | n/a | if v is not None : |
|---|
| 183 | n/a | k, v = v |
|---|
| 184 | n/a | if isinstance(k, bytes) : |
|---|
| 185 | n/a | k = k.decode(charset) |
|---|
| 186 | n/a | v = (k, v.decode(charset)) |
|---|
| 187 | n/a | return v |
|---|
| 188 | n/a | |
|---|
| 189 | n/a | def get_both(self, key, value) : |
|---|
| 190 | n/a | if isinstance(key, str) : |
|---|
| 191 | n/a | key = bytes(key, charset) |
|---|
| 192 | n/a | if isinstance(value, str) : |
|---|
| 193 | n/a | value = bytes(value, charset) |
|---|
| 194 | n/a | v=self._dbcursor.get_both(key, value) |
|---|
| 195 | n/a | return self._fix(v) |
|---|
| 196 | n/a | |
|---|
| 197 | n/a | class dup_cursor_py3k(cursor_py3k) : |
|---|
| 198 | n/a | def __init__(self, dbcursor) : |
|---|
| 199 | n/a | self._dbcursor = dbcursor |
|---|
| 200 | n/a | |
|---|
| 201 | n/a | class DB_py3k(object) : |
|---|
| 202 | n/a | def __init__(self, *args, **kwargs) : |
|---|
| 203 | n/a | args2=[] |
|---|
| 204 | n/a | for i in args : |
|---|
| 205 | n/a | if isinstance(i, DBEnv_py3k) : |
|---|
| 206 | n/a | i = i._dbenv |
|---|
| 207 | n/a | args2.append(i) |
|---|
| 208 | n/a | args = tuple(args2) |
|---|
| 209 | n/a | for k, v in kwargs.items() : |
|---|
| 210 | n/a | if isinstance(v, DBEnv_py3k) : |
|---|
| 211 | n/a | kwargs[k] = v._dbenv |
|---|
| 212 | n/a | |
|---|
| 213 | n/a | self._db = bsddb._db.DB_orig(*args, **kwargs) |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | def __contains__(self, k) : |
|---|
| 216 | n/a | if isinstance(k, str) : |
|---|
| 217 | n/a | k = bytes(k, charset) |
|---|
| 218 | n/a | return getattr(self._db, "has_key")(k) |
|---|
| 219 | n/a | |
|---|
| 220 | n/a | def __getitem__(self, k) : |
|---|
| 221 | n/a | if isinstance(k, str) : |
|---|
| 222 | n/a | k = bytes(k, charset) |
|---|
| 223 | n/a | v = self._db[k] |
|---|
| 224 | n/a | if v is not None : |
|---|
| 225 | n/a | v = v.decode(charset) |
|---|
| 226 | n/a | return v |
|---|
| 227 | n/a | |
|---|
| 228 | n/a | def __setitem__(self, k, v) : |
|---|
| 229 | n/a | if isinstance(k, str) : |
|---|
| 230 | n/a | k = bytes(k, charset) |
|---|
| 231 | n/a | if isinstance(v, str) : |
|---|
| 232 | n/a | v = bytes(v, charset) |
|---|
| 233 | n/a | self._db[k] = v |
|---|
| 234 | n/a | |
|---|
| 235 | n/a | def __delitem__(self, k) : |
|---|
| 236 | n/a | if isinstance(k, str) : |
|---|
| 237 | n/a | k = bytes(k, charset) |
|---|
| 238 | n/a | del self._db[k] |
|---|
| 239 | n/a | |
|---|
| 240 | n/a | def __getattr__(self, v) : |
|---|
| 241 | n/a | return getattr(self._db, v) |
|---|
| 242 | n/a | |
|---|
| 243 | n/a | def __len__(self) : |
|---|
| 244 | n/a | return len(self._db) |
|---|
| 245 | n/a | |
|---|
| 246 | n/a | def has_key(self, k, txn=None) : |
|---|
| 247 | n/a | if isinstance(k, str) : |
|---|
| 248 | n/a | k = bytes(k, charset) |
|---|
| 249 | n/a | return self._db.has_key(k, txn=txn) |
|---|
| 250 | n/a | |
|---|
| 251 | n/a | def set_re_delim(self, c) : |
|---|
| 252 | n/a | if isinstance(c, str) : # We can use a numeric value byte too |
|---|
| 253 | n/a | c = bytes(c, charset) |
|---|
| 254 | n/a | return self._db.set_re_delim(c) |
|---|
| 255 | n/a | |
|---|
| 256 | n/a | def set_re_pad(self, c) : |
|---|
| 257 | n/a | if isinstance(c, str) : # We can use a numeric value byte too |
|---|
| 258 | n/a | c = bytes(c, charset) |
|---|
| 259 | n/a | return self._db.set_re_pad(c) |
|---|
| 260 | n/a | |
|---|
| 261 | n/a | def get_re_source(self) : |
|---|
| 262 | n/a | source = self._db.get_re_source() |
|---|
| 263 | n/a | return source.decode(charset) |
|---|
| 264 | n/a | |
|---|
| 265 | n/a | def put(self, key, data, txn=None, flags=0, dlen=-1, doff=-1) : |
|---|
| 266 | n/a | if isinstance(key, str) : |
|---|
| 267 | n/a | key = bytes(key, charset) |
|---|
| 268 | n/a | if isinstance(data, str) : |
|---|
| 269 | n/a | value = bytes(data, charset) |
|---|
| 270 | n/a | return self._db.put(key, data, flags=flags, txn=txn, dlen=dlen, |
|---|
| 271 | n/a | doff=doff) |
|---|
| 272 | n/a | |
|---|
| 273 | n/a | def append(self, value, txn=None) : |
|---|
| 274 | n/a | if isinstance(value, str) : |
|---|
| 275 | n/a | value = bytes(value, charset) |
|---|
| 276 | n/a | return self._db.append(value, txn=txn) |
|---|
| 277 | n/a | |
|---|
| 278 | n/a | def get_size(self, key) : |
|---|
| 279 | n/a | if isinstance(key, str) : |
|---|
| 280 | n/a | key = bytes(key, charset) |
|---|
| 281 | n/a | return self._db.get_size(key) |
|---|
| 282 | n/a | |
|---|
| 283 | n/a | def exists(self, key, *args, **kwargs) : |
|---|
| 284 | n/a | if isinstance(key, str) : |
|---|
| 285 | n/a | key = bytes(key, charset) |
|---|
| 286 | n/a | return self._db.exists(key, *args, **kwargs) |
|---|
| 287 | n/a | |
|---|
| 288 | n/a | def get(self, key, default="MagicCookie", txn=None, flags=0, dlen=-1, doff=-1) : |
|---|
| 289 | n/a | if isinstance(key, str) : |
|---|
| 290 | n/a | key = bytes(key, charset) |
|---|
| 291 | n/a | if default != "MagicCookie" : # Magic for 'test_get_none.py' |
|---|
| 292 | n/a | v=self._db.get(key, default=default, txn=txn, flags=flags, |
|---|
| 293 | n/a | dlen=dlen, doff=doff) |
|---|
| 294 | n/a | else : |
|---|
| 295 | n/a | v=self._db.get(key, txn=txn, flags=flags, |
|---|
| 296 | n/a | dlen=dlen, doff=doff) |
|---|
| 297 | n/a | if (v is not None) and isinstance(v, bytes) : |
|---|
| 298 | n/a | v = v.decode(charset) |
|---|
| 299 | n/a | return v |
|---|
| 300 | n/a | |
|---|
| 301 | n/a | def pget(self, key, txn=None) : |
|---|
| 302 | n/a | if isinstance(key, str) : |
|---|
| 303 | n/a | key = bytes(key, charset) |
|---|
| 304 | n/a | v=self._db.pget(key, txn=txn) |
|---|
| 305 | n/a | if v is not None : |
|---|
| 306 | n/a | v1, v2 = v |
|---|
| 307 | n/a | if isinstance(v1, bytes) : |
|---|
| 308 | n/a | v1 = v1.decode(charset) |
|---|
| 309 | n/a | |
|---|
| 310 | n/a | v = (v1, v2.decode(charset)) |
|---|
| 311 | n/a | return v |
|---|
| 312 | n/a | |
|---|
| 313 | n/a | def get_both(self, key, value, txn=None, flags=0) : |
|---|
| 314 | n/a | if isinstance(key, str) : |
|---|
| 315 | n/a | key = bytes(key, charset) |
|---|
| 316 | n/a | if isinstance(value, str) : |
|---|
| 317 | n/a | value = bytes(value, charset) |
|---|
| 318 | n/a | v=self._db.get_both(key, value, txn=txn, flags=flags) |
|---|
| 319 | n/a | if v is not None : |
|---|
| 320 | n/a | v = v.decode(charset) |
|---|
| 321 | n/a | return v |
|---|
| 322 | n/a | |
|---|
| 323 | n/a | def delete(self, key, txn=None) : |
|---|
| 324 | n/a | if isinstance(key, str) : |
|---|
| 325 | n/a | key = bytes(key, charset) |
|---|
| 326 | n/a | return self._db.delete(key, txn=txn) |
|---|
| 327 | n/a | |
|---|
| 328 | n/a | def keys(self) : |
|---|
| 329 | n/a | k = self._db.keys() |
|---|
| 330 | n/a | if len(k) and isinstance(k[0], bytes) : |
|---|
| 331 | n/a | return [i.decode(charset) for i in self._db.keys()] |
|---|
| 332 | n/a | else : |
|---|
| 333 | n/a | return k |
|---|
| 334 | n/a | |
|---|
| 335 | n/a | def items(self) : |
|---|
| 336 | n/a | data = self._db.items() |
|---|
| 337 | n/a | if not len(data) : return data |
|---|
| 338 | n/a | data2 = [] |
|---|
| 339 | n/a | for k, v in data : |
|---|
| 340 | n/a | if isinstance(k, bytes) : |
|---|
| 341 | n/a | k = k.decode(charset) |
|---|
| 342 | n/a | data2.append((k, v.decode(charset))) |
|---|
| 343 | n/a | return data2 |
|---|
| 344 | n/a | |
|---|
| 345 | n/a | def associate(self, secondarydb, callback, flags=0, txn=None) : |
|---|
| 346 | n/a | class associate_callback(object) : |
|---|
| 347 | n/a | def __init__(self, callback) : |
|---|
| 348 | n/a | self._callback = callback |
|---|
| 349 | n/a | |
|---|
| 350 | n/a | def callback(self, key, data) : |
|---|
| 351 | n/a | if isinstance(key, str) : |
|---|
| 352 | n/a | key = key.decode(charset) |
|---|
| 353 | n/a | data = data.decode(charset) |
|---|
| 354 | n/a | key = self._callback(key, data) |
|---|
| 355 | n/a | if (key != bsddb._db.DB_DONOTINDEX) : |
|---|
| 356 | n/a | if isinstance(key, str) : |
|---|
| 357 | n/a | key = bytes(key, charset) |
|---|
| 358 | n/a | elif isinstance(key, list) : |
|---|
| 359 | n/a | key2 = [] |
|---|
| 360 | n/a | for i in key : |
|---|
| 361 | n/a | if isinstance(i, str) : |
|---|
| 362 | n/a | i = bytes(i, charset) |
|---|
| 363 | n/a | key2.append(i) |
|---|
| 364 | n/a | key = key2 |
|---|
| 365 | n/a | return key |
|---|
| 366 | n/a | |
|---|
| 367 | n/a | return self._db.associate(secondarydb._db, |
|---|
| 368 | n/a | associate_callback(callback).callback, flags=flags, |
|---|
| 369 | n/a | txn=txn) |
|---|
| 370 | n/a | |
|---|
| 371 | n/a | def cursor(self, txn=None, flags=0) : |
|---|
| 372 | n/a | return cursor_py3k(self._db, txn=txn, flags=flags) |
|---|
| 373 | n/a | |
|---|
| 374 | n/a | def join(self, cursor_list) : |
|---|
| 375 | n/a | cursor_list = [i._dbcursor for i in cursor_list] |
|---|
| 376 | n/a | return dup_cursor_py3k(self._db.join(cursor_list)) |
|---|
| 377 | n/a | |
|---|
| 378 | n/a | class DBEnv_py3k(object) : |
|---|
| 379 | n/a | def __init__(self, *args, **kwargs) : |
|---|
| 380 | n/a | self._dbenv = bsddb._db.DBEnv_orig(*args, **kwargs) |
|---|
| 381 | n/a | |
|---|
| 382 | n/a | def __getattr__(self, v) : |
|---|
| 383 | n/a | return getattr(self._dbenv, v) |
|---|
| 384 | n/a | |
|---|
| 385 | n/a | def log_cursor(self, flags=0) : |
|---|
| 386 | n/a | return logcursor_py3k(self._dbenv) |
|---|
| 387 | n/a | |
|---|
| 388 | n/a | def get_lg_dir(self) : |
|---|
| 389 | n/a | return self._dbenv.get_lg_dir().decode(charset) |
|---|
| 390 | n/a | |
|---|
| 391 | n/a | def get_tmp_dir(self) : |
|---|
| 392 | n/a | return self._dbenv.get_tmp_dir().decode(charset) |
|---|
| 393 | n/a | |
|---|
| 394 | n/a | def get_data_dirs(self) : |
|---|
| 395 | n/a | # Have to use a list comprehension and not |
|---|
| 396 | n/a | # generators, because we are supporting Python 2.3. |
|---|
| 397 | n/a | return tuple( |
|---|
| 398 | n/a | [i.decode(charset) for i in self._dbenv.get_data_dirs()]) |
|---|
| 399 | n/a | |
|---|
| 400 | n/a | class DBSequence_py3k(object) : |
|---|
| 401 | n/a | def __init__(self, db, *args, **kwargs) : |
|---|
| 402 | n/a | self._db=db |
|---|
| 403 | n/a | self._dbsequence = bsddb._db.DBSequence_orig(db._db, *args, **kwargs) |
|---|
| 404 | n/a | |
|---|
| 405 | n/a | def __getattr__(self, v) : |
|---|
| 406 | n/a | return getattr(self._dbsequence, v) |
|---|
| 407 | n/a | |
|---|
| 408 | n/a | def open(self, key, *args, **kwargs) : |
|---|
| 409 | n/a | return self._dbsequence.open(bytes(key, charset), *args, **kwargs) |
|---|
| 410 | n/a | |
|---|
| 411 | n/a | def get_key(self) : |
|---|
| 412 | n/a | return self._dbsequence.get_key().decode(charset) |
|---|
| 413 | n/a | |
|---|
| 414 | n/a | def get_dbp(self) : |
|---|
| 415 | n/a | return self._db |
|---|
| 416 | n/a | |
|---|
| 417 | n/a | import string |
|---|
| 418 | n/a | string.letters=[chr(i) for i in xrange(65,91)] |
|---|
| 419 | n/a | |
|---|
| 420 | n/a | bsddb._db.DBEnv_orig = bsddb._db.DBEnv |
|---|
| 421 | n/a | bsddb._db.DB_orig = bsddb._db.DB |
|---|
| 422 | n/a | if bsddb.db.version() <= (4, 3) : |
|---|
| 423 | n/a | bsddb._db.DBSequence_orig = None |
|---|
| 424 | n/a | else : |
|---|
| 425 | n/a | bsddb._db.DBSequence_orig = bsddb._db.DBSequence |
|---|
| 426 | n/a | |
|---|
| 427 | n/a | def do_proxy_db_py3k(flag) : |
|---|
| 428 | n/a | flag2 = do_proxy_db_py3k.flag |
|---|
| 429 | n/a | do_proxy_db_py3k.flag = flag |
|---|
| 430 | n/a | if flag : |
|---|
| 431 | n/a | bsddb.DBEnv = bsddb.db.DBEnv = bsddb._db.DBEnv = DBEnv_py3k |
|---|
| 432 | n/a | bsddb.DB = bsddb.db.DB = bsddb._db.DB = DB_py3k |
|---|
| 433 | n/a | bsddb._db.DBSequence = DBSequence_py3k |
|---|
| 434 | n/a | else : |
|---|
| 435 | n/a | bsddb.DBEnv = bsddb.db.DBEnv = bsddb._db.DBEnv = bsddb._db.DBEnv_orig |
|---|
| 436 | n/a | bsddb.DB = bsddb.db.DB = bsddb._db.DB = bsddb._db.DB_orig |
|---|
| 437 | n/a | bsddb._db.DBSequence = bsddb._db.DBSequence_orig |
|---|
| 438 | n/a | return flag2 |
|---|
| 439 | n/a | |
|---|
| 440 | n/a | do_proxy_db_py3k.flag = False |
|---|
| 441 | n/a | do_proxy_db_py3k(True) |
|---|
| 442 | n/a | |
|---|
| 443 | n/a | try: |
|---|
| 444 | n/a | # For Pythons w/distutils pybsddb |
|---|
| 445 | n/a | from bsddb3 import db, dbtables, dbutils, dbshelve, \ |
|---|
| 446 | n/a | hashopen, btopen, rnopen, dbobj |
|---|
| 447 | n/a | except ImportError: |
|---|
| 448 | n/a | # For Python 2.3 |
|---|
| 449 | n/a | from bsddb import db, dbtables, dbutils, dbshelve, \ |
|---|
| 450 | n/a | hashopen, btopen, rnopen, dbobj |
|---|
| 451 | n/a | |
|---|
| 452 | n/a | try: |
|---|
| 453 | n/a | from bsddb3 import test_support |
|---|
| 454 | n/a | except ImportError: |
|---|
| 455 | n/a | if sys.version_info[0] < 3 : |
|---|
| 456 | n/a | from test import test_support |
|---|
| 457 | n/a | else : |
|---|
| 458 | n/a | from test import support as test_support |
|---|
| 459 | n/a | |
|---|
| 460 | n/a | |
|---|
| 461 | n/a | try: |
|---|
| 462 | n/a | if sys.version_info[0] < 3 : |
|---|
| 463 | n/a | from threading import Thread, currentThread |
|---|
| 464 | n/a | del Thread, currentThread |
|---|
| 465 | n/a | else : |
|---|
| 466 | n/a | from threading import Thread, current_thread |
|---|
| 467 | n/a | del Thread, current_thread |
|---|
| 468 | n/a | have_threads = True |
|---|
| 469 | n/a | except ImportError: |
|---|
| 470 | n/a | have_threads = False |
|---|
| 471 | n/a | |
|---|
| 472 | n/a | verbose = 0 |
|---|
| 473 | n/a | if 'verbose' in sys.argv: |
|---|
| 474 | n/a | verbose = 1 |
|---|
| 475 | n/a | sys.argv.remove('verbose') |
|---|
| 476 | n/a | |
|---|
| 477 | n/a | if 'silent' in sys.argv: # take care of old flag, just in case |
|---|
| 478 | n/a | verbose = 0 |
|---|
| 479 | n/a | sys.argv.remove('silent') |
|---|
| 480 | n/a | |
|---|
| 481 | n/a | |
|---|
| 482 | n/a | def print_versions(): |
|---|
| 483 | n/a | print |
|---|
| 484 | n/a | print '-=' * 38 |
|---|
| 485 | n/a | print db.DB_VERSION_STRING |
|---|
| 486 | n/a | print 'bsddb.db.version(): %s' % (db.version(), ) |
|---|
| 487 | n/a | print 'bsddb.db.__version__: %s' % db.__version__ |
|---|
| 488 | n/a | print 'bsddb.db.cvsid: %s' % db.cvsid |
|---|
| 489 | n/a | |
|---|
| 490 | n/a | # Workaround for allowing generating an EGGs as a ZIP files. |
|---|
| 491 | n/a | suffix="__" |
|---|
| 492 | n/a | print 'py module: %s' % getattr(bsddb, "__file"+suffix) |
|---|
| 493 | n/a | print 'extension module: %s' % getattr(bsddb, "__file"+suffix) |
|---|
| 494 | n/a | |
|---|
| 495 | n/a | print 'python version: %s' % sys.version |
|---|
| 496 | n/a | print 'My pid: %s' % os.getpid() |
|---|
| 497 | n/a | print '-=' * 38 |
|---|
| 498 | n/a | |
|---|
| 499 | n/a | |
|---|
| 500 | n/a | def get_new_path(name) : |
|---|
| 501 | n/a | get_new_path.mutex.acquire() |
|---|
| 502 | n/a | try : |
|---|
| 503 | n/a | import os |
|---|
| 504 | n/a | path=os.path.join(get_new_path.prefix, |
|---|
| 505 | n/a | name+"_"+str(os.getpid())+"_"+str(get_new_path.num)) |
|---|
| 506 | n/a | get_new_path.num+=1 |
|---|
| 507 | n/a | finally : |
|---|
| 508 | n/a | get_new_path.mutex.release() |
|---|
| 509 | n/a | return path |
|---|
| 510 | n/a | |
|---|
| 511 | n/a | def get_new_environment_path() : |
|---|
| 512 | n/a | path=get_new_path("environment") |
|---|
| 513 | n/a | import os |
|---|
| 514 | n/a | try: |
|---|
| 515 | n/a | os.makedirs(path,mode=0700) |
|---|
| 516 | n/a | except os.error: |
|---|
| 517 | n/a | test_support.rmtree(path) |
|---|
| 518 | n/a | os.makedirs(path) |
|---|
| 519 | n/a | return path |
|---|
| 520 | n/a | |
|---|
| 521 | n/a | def get_new_database_path() : |
|---|
| 522 | n/a | path=get_new_path("database") |
|---|
| 523 | n/a | import os |
|---|
| 524 | n/a | if os.path.exists(path) : |
|---|
| 525 | n/a | os.remove(path) |
|---|
| 526 | n/a | return path |
|---|
| 527 | n/a | |
|---|
| 528 | n/a | |
|---|
| 529 | n/a | # This path can be overriden via "set_test_path_prefix()". |
|---|
| 530 | n/a | import os, os.path |
|---|
| 531 | n/a | get_new_path.prefix=os.path.join(os.sep,"tmp","z-Berkeley_DB") |
|---|
| 532 | n/a | get_new_path.num=0 |
|---|
| 533 | n/a | |
|---|
| 534 | n/a | def get_test_path_prefix() : |
|---|
| 535 | n/a | return get_new_path.prefix |
|---|
| 536 | n/a | |
|---|
| 537 | n/a | def set_test_path_prefix(path) : |
|---|
| 538 | n/a | get_new_path.prefix=path |
|---|
| 539 | n/a | |
|---|
| 540 | n/a | def remove_test_path_directory() : |
|---|
| 541 | n/a | test_support.rmtree(get_new_path.prefix) |
|---|
| 542 | n/a | |
|---|
| 543 | n/a | if have_threads : |
|---|
| 544 | n/a | import threading |
|---|
| 545 | n/a | get_new_path.mutex=threading.Lock() |
|---|
| 546 | n/a | del threading |
|---|
| 547 | n/a | else : |
|---|
| 548 | n/a | class Lock(object) : |
|---|
| 549 | n/a | def acquire(self) : |
|---|
| 550 | n/a | pass |
|---|
| 551 | n/a | def release(self) : |
|---|
| 552 | n/a | pass |
|---|
| 553 | n/a | get_new_path.mutex=Lock() |
|---|
| 554 | n/a | del Lock |
|---|
| 555 | n/a | |
|---|
| 556 | n/a | |
|---|
| 557 | n/a | |
|---|
| 558 | n/a | class PrintInfoFakeTest(unittest.TestCase): |
|---|
| 559 | n/a | def testPrintVersions(self): |
|---|
| 560 | n/a | print_versions() |
|---|
| 561 | n/a | |
|---|
| 562 | n/a | |
|---|
| 563 | n/a | # This little hack is for when this module is run as main and all the |
|---|
| 564 | n/a | # other modules import it so they will still be able to get the right |
|---|
| 565 | n/a | # verbose setting. It's confusing but it works. |
|---|
| 566 | n/a | if sys.version_info[0] < 3 : |
|---|
| 567 | n/a | import test_all |
|---|
| 568 | n/a | test_all.verbose = verbose |
|---|
| 569 | n/a | else : |
|---|
| 570 | n/a | import sys |
|---|
| 571 | n/a | print >>sys.stderr, "Work to do!" |
|---|
| 572 | n/a | |
|---|
| 573 | n/a | |
|---|
| 574 | n/a | def suite(module_prefix='', timing_check=None): |
|---|
| 575 | n/a | test_modules = [ |
|---|
| 576 | n/a | 'test_associate', |
|---|
| 577 | n/a | 'test_basics', |
|---|
| 578 | n/a | 'test_dbenv', |
|---|
| 579 | n/a | 'test_db', |
|---|
| 580 | n/a | 'test_compare', |
|---|
| 581 | n/a | 'test_compat', |
|---|
| 582 | n/a | 'test_cursor_pget_bug', |
|---|
| 583 | n/a | 'test_dbobj', |
|---|
| 584 | n/a | 'test_dbshelve', |
|---|
| 585 | n/a | 'test_dbtables', |
|---|
| 586 | n/a | 'test_distributed_transactions', |
|---|
| 587 | n/a | 'test_early_close', |
|---|
| 588 | n/a | 'test_fileid', |
|---|
| 589 | n/a | 'test_get_none', |
|---|
| 590 | n/a | 'test_join', |
|---|
| 591 | n/a | 'test_lock', |
|---|
| 592 | n/a | 'test_misc', |
|---|
| 593 | n/a | 'test_pickle', |
|---|
| 594 | n/a | 'test_queue', |
|---|
| 595 | n/a | 'test_recno', |
|---|
| 596 | n/a | 'test_replication', |
|---|
| 597 | n/a | 'test_sequence', |
|---|
| 598 | n/a | 'test_thread', |
|---|
| 599 | n/a | ] |
|---|
| 600 | n/a | |
|---|
| 601 | n/a | alltests = unittest.TestSuite() |
|---|
| 602 | n/a | for name in test_modules: |
|---|
| 603 | n/a | #module = __import__(name) |
|---|
| 604 | n/a | # Do it this way so that suite may be called externally via |
|---|
| 605 | n/a | # python's Lib/test/test_bsddb3. |
|---|
| 606 | n/a | module = __import__(module_prefix+name, globals(), locals(), name) |
|---|
| 607 | n/a | |
|---|
| 608 | n/a | alltests.addTest(module.test_suite()) |
|---|
| 609 | n/a | if timing_check: |
|---|
| 610 | n/a | alltests.addTest(unittest.makeSuite(timing_check)) |
|---|
| 611 | n/a | return alltests |
|---|
| 612 | n/a | |
|---|
| 613 | n/a | |
|---|
| 614 | n/a | def test_suite(): |
|---|
| 615 | n/a | suite = unittest.TestSuite() |
|---|
| 616 | n/a | suite.addTest(unittest.makeSuite(PrintInfoFakeTest)) |
|---|
| 617 | n/a | return suite |
|---|
| 618 | n/a | |
|---|
| 619 | n/a | |
|---|
| 620 | n/a | if __name__ == '__main__': |
|---|
| 621 | n/a | print_versions() |
|---|
| 622 | n/a | unittest.main(defaultTest='suite') |
|---|