'Allows slice assignment, so long as the slice is an OrderedDict
>>> d = OrderedDict()
>>> d[\'a\'] = \'b\'
>>> d[\'b\'] = \'a\'
>>> d[3] = 12
>>> d
OrderedDict([(\'a\', \'b\'), (\'b\', \'a\'), (3, 12)])
>>> d[:] = OrderedDict(((1, 2), (2, 3), (3, 4)))
>>> d
OrderedDict([(1, 2), (2, 3), (3, 4)])
>>> d[::2] = OrderedDict(((7, 8), (9, 10)))
>>> d
OrderedDict([(7, 8), (2, 3), (9, 10)])
>>> d = OrderedDict(((0, 1), (1, 2), (2, 3), (3, 4)))
>>> d[1:3] = OrderedDict(((1, 2), (5, 6), (7, 8)))
>>> d
OrderedDict([(0, 1), (1, 2), (5, 6), (7, 8), (3, 4)])
>>> d = OrderedDict(((0, 1), (1, 2), (2, 3), (3, 4)), strict=True)
>>> d[1:3] = OrderedDict(((1, 2), (5, 6), (7, 8)))
>>> d
OrderedDict([(0, 1), (1, 2), (5, 6), (7, 8), (3, 4)])
>>> a = OrderedDict(((0, 1), (1, 2), (2, 3)), strict=True)
>>> a[3] = 4
>>> a
OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a[::1] = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a
OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a[:2] = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4), (4, 5)])
Traceback (most recent call last):
ValueError: slice assignment must be from unique keys
>>> a = OrderedDict(((0, 1), (1, 2), (2, 3)))
>>> a[3] = 4
>>> a
OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a[::1] = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a
OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a[:2] = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a
OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a[::-1] = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> a
OrderedDict([(3, 4), (2, 3), (1, 2), (0, 1)])
>>> d = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> d[:1] = 3
Traceback (most recent call last):
TypeError: slice assignment requires an OrderedDict
>>> d = OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> d[:1] = OrderedDict([(9, 8)])
>>> d
OrderedDict([(9, 8), (1, 2), (2, 3), (3, 4)])'

def __setitem__(self, key, val):

    if isinstance(key, types.SliceType):
        if (not isinstance(val, OrderedDict)):
            raise TypeError('slice    assignment    requires    an    OrderedDict')
        keys = self._sequence[key]
        indexes = range(len(self._sequence))[key]
        if (key.step is None):
            pos = (key.start or 0)
            del self[key]
            newkeys = val.keys()
            for k in newkeys:
                if (k in self):
                    if self.strict:
                        raise ValueError('slice    assignment    must    be    from    unique    keys')
                    else:
                        del self[k]
            self._sequence = ((self._sequence[:pos] + newkeys) + self._sequence[pos:])
            dict.update(self, val)
        else:
            if (len(keys) != len(val)):
                raise ValueError(('attempt    to    assign    sequence    of    size    %s    to    extended    slice    of    size    %s' % (len(val), len(keys))))
            del self[key]
            item_list = zip(indexes, val.items())
            item_list.sort()
            for (pos, (newkey, newval)) in item_list:
                if (self.strict and (newkey in self)):
                    raise ValueError('slice    assignment    must    be    from    unique    keys')
                self.insert(pos, newkey, newval)
    else:
        if (key not in self):
            self._sequence.append(key)
        dict.__setitem__(self, key, val)
