def _non_cell_getitem(self, key): """ This method is just a small shortcut """ get_dependant_stack().push(None) try: v = self[key] finally: get_dependant_stack().pop(None) return v
def clear(self): get_dependant_stack().push(None) try: keys = set(self.keys()) finally: get_dependant_stack().pop(None) dict.clear(self) self.changed() for key in keys.intersection(set(self._key_subcells)): self._key_changed(key)
def flush(self, force=False): """ Tell all held observers to check for changes now. Note that this is a possible location for an infinite loop. If an observer changes one of its dependencies, it will again be added to the bank. """ while len(self): if not force and get_dependant_stack()._call_stack: get_dependant_stack().call_when_empty.add(lambda: self.flush()) return self.pop().check()
def update(self, *args, **kwargs): get_dependant_stack().push(None) try: passed_keys = set(kwargs) if args: passed_keys.update(set(args[0])) keys = set(self._key_subcells).intersection(passed_keys) originals = {} missing = set() for key in keys: if self.has_key(key): originals[key] = self[key] else: missing.add(key) finally: get_dependant_stack().pop(None) dict_update(self, *args, **kwargs) self.changed() # Find all of those that were originaly here and have changed. get_dependant_stack().push(None) try: changed = set() for key, v in originals.items(): if v != self[key]: changed.add(key) finally: get_dependant_stack().pop(None) for key in changed | missing: self._key_changed(key)
def _key_accessed(self, key): if get_dependant_stack().current is not None: if not key in self._key_subcells: self._key_subcells[key] = _KeyCell( lambda: self._key_subcells.__delitem__(key)) # XXX By having a reference to ``self`` in the lambda function, # we might be held in memory a lot longer than needed. I don't # know if this is a problem worth fixing. self._key_subcells[key].depended()