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