Example #1
0
 def next(self):
     if self.node:
         (p,datatype,datalen) = py2shmobj.shmlnode_get(self.node)
         obj = typed_ptr(p,datatype)
         self.node = py2shmobj.shmlist_prev(self.list, self.node)
         return obj
     else:
         raise StopIteration
Example #2
0
 def remove(self, item):
     SHMOBJ.protect(self)
     np = py2shmobj.shmlist_first(self.addr)
     while np:
         (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
         obj = typed_ptr(p,datatype)
         if obj == item:
             py2shmobj.shmlist_remove(self.addr, np)
             return None
         np = py2shmobj.shmlist_next(self.addr,np)
Example #3
0
 def count(self, arg):
     SHMOBJ.protect(self)
     count = 0
     np = py2shmobj.shmlist_first(self.addr)
     while np:
         (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
         obj = typed_ptr(p,datatype)
         if obj == arg:
             count += 1
         np = py2shmobj.shmlist_next(self.addr,np)
     return count
Example #4
0
 def index(self, item, begIdx=0, endIdx=sys.maxint):
     SHMOBJ.protect(self)
     idx = 0
     np = py2shmobj.shmlist_getnode(self.addr, begIdx)
     while np and idx < endIdx:
         (p,datatype,datalen) = py2shmobj.shmlnode_get(np)
         obj = typed_ptr(p,datatype)
         if obj == item:
             return idx
         np = py2shmobj.shmlist_next(self.addr,np)
         idx += 1
     raise ValueError
Example #5
0
 def __getitem__(self,idx):
     SHMOBJ.protect(self)
     if idx < 0:
         idx += len(self)
     if idx < 0 or not type(idx) in [int, SHMINT]:
         raise IndexError
     np = py2shmobj.shmlist_getnode(self.addr, idx)
     if np:
         (ep,datatype,datalen) = py2shmobj.shmlnode_get(np)
         return typed_ptr(ep,datatype)
     else:
         raise IndexError
Example #6
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 #7
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 #8
0
    def __getslice__(self,idx_a,idx_b):
        SHMOBJ.protect(self)
        slice = []

        if idx_b == sys.maxint:
            idx_b = len(self)

        if idx_a < 0:
            idx_a += len(self)
            if idx_a < 0:
                idx_a = 0
        if idx_a > len(self):
            idx_a = len(self)

        if idx_b < 0:
            idx_b += len(self)
            if idx_b < 0:
                idx_b = 0
        if idx_b > len(self):
            idx_b = len(self)

        if idx_b <= idx_a: 
            return slice

        if idx_a < 0 or idx_b < 0 or idx_a > len(self) or idx_b > len(self):
            raise IndexError

        i = idx_a
        np = py2shmobj.shmlist_getnode(self.addr, idx_a)
        while np and i < idx_b:
            (ep,datatype,datalen) = py2shmobj.shmlnode_get(np)
            slice.append(typed_ptr(ep,datatype))
            np = py2shmobj.shmlist_next(self.addr,np)
            i += 1
        if i < idx_b:
            raise IndexError
        return slice