]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/mw/xml_dump/iteration/contributor.py
Initial commit
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / mw / xml_dump / iteration / contributor.py
1 from ...types import serializable
2 from ...util import none_or
3
4 from .util import consume_tags
5
6
7 class Contributor(serializable.Type):
8     """
9     Contributor meta data.
10     """
11     __slots__ = ('id', 'user_text')
12
13     TAG_MAP = {
14         'id': lambda e: int(e.text),
15         'username': lambda e: str(e.text),
16         'ip': lambda e: str(e.text)
17     }
18
19     def __init__(self, id, user_text):
20         self.id = none_or(id, int)
21         """
22         User ID : int | `None` (if not specified in the XML)
23
24         User ID of a user if the contributor is signed into an account
25         in the while making the contribution and `None` when
26         contributors are not signed in.
27         """
28
29         self.user_text = none_or(user_text, str)
30         """
31         User name or IP address : str | `None` (if not specified in the XML)
32
33         If a user is logged in, this will reflect the users accout
34         name. If the user is not logged in, this will usually be
35         recorded as the IPv4 or IPv6 address in the XML.
36         """
37
38     @classmethod
39     def from_element(cls, element):
40         values = consume_tags(cls.TAG_MAP, element)
41
42         return cls(
43             values.get('id'),
44             values.get('username', values.get('ip'))
45         )

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