def _p_resolveConflict(self, old, committed, new): oldob = State(old) committedob = State(committed) newob = State(new) if not oldob.period == committedob.period == newob.period: raise ConflictError('Conflicting periods') if not oldob.timeout == committedob.timeout == newob.timeout: raise ConflictError('Conflicting timeouts') o_head, o_tail = _head_and_tail(oldob) c_head, c_tail = _head_and_tail(committedob) n_head, n_tail = _head_and_tail(newob) # We are operating on the __setstate__ representation of the # attached ListNodes (no clue why, we're operating on the # __getstate__ representation of the PersistentMapping object # in SessionDataObject). o_head_ts = o_head.ob[0] if o_head_ts < c_tail.ob[0]: raise ConflictError('Committed has obsoleted old') if o_head_ts < n_tail.ob[0]: raise ConflictError('New has obsoleted old') # find any slices added in 'new' n_added = _prefix(n_head, o_head_ts) # and portion of 'committed' newer than new's tail. c_rest = _prefix(c_head, n_tail.ob[0], include_match=True) head = deserialize(n_added + c_rest) new['head'] = head return new
def test_deserialize(self): from repoze.session import linkedlist testseq = [1, 2, 7, 10, None, unittest] node = linkedlist.deserialize(testseq) for item in testseq: self.assertEqual(node.ob, item) node = node.next self.assertEqual(node, None)
def test_pickle(self): from repoze.session._compat import pickle from repoze.session import linkedlist import string node = linkedlist.deserialize(range(26)) dumped_data = pickle.dumps(linkedlist.serialize(node), 2) dumped_node = pickle.dumps(node, 2) new_node = pickle.loads(dumped_node) self.assertEqual(linkedlist.serialize(new_node), linkedlist.serialize(node)) # Efficient pickling uses list repr self.failUnless(dumped_data[5:-1] in dumped_node)
def test_repr(self): from repoze.session import linkedlist testseq = [1] node = linkedlist.deserialize(testseq) self.failUnless(repr(node).startswith('<ListNode object'))