Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
 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