def __setattr__(self, key, value): from types import StringType if type(key) is not StringType: raise KeyError, 'Key was not a string or integer' if key in self and _odict.__getattribute__(self, '__lock'): raise KeyError, 'Dictionary is locked, delete item to reassign to key' _odict.__setattr__(self, key, value) if key in ['_OrderedDict__end', '_OrderedDict__map'] or key.startswith('__'): return # ignore internal attributes used by ordereddict implementation _odict.__setitem__(self, key, value)
def __setitem__(self, key, value): ''' Key can be a number (integer) in which case set value at index of key list ''' from types import StringType, IntType if type(key) is IntType: if key > len(self): raise IndexError, 'Key was too large' key = _odict.keys(self)[key] if type(key) is StringType: key = sanitise_name(key) if key in self and _odict.__getattribute__(self, '__lock'): raise KeyError, 'Dictionary is locked, delete item to reassign to key' _odict.__setitem__(self, key, value) _odict.__setattr__(self, key, value) else: raise KeyError, 'Key was not a string or integer'