Esempio n. 1
0
 def setitem(self, index, value):
     if not isinstance(index, Integer):
         raise space.unwind(space.LTypeError(u"index not an integer"))
     if not 0 <= index.value < len(self.contents):
         raise space.unwind(space.LKeyError(self, index))
     self.contents[index.value] = value
     return value
Esempio n. 2
0
 def setitem(self, index, value):
     # TODO: Add slice support to this side.
     index = space.cast(index, Integer, u"index not an integer")
     if not 0 <= index.value < len(self.contents):
         raise space.unwind(space.LKeyError(self, index))
     self.contents[index.value] = value
     return value
Esempio n. 3
0
 def setitem(self, index, value):
     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))
     value = space.cast(value, numbers.Integer, u"value not an integer")
     self.uint8data[index.value] = rffi.r_uchar(value.value)
     return value
Esempio n. 4
0
def List_pop(self, index):
    if index:
        index = index.value
    else:
        index = len(self.contents) - 1
    if not 0 <= index < len(self.contents):
        raise space.unwind(space.LKeyError(self, space.Integer(index)))
    return self.contents.pop(index)
Esempio n. 5
0
 def getitem(self, index):
     index = space.cast(index, space.List, u"Multimethod.getitem")
     try:
         vec = [cls.interface.weakref for cls in index.contents]
         item = self.multimethod_table[vec]()
         if item is not None:
             return item
     except KeyError as _:
         pass
     raise space.unwind(space.LKeyError(self, index))
Esempio n. 6
0
 def getitem(self, index):
     if isinstance(index, space.Slice):
         result = []
         start, stop, step = index.clamped(0, len(self.string)-1)
         for i in range(start, stop, step):
             result.append(self.string[i])
         return String(u"".join(result))
     index = space.cast(index, Integer, u"index not an integer")
     if not 0 <= index.value < len(self.string):
         raise space.unwind(space.LKeyError(self, index))
     return String(self.string[index.value])
Esempio n. 7
0
 def getitem(self, index):
     if isinstance(index, space.Slice):
         start, stop, step = index.clamped(0, len(self.contents) - 1)
         result = []
         for i in range(start, stop, step):
             result.append(self.contents[i])
         return List(result)
     index = space.cast(index, Integer, u"index not an integer")
     if not 0 <= index.value < len(self.contents):
         raise space.unwind(space.LKeyError(self, index))
     return self.contents[index.value]
Esempio n. 8
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. 9
0
 def getitem(self, index):
     try:
         return self.data[index]
     except KeyError as _:
         raise space.unwind(space.LKeyError(self, index))
Esempio n. 10
0
 def setitem(self, index, value):
     raise space.unwind(space.LKeyError(self, index))
Esempio n. 11
0
 def getitem(self, index):
     raise space.unwind(space.LKeyError(self, index))
Esempio n. 12
0
def Set_pop(self):
    try:
        return self._set.popitem()[0]
    except KeyError as _:
        raise space.unwind(space.LKeyError(self, null))
    return null
Esempio n. 13
0
def Set_remove(self, obj):
    try:
        del self._set[obj]
    except KeyError as _:
        raise space.unwind(space.LKeyError(self, obj))
    return null
Esempio n. 14
0
def Dict_pop(self, key):
    try:
        return self.data.pop(key)
    except KeyError as error:
        raise space.unwind(space.LKeyError(self, key))
Esempio n. 15
0
 def getitem(self, index):
     index = space.cast(index, space.List, u"Multimethod.getitem")
     try:
         return self.multimethod_table[index.contents]
     except KeyError as _:
         raise space.unwind(space.LKeyError(self, index))
Esempio n. 16
0
def List_insert(self, index, obj):
    val = index.value
    if not 0 <= val <= len(self.contents):
        raise space.unwind(space.LKeyError(self, index))
    self.contents.insert(val, obj)
    return space.null
Esempio n. 17
0
 def getitem(self, index):
     if not isinstance(index, numbers.Integer):
         raise space.unwind(space.LKeyError(self, index))
     if not 0 <= index.value < len(self.string):
         raise space.OldError(u"index out of range")
     return String(self.string[index.value])