Revision: 7979 Author: valhallasw Date: 2010-03-05 23:38:37 +0000 (Fri, 05 Mar 2010)
Log Message: ----------- Added Exception to filter IP address users, which are not supported by the API. This partially fixes issue #2929350
Modified Paths: -------------- trunk/pywikipedia/userlib.py
Modified: trunk/pywikipedia/userlib.py =================================================================== --- trunk/pywikipedia/userlib.py 2010-03-05 23:38:35 UTC (rev 7978) +++ trunk/pywikipedia/userlib.py 2010-03-05 23:38:37 UTC (rev 7979) @@ -32,6 +32,10 @@
class AlreadyUnblocked(UnblockError): pass
+class InvalidUser(wikipedia.InvalidTitle): + """The mediawiki API does not allow IP lookups.""" + pass + class User(object): """ A class that represents a Wiki user. @@ -606,14 +610,19 @@ #if self._blocked: #Get block ID
def getData(self): - datas = {} + users = {} params = { 'action': 'query', 'list': 'users', 'usprop': ['blockinfo', 'groups', 'editcount', 'registration', 'emailable', 'gender'], 'ususers': u'|'.join([n.name() for n in self.users]), } - return dict([(n['name'], n) for n in query.GetData(params, self.site)['query']['users']]) + data = query.GetData(params, self.site) + for user in data['query']['users']: + if u'invalid' in user: + raise InvalidUser("User name '%s' is invalid. IP addresses are not supported." % user['name']) + users[user['name']] = user + return users
if __name__ == '__main__': """
pywikipedia-svn@lists.wikimedia.org