def __setitem__(self, key, value): # Invalidate cache for given key if self.cache and key in self._cache: del self._cache[key] if self._keys is None: keys = self._get_data() else: keys = self._keys if isinstance(value, dbbase._dbbase): reobj = value else: reobj = dbbase._retype(value)(self._conn) reobj._initialize(value) if key in keys: self._get(keys[key])._ref_dec() keys[key] = reobj._id reobj._ref_inc() # Rewrite self._set(keys) # Reset cache self._keys = None
def __setitem__(self, index, value): if self._keys is None: self._keys = keys = self._get_data() else: keys = self._keys if index >= len(keys): raise Exception("Index %d is out of bounds" % index) if isinstance(value, dbbase._dbbase): reobj = value else: reobj = dbbase._retype(value)(self._conn) reobj._initialize(value) self._get(keys[index])._ref_dec() keys[index] = reobj._id reobj._ref_inc() # Rewrite self._set(keys) # Reset cache self._keys = None # Delete cached item if self.cache: del self._cache[index]
def _initialize(self, data): keys = [] for d in data: reobj = dbbase._retype(d)(self._conn) reobj._initialize(d) keys.append(reobj._id) reobj._ref_inc() self._set(keys)
def _initialize(self, data): keys = {} # Set data for k in data.keys(): reobj = dbbase._retype(data[k])(self._conn) reobj._initialize(data[k]) keys[k] = reobj._id reobj._ref_inc() self._set(keys)
def append(self, data): if self._keys is None: self._keys = keys = self._get_data() else: keys = self._keys reobj = dbbase._retype(data)(self._conn) reobj._initialize(data) keys.append(reobj._id) reobj._ref_inc() self._set(keys) # Invalidate cache self._keys = None