3 from ...util import none_or
4 from ..errors import MalformedResponse
5 from .collection import Collection
7 logger = logging.getLogger("mw.api.collections.users")
10 class Users(Collection):
12 A collection of information about users
15 PROPERTIES = {'blockinfo', 'implicitgroups', 'groups', 'registration',
16 'emailable', 'editcount', 'gender'}
18 SHOW = {'minor', '!minor', 'patrolled', '!patrolled'}
22 def query(self, *args, **kwargs):
24 Get a user's metadata.
25 See `<https://www.mediawiki.org/wiki/API:Users>`_
29 The usernames of the users to be retrieved.
32 Include additional pieces of information
34 blockinfo - Tags if the user is blocked, by whom, and
36 groups - Lists all the groups the user(s) belongs to
37 implicitgroups - Lists all the groups a user is automatically
39 rights - Lists all the rights the user(s) has
40 editcount - Adds the user's edit count
41 registration - Adds the user's registration timestamp
42 emailable - Tags if the user can and wants to receive
43 email through [[Special:Emailuser]]
44 gender - Tags the gender of the user. Returns "male",
45 "female", or "unknown"
50 us_docs, query_continue = self._query(*args, **kwargs)
55 if query_continue is None or len(us_docs) == 0:
58 kwargs['query_continue'] = query_continue
60 def _query(self, users, query_continue=None, properties=None):
66 params['ususers'] = self._items(users, type=str)
67 params['usprop'] = self._items(properties, levels=self.PROPERTIES)
68 if query_continue is not None:
69 params.update(query_continue)
71 doc = self.session.get(params)
73 if 'query-continue' in doc:
74 query_continue = doc['query-continue']['users']
78 us_docs = doc['query']['users']
80 return us_docs, query_continue
83 raise MalformedResponse(str(e), doc)