def descr_insert(self, space, w_idx, w_other): where = space.int_w(w_idx) length = len(self.data) index = get_positive_index(where, length) val = getbytevalue(space, w_other) self.data.insert(index, val) return space.w_None
def descr_setitem(self, space, w_index, w_other): if isinstance(w_index, W_SliceObject): oldsize = len(self.data) start, stop, step, slicelength = w_index.indices4(space, oldsize) sequence2 = makebytesdata_w(space, w_other) _setitem_slice_helper(space, self.data, start, step, slicelength, sequence2, empty_elem='\x00') else: idx = space.getindex_w(w_index, space.w_IndexError, "bytearray index") try: self.data[idx] = getbytevalue(space, w_other) except IndexError: raise oefmt(space.w_IndexError, "bytearray index out of range")
def unwrap_value(space, push_func, add_arg, argdesc, letter, w_arg): w = space.wrap if letter in TYPEMAP_PTR_LETTERS: # check for NULL ptr if isinstance(w_arg, W_DataInstance): ptr = w_arg.ll_buffer else: ptr = unwrap_truncate_int(rffi.VOIDP, space, w_arg) push_func(add_arg, argdesc, ptr) elif letter == "d": push_func(add_arg, argdesc, space.float_w(w_arg)) elif letter == "f": push_func(add_arg, argdesc, rffi.cast(rffi.FLOAT, space.float_w(w_arg))) elif letter == "g": push_func(add_arg, argdesc, rffi.cast(rffi.LONGDOUBLE, space.float_w(w_arg))) elif letter == "c": if space.isinstance_w(w_arg, space.w_int): val = getbytevalue(space, w_arg) else: s = space.str_w(w_arg) if len(s) != 1: raise OperationError( space.w_TypeError, w("Expected string of length one as character")) val = s[0] push_func(add_arg, argdesc, val) elif letter == 'u': s = space.unicode_w(w_arg) if len(s) != 1: raise OperationError( space.w_TypeError, w("Expected unicode string of length one as wide character")) val = s[0] push_func(add_arg, argdesc, val) else: for c in unroll_letters_for_numbers: if letter == c: TP = LL_TYPEMAP[c] val = unwrap_truncate_int(TP, space, w_arg) push_func(add_arg, argdesc, val) return else: raise OperationError(space.w_TypeError, space.wrap("cannot directly write value"))
def unwrap_value(space, push_func, add_arg, argdesc, letter, w_arg): w = space.wrap if letter in TYPEMAP_PTR_LETTERS: # check for NULL ptr if isinstance(w_arg, W_DataInstance): ptr = w_arg.ll_buffer else: ptr = unwrap_truncate_int(rffi.VOIDP, space, w_arg) push_func(add_arg, argdesc, ptr) elif letter == "d": push_func(add_arg, argdesc, space.float_w(w_arg)) elif letter == "f": push_func(add_arg, argdesc, rffi.cast(rffi.FLOAT, space.float_w(w_arg))) elif letter == "g": push_func(add_arg, argdesc, rffi.cast(rffi.LONGDOUBLE, space.float_w(w_arg))) elif letter == "c": if space.isinstance_w(w_arg, space.w_int): val = getbytevalue(space, w_arg) else: s = space.str_w(w_arg) if len(s) != 1: raise OperationError(space.w_TypeError, w( "Expected string of length one as character")) val = s[0] push_func(add_arg, argdesc, val) elif letter == 'u': s = space.unicode_w(w_arg) if len(s) != 1: raise OperationError(space.w_TypeError, w( "Expected unicode string of length one as wide character")) val = s[0] push_func(add_arg, argdesc, val) else: for c in unroll_letters_for_numbers: if letter == c: TP = LL_TYPEMAP[c] val = unwrap_truncate_int(TP, space, w_arg) push_func(add_arg, argdesc, val) return else: raise OperationError(space.w_TypeError, space.wrap("cannot directly write value"))
def descr_append(self, space, w_item): self.data.append(getbytevalue(space, w_item))