MCPcopy Create free account
hub / github.com/couchbase/couchbase-python-client / MutationState

Class MutationState

couchbase/mutation_state.py:28–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27
28class MutationState:
29 def __init__(self, *docs, # type: List[MutationResult]
30 **kwargs # type: Dict[str, Any]
31 ):
32 self._sv = set()
33 if docs:
34 self.add_results(*docs, **kwargs)
35
36 def add_mutation_token(self, mut_token # type: MutationToken
37 ) -> None:
38 if isinstance(mut_token, MutationToken):
39 self._sv.add(mut_token)
40
41 def _add_scanvec(self, mut_token # type: MutationToken
42 ) -> bool:
43 """
44 Internal method used to specify a scan vector.
45 :param mut_token: A tuple in the form of
46 `(vbucket id, vbucket uuid, mutation sequence)`
47 """
48 if isinstance(mut_token, MutationToken):
49 self._sv.add(mut_token)
50 return True
51
52 return False
53
54 def add_results(self, *rvs, # type: List[MutationResult]
55 **kwargs # type: Dict[str, Any]
56 ) -> bool:
57 """
58 Changes the state to reflect the mutation which yielded the given
59 result.
60
61 In order to use the result, the `enable_mutation_tokens` option must
62 have been specified in the connection string, _and_ the result
63 must have been successful.
64
65 :param rvs: One or more :class:`~.OperationResult` which have been
66 returned from mutations
67 :param quiet: Suppress errors if one of the results does not
68 contain a convertible state.
69 :return: `True` if the result was valid and added, `False` if not
70 added (and `quiet` was specified
71 :raise: :exc:`~.MissingTokenException` if `result` does not contain
72 a valid token
73 """
74 if not rvs:
75 raise MissingTokenException(message='No results passed')
76 for rv in rvs:
77 mut_token = rv.mutation_token()
78 if not isinstance(mut_token, MutationToken):
79 if kwargs.get('quiet', False) is True:
80 return False
81 raise MissingTokenException(
82 message='Result does not contain token')
83 if not self._add_scanvec(mut_token):
84 return False
85 return True

Callers 15

test_mutation_stateMethod · 0.90
_mutation_stateMethod · 0.90
test_consistent_withMethod · 0.90
test_consistent_withMethod · 0.90
test_query_ryowMethod · 0.90
test_query_ryowMethod · 0.90
test_mutation_stateMethod · 0.90
test_query_ryowMethod · 0.90
test_query_ryowMethod · 0.90

Calls

no outgoing calls

Tested by 11

test_mutation_stateMethod · 0.72
test_consistent_withMethod · 0.72
test_consistent_withMethod · 0.72
test_query_ryowMethod · 0.72
test_query_ryowMethod · 0.72
test_mutation_stateMethod · 0.72
test_query_ryowMethod · 0.72
test_query_ryowMethod · 0.72