示例#1
0
    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)
示例#2
0
    def __init__(self, data=None, lock=False):
        '''
        A dictionary or list of tuples of key/value pairs. If lock=True,
        keys cannot be reassigned without first deleting the item
        '''
#        super(ListDict, self).__setattr__('__lock', lock)
        _odict.__setattr__(self, '__lock', lock)
        #self.__lock = lock #setattr__(self, '__lock', lock)
        if isinstance(data, dict):
            data = [ i for i in data.items() ]
        data = make_safe(data)
        _odict.__init__(self, data)
        if data:
            self.__dict__.update(data)
示例#3
0
    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'