1 from .detector import Detector
5 def detect(checksum_revisions, radius=defaults.RADIUS):
7 Detects reverts that occur in a sequence of revisions. Note that,
8 `revision` data meta will simply be returned in the case of a revert.
10 This function serves as a convenience wrapper around calls to
11 :class:`Detector`'s :meth:`~Detector.process`
15 checksum_revisions : iter( ( checksum : str, revision : `mixed` ) )
16 an iterable over tuples of checksum and revision meta data
18 a positive integer indicating the maximum revision distance that a revert can span.
21 a iterator over :class:`Revert`
24 >>> from mw.lib import reverts
26 >>> checksum_revisions = [
27 ... ("aaa", {'rev_id': 1}),
28 ... ("bbb", {'rev_id': 2}),
29 ... ("aaa", {'rev_id': 3}),
30 ... ("ccc", {'rev_id': 4})
33 >>> list(reverts.detect(checksum_revisions))
34 [Revert(reverting={'rev_id': 3}, reverteds=[{'rev_id': 2}], reverted_to={'rev_id': 1})]
38 revert_detector = Detector(radius)
40 for checksum, revision in checksum_revisions:
41 revert = revert_detector.process(checksum, revision)
42 if revert is not None:
45 # For backwards compatibility