def _hasattribute(obj, name): try: _getattribute(obj, name) except AttributeError: return False else: return True
def __setstate__(self, state): if _hasattribute(self, '__dict__'): _getattribute(self, '__dict__').clear() for name in self._p_gen_data_slots(): _delattribute(self, name) if state is not None: for key, value in iteritems(state): _setattribute(self, key, value)
def __getstate__(self): if self._p_status == GHOST: self._p_load_state() state = {} if _hasattribute(self, '__dict__'): state.update(_getattribute(self, '__dict__')) for name in self._p_gen_data_slots(): state[name] = _getattribute(self, name) return state
def __getattribute__(self, name): if name[:3] != "_p_" and name not in _GHOST_SAFE_ATTRIBUTES: if self._p_status == GHOST: self._p_load_state() connection = self._p_connection if connection is not None and self._p_serial != connection.transaction_serial: connection.note_access(self) return _getattribute(self, name)
def __getattribute__(self, name): if name[:3] != '_p_' and name not in _GHOST_SAFE_ATTRIBUTES: if self._p_status == GHOST: self._p_load_state() connection = self._p_connection if (connection is not None and self._p_serial != connection.transaction_serial): connection.note_access(self) return _getattribute(self, name)
def get(self, compute): """(compute) -> value Compute the value (if necessary) and return it. 'compute' needs to be a function that takes no arguments. """ # we are careful here not to mark object as UNSAVED if _hasattribute(self, 'value'): value = _getattribute(self, 'value') else: value = compute() _setattribute(self, 'value', value) return value
def __setstate__(self, state): self_dict = _getattribute(self, '__dict__') self_dict.clear() self_dict.update(state)