jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Add force option to APISite.getuserinfo ......................................................................
[IMPROV] Add force option to APISite.getuserinfo
Change-Id: I6dd0563c373119c6723c833fd8285901d01682ba --- M pywikibot/site.py 1 file changed, 7 insertions(+), 11 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index ccc11c6..81ea424 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1813,10 +1813,8 @@ return # check whether a login cookie already exists for this user self._loginstatus = LoginStatus.IN_PROGRESS - if hasattr(self, "_userinfo"): - del self._userinfo try: - self.getuserinfo() + self.getuserinfo(force=True) if self.userinfo['name'] == self._username[sysop] and \ self.logged_in(sysop): return @@ -1826,9 +1824,7 @@ user=self._username[sysop]) if loginMan.login(retry=True): self._username[sysop] = loginMan.username - if hasattr(self, "_userinfo"): - del self._userinfo - self.getuserinfo() + self.getuserinfo(force=True) self._loginstatus = (LoginStatus.AS_SYSOP if sysop else LoginStatus.AS_USER) else: @@ -1846,11 +1842,9 @@ uirequest = self._simple_request(action='logout') uirequest.submit() self._loginstatus = LoginStatus.NOT_LOGGED_IN - if hasattr(self, "_userinfo"): - del self._userinfo - self.getuserinfo() + self.getuserinfo(force=True)
- def getuserinfo(self): + def getuserinfo(self, force=False): """Retrieve userinfo from site and store in _userinfo attribute.
self._userinfo will be a dict with the following keys and values: @@ -1863,8 +1857,10 @@ - message: present if user has a new message on talk page - blockinfo: present if user is blocked (dict)
+ @param force: force to retrieve userinfo ignoring cache + @type force: bool """ - if (not hasattr(self, '_userinfo') or + if (not hasattr(self, '_userinfo') or force or 'rights' not in self._userinfo or self._userinfo['name'] != self._username['sysop' in self._userinfo['groups']]): uirequest = self._simple_request(