def firstkey(self): with _lock: self.__check_closed() key = lib.gdbm_firstkey(self.__ll_dbm) if key.dptr: res = bytes(ffi.buffer(key.dptr, key.dsize)) lib.free(key.dptr) return res
def nextkey(self, key): with _lock: self.__check_closed() key = lib.gdbm_nextkey(self.__ll_dbm, _fromstr(key)) if key.dptr: res = bytes(ffi.buffer(key.dptr, key.dsize)) lib.free(key.dptr) return res
def nextkey(self, key): with _lock: self.__check_closed() key = lib.gdbm_nextkey(self.__ll_dbm, _fromstr(key)) if key.dptr: res = str(ffi.buffer(key.dptr, key.dsize)) lib.free(key.dptr) return res
def firstkey(self): with _lock: self.__check_closed() key = lib.gdbm_firstkey(self.__ll_dbm) if key.dptr: res = str(ffi.buffer(key.dptr, key.dsize)) lib.free(key.dptr) return res
def __keys(self): self.__check_closed() l = [] key = lib.gdbm_firstkey(self.__ll_dbm) while key.dptr: l.append(bytes(ffi.buffer(key.dptr, key.dsize))) nextkey = lib.gdbm_nextkey(self.__ll_dbm, key) lib.free(key.dptr) key = nextkey return l
def get(self, key, default=None): with _lock: self.__check_closed() key = _checkstr(key) drec = lib.pygdbm_fetch(self.__ll_dbm, key, len(key)) if not drec.dptr: return default res = bytes(ffi.buffer(drec.dptr, drec.dsize)) lib.free(drec.dptr) return res
def __getitem__(self, key): with _lock: self.__check_closed() key = _checkstr(key) drec = lib.pygdbm_fetch(self.__ll_dbm, key, len(key)) if not drec.dptr: raise KeyError(key) res = str(ffi.buffer(drec.dptr, drec.dsize)) lib.free(drec.dptr) return res
def __keys(self): self.__check_closed() l = [] key = lib.gdbm_firstkey(self.__ll_dbm) while key.dptr: l.append(str(ffi.buffer(key.dptr, key.dsize))) nextkey = lib.gdbm_nextkey(self.__ll_dbm, key) lib.free(key.dptr) key = nextkey return l