示例#1
0
 def __init__(self, shmdict, type='keys'):
     self.dict = shmdict.get_ptr()
     self.node = py2shmobj.shmdict_first(self.dict)
     if type == 'values':
         self.__val = self.__value
     elif type == 'items':
         self.__val = self.__item
     else:
         self.__val = self.__key
示例#2
0
 def popitem(self):
     SHMOBJ.protect(self)
     np = py2shmobj.shmdict_first(self.addr)
     if np:
         kp = py2shmobj.shmdnode_getkey(np)
         key = SHMSTR(kp,internal=True)
         val = self.pop(key, deletekey=False)
         return (key, val)
     else:
         raise KeyError('popitem(): SHMDCT is empty')
示例#3
0
 def clear(self, shallow=False):
     SHMOBJ.protect(self)
     np = py2shmobj.shmdict_first(self.addr)
     while np:
         (p,datatype,datalen) = py2shmobj.shmdnode_get(np)
         if not shallow:
             #DE - for now we assume the key is always a SHMSTR
             kp = py2shmobj.shmdnode_getkey(np)
             py2shmobj.shmobj_del(kp)
             val = typed_ptr(p,datatype)
             if type(val) in [SHMLST, SHMDCT]:
                 val.delete(shallow=shallow)
             elif isinstance(val, SHMOBJ):
                 val.delete()
         next = py2shmobj.shmdict_next(self.addr,np)
         py2shmobj.shmdict_remove(self.addr, np)
         py2shmobj.shmobj_del(np)
         np = next
示例#4
0
 def __iter__(self):
     self.node = py2shmobj.shmdict_first(self.dict)
     return self