jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1300722?usp=email )
Change subject: TokenWallet: Reload a single token if missing in the dict
......................................................................
TokenWallet: Reload a single token if missing in the dict
Bug: T428817
Bug: T343187
Change-Id: I7d3fa81a66f3e577210f95576866f9cbbb8eec61
---
M pywikibot/site/_tokenwallet.py
1 file changed, 9 insertions(+), 5 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/site/_tokenwallet.py b/pywikibot/site/_tokenwallet.py
index b404c35..b5928ba 100644
--- a/pywikibot/site/_tokenwallet.py
+++ b/pywikibot/site/_tokenwallet.py
@@ -21,6 +21,11 @@
You should not use this container class directly; use
:attr:`APISite.tokens<pywikibot.site._apisite.APISite.tokens>`
instead which gives access to the site's TokenWallet instance.
+
+ .. version-changed:: 11.0
+ Support of legacy API tokens was dropped.
+ .. version-changed:: 11.4
+ Reload a single token if missing.
"""
def __init__(self, site: APISite) -> None:
@@ -32,11 +37,7 @@
self._last_token_key: str | None = None
def __getitem__(self, key: str) -> str:
- """Get token value for the given key.
-
- .. version-changed:: 11.0
- Support of legacy API tokens was dropped.
- """
+ """Get token value for the given key."""
if self.site.user() is None and key != 'login':
self.site.login()
@@ -47,6 +48,9 @@
if not self._tokens:
self._tokens = self.site.get_tokens([])
+ if key not in self._tokens:
+ self._tokens.update(self.site.get_tokens([key]))
+
try:
token = self._tokens[key]
except KeyError:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1300722?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I7d3fa81a66f3e577210f95576866f9cbbb8eec61
Gerrit-Change-Number: 1300722
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: JAn Dudík <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Mykhal <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]