def _openDBHash(filename,flag,mode=0666): """Open a Berkeley DB hash database. Equivalent to dbhash.open, but when possible, reaches into bsddb.db and uses the DB_RECOVER* flag(s) to handle possible corruption from crashing without closing the database. """ if 1: #XXXX008 This function is borked. Fix it or remove it. return anydbm.open(filename, flag, mode) try: import bsddb except ImportError: # Fallback to anydbm, which delegates to dbhash return anydbm.open(filename, flag, mode) # Adapted from bsddb.hashopen e = bsddb.db.DBEnv(bsddb.db.DB_PRIVATE| bsddb.db.DB_CREATE | bsddb.db.DB_THREAD | bsddb.db.DB_INIT_LOCK | bsddb.db.DB_INIT_MPOOL | bsddb.db.DB_RECOVER ) flags = bsddb.db.DB_CREATE | bsddb.db.DB_THREAD flags |= getattr(bsddb.db, "DB_AUTO_COMMIT", 0) #flags |= getattr(bsddb.db, "DB_RECOVER", 0) #flags |= getattr(bsddb.db, "DB_RECOVER_FATAL", 0) d = bsddb.db.DB(e) d.open(filename, bsddb.db.DB_HASH, flags, mode) return bsddb._DBWithCursor(d)
def _openDBHash(filename, flag, mode=0666): """Open a Berkeley DB hash database. Equivalent to dbhash.open, but when possible, reaches into bsddb.db and uses the DB_RECOVER* flag(s) to handle possible corruption from crashing without closing the database. """ if 1: #XXXX008 This function is borked. Fix it or remove it. return anydbm.open(filename, flag, mode) try: import bsddb except ImportError: # Fallback to anydbm, which delegates to dbhash return anydbm.open(filename, flag, mode) # Adapted from bsddb.hashopen e = bsddb.db.DBEnv(bsddb.db.DB_PRIVATE | bsddb.db.DB_CREATE | bsddb.db.DB_THREAD | bsddb.db.DB_INIT_LOCK | bsddb.db.DB_INIT_MPOOL | bsddb.db.DB_RECOVER) flags = bsddb.db.DB_CREATE | bsddb.db.DB_THREAD flags |= getattr(bsddb.db, "DB_AUTO_COMMIT", 0) #flags |= getattr(bsddb.db, "DB_RECOVER", 0) #flags |= getattr(bsddb.db, "DB_RECOVER_FATAL", 0) d = bsddb.db.DB(e) d.open(filename, bsddb.db.DB_HASH, flags, mode) return bsddb._DBWithCursor(d)
''' return '\0'.join(map(_to_safe_str, args)) def _btopen(env, file, flag='c', mode=0666, btflags=0, cachesize=None, maxkeypage=None, minkeypage=None, pgsize=None, lorder=None): flags = bsddb.db.DB_CREATE # bsddb._checkflag(flag, file) d = bsddb.db.DB(env) if pgsize is not None: d.set_pagesize(pgsize) if lorder is not None: d.set_lorder(lorder) d.set_flags(btflags) if minkeypage is not None: d.set_bt_minkey(minkeypage) if maxkeypage is not None: d.set_bt_maxkey(maxkeypage) d.open(file, dbtype=bsddb.db.DB_BTREE, flags=flags, mode=mode) return bsddb._DBWithCursor(d) class BdbStore(Model): ''' datastore using Berkeley DB using Python's bsddb module two b-tree databases with sorted duplicates p o t => c s s => p o t c where s subject p predicate