def add_item(self, key, value, after=False, index=None, pos_key=None,<EOL>replace=True):
if self._validate_fn:<EOL><INDENT>self._validate_fn(value)<EOL><DEDENT>if (index is not None) and (pos_key is not None):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>elif pos_key is not None:<EOL><INDENT>try:<EOL><INDENT>index = self.index(pos_key)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise KeyError('<STR_LIT>' % pos_key)<EOL><DEDENT><DEDENT>if after and (index is not None):<EOL><INDENT>index += <NUM_LIT:1><EOL><DEDENT>if key in self._values:<EOL><INDENT>if not replace:<EOL><INDENT>raise KeyError('<STR_LIT>' % key)<EOL><DEDENT>if index is not None:<EOL><INDENT>del self[key]<EOL><DEDENT>else:<EOL><INDENT>self._values[key] = value<EOL>return<EOL><DEDENT><DEDENT>if index is not None:<EOL><INDENT>self._order.insert(index, key)<EOL><DEDENT>else:<EOL><INDENT>self._order.append(key)<EOL><DEDENT>self._values[key] = value<EOL>
Add an item at a specific location, possibly replacing the
existing item.

If after is True, we insert *after* the given index, otherwise we
insert before.

The position is specified using either index or pos_key, the former
specifies the position from the start of the array (base 0).  pos_key
specifies the name of another key, and positions the new key relative
to that key.

When replacing, the position will be left un-changed unless a location
is specified explicitly.