Exemplo n.º 1
0
 def _hasattribute(obj, name):
     try:
         _getattribute(obj, name)
     except AttributeError:
         return False
     else:
         return True
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
 def __setstate__(self, state):
     self_dict = _getattribute(self, '__dict__')
     self_dict.clear()
     self_dict.update(state)