]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/mw/lib/reverts/functions.py
Initial commit
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / mw / lib / reverts / functions.py
1 from .detector import Detector
2 from . import defaults
3
4
5 def detect(checksum_revisions, radius=defaults.RADIUS):
6     """
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.
9
10     This function serves as a convenience wrapper around calls to
11     :class:`Detector`'s :meth:`~Detector.process`
12     method.
13
14     :Parameters:
15         checksum_revisions : iter( ( checksum : str, revision : `mixed` ) )
16             an iterable over tuples of checksum and revision meta data
17         radius : int
18             a positive integer indicating the maximum revision distance that a revert can span.
19
20     :Return:
21         a iterator over :class:`Revert`
22
23     :Example:
24         >>> from mw.lib import reverts
25         >>>
26         >>> checksum_revisions = [
27         ...     ("aaa", {'rev_id': 1}),
28         ...     ("bbb", {'rev_id': 2}),
29         ...     ("aaa", {'rev_id': 3}),
30         ...     ("ccc", {'rev_id': 4})
31         ... ]
32         >>>
33         >>> list(reverts.detect(checksum_revisions))
34         [Revert(reverting={'rev_id': 3}, reverteds=[{'rev_id': 2}], reverted_to={'rev_id': 1})]
35
36     """
37
38     revert_detector = Detector(radius)
39
40     for checksum, revision in checksum_revisions:
41         revert = revert_detector.process(checksum, revision)
42         if revert is not None:
43             yield revert
44
45 # For backwards compatibility
46 reverts = detect

Community Data Science Collective || Want to submit a patch?