Example #1
0
    def delitem(self, idx, shallow=False):
        SHMOBJ.protect(self)
        np = py2shmobj.shmlist_getnode(self.addr, idx)
        if not np:
            raise IndexError

        if not shallow:
            (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
            if p:
                obj = typed_ptr(p,datatype)
                if isinstance(obj, SHMLST): 
                    obj.delete(shallow=shallow)
                else:
                    obj.delete()

        py2shmobj.shmlist_remove(self.addr,np)
        py2shmobj.shmobj_del(np)
Example #2
0
 def delete(self, shallow=False):
     SHMOBJ.protect(self)
     np = py2shmobj.shmlist_first(self.addr)
     while np:
         if not shallow:
             (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
             if p:
                 val = typed_ptr(p,datatype)
                 if type(val) in [SHMLST, SHMDCT]:
                     val.delete(shallow=shallow)
                 elif isinstance(val, SHMOBJ):
                     val.delete()
         next = py2shmobj.shmlist_next(self.addr,np)
         py2shmobj.shmlist_remove(self.addr, np)
         py2shmobj.shmobj_del(np)
         np = next
     SHMOBJ.delete(self)
Example #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
Example #4
0
 def pop(self, key, defval=None, deletekey=True):
     SHMOBJ.protect(self)
     if isinstance(key, SHMSTR):
         key = str(key)
     if not isinstance(key, str):
         raise TypeError("** error: SHMDCT.pop only takes SHMSTR or str for key")
     np = py2shmobj.shmdict_lookup(self.addr, key)
     if np:
         kp = py2shmobj.shmdnode_getkey(np)
         (ep,datatype,datalen) = py2shmobj.shmdnode_get(np)
         py2shmobj.shmdict_remove(self.addr, np)
         py2shmobj.shmobj_del(np)
         if deletekey == True:
             py2shmobj.shmobj_del(kp)
         return typed_ptr(ep,datatype)
     if defval:
         return defval
     else:
         raise KeyError(key)
Example #5
0
 def delete(self):
     self.protect()
     py2shmobj.shmobj_del(self.addr)
     self.addr = None