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 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