Esempio n. 1
0
 def getitem(self, index):
     if isinstance(index, space.Slice):
         start, stop, step = index.clamped(0, self.length - 1)
         if step != 1:
             result = []  # TODO: keep it as Uint8Array?
             for i in range(start, stop, step):
                 result.append(
                     numbers.Integer(rffi.r_long(self.uint8data[i])))
             return space.List(result)
         parent = self.parent if isinstance(self, Uint8Slice) else self
         return Uint8Slice(rffi.ptradd(self.uint8data, start), stop - start,
                           parent)
     index = space.cast(index, numbers.Integer, u"index not an integer")
     if not 0 <= index.value < self.length:
         raise space.unwind(space.LKeyError(self, index))
     return numbers.Integer(rffi.r_long(self.uint8data[index.value]))
Esempio n. 2
0
 def getattr(self, name):
     if name == u'length':
         return numbers.Integer(self.length)
     return Object.getattr(self, name)
Esempio n. 3
0
 def getitem(self, index):
     if not isinstance(index, numbers.Integer):
         raise space.OldError(u"index not an integer")
     if not 0 <= index.value < self.length:
         raise space.OldError(u"index out of range")
     return numbers.Integer(rffi.r_long(self.uint8data[index.value]))