def _MI_setitem(self, args, value):
indices = self.indices<EOL>N = len(indices)<EOL>empty = N == <NUM_LIT:0><EOL>if empty: <EOL><INDENT>index1, key, index2, index1_last = MI_parse_args(self, args, allow_new=True)<EOL>exist_names = [index1]<EOL>item = [key]<EOL>try:<EOL><INDENT>MI_check_index_name(index2)<EOL>exist_names.append(index2)<EOL>item.append(value)<EOL><DEDENT>except TypeError:<EOL><INDENT>Nvalue, value = get_value_len(value)<EOL>if len(index2) != Nvalue:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (len(index2), index2, Nvalue))<EOL><DEDENT>exist_names.extend(index2)<EOL>item.extend(value)<EOL><DEDENT>if index1_last:<EOL><INDENT>exist_names = exist_names[<NUM_LIT:1>:] + exist_names[:<NUM_LIT:1>]<EOL>item = item[<NUM_LIT:1>:] + item[:<NUM_LIT:1>]<EOL><DEDENT>_MI_init(self, [item], exist_names)<EOL>return<EOL><DEDENT>index1, key, index2, item, old_value = MI_parse_args(self, args, allow_new=True)<EOL>names = force_list(indices.keys())<EOL>is_new_key = item is None<EOL>single = isinstance(index2, int)<EOL>if single:<EOL><INDENT>index2_list = [index2]<EOL>value = [value]<EOL>old_value = [old_value]<EOL><DEDENT>else:<EOL><INDENT>index2_list = index2<EOL>Nvalue, value = get_value_len(value)<EOL>if len(index2_list) != Nvalue:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>' % (len(index2_list), index2, Nvalue))<EOL><DEDENT>if is_new_key:<EOL><INDENT>old_value = [None] * Nvalue  <EOL><DEDENT><DEDENT>index2_d = OrderedDict()<EOL>for e, index in enumerate(index2_list):<EOL><INDENT>index2_d[index] = e <EOL><DEDENT>if len(index2_d) < len(index2_list): <EOL><INDENT>idx = index2_d.values()<EOL>index2_list = mget_list(index2_list, idx)<EOL>value = mget_list(value, idx)<EOL>old_value = mget_list(old_value, idx)<EOL><DEDENT>for i, v, old_v in zip(index2_list, value, old_value):<EOL><INDENT>if v in indices[i]:<EOL><INDENT>if is_new_key or v != old_v:<EOL><INDENT>raise ValueExistsError(v, i, names[i])<EOL><DEDENT><DEDENT><DEDENT>if is_new_key:<EOL><INDENT>if set(index2_list + [index1]) != set(range(N)):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>d = {}<EOL>d[index1] = key<EOL>d.update(zip(index2_list, value))<EOL>values = [d[i] for i in range(N)]  <EOL>key = values[<NUM_LIT:0>]<EOL>val = values[<NUM_LIT:1>] if len(values) == <NUM_LIT:2> else values[<NUM_LIT:1>:]<EOL>super(MIMapping, self).__setitem__(key, val)<EOL>for i, v in zip(names[<NUM_LIT:1>:], values[<NUM_LIT:1>:]):<EOL><INDENT>indices[i][v] = key<EOL><DEDENT><DEDENT>else: <EOL><INDENT>import pdb;pdb.set_trace()<EOL>
Separate __setitem__ function of MIMapping