def __delitem__(self, key): ''' 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: _odict.__delitem__(self, key) _odict.__delattr__(self, key) else: raise KeyError, 'Key was not a string or integer'
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'