示例#1
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
示例#2
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
示例#3
0
 def __setitem__(self,idx,arg):
     SHMOBJ.protect(self)
     #### RMB: VERIFY THAT ARG IS ALREADY SHMOBJ
     if not isinstance(arg, SHMOBJ):
         raise TypeError("** invalid type being replaced in shmlist")
     datatype, datalen = get_type_and_len(arg)
     np = py2shmobj.shmlist_getnode(self.addr, idx)
     if np:
         ep = arg.get_ptr()
         py2shmobj.shmlnode_put(np,ep,datatype,datalen)
         return None
     else:
         raise IndexError
示例#4
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)
示例#5
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