jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Tokens: Only load all tokens if it can be done in one request ......................................................................
[IMPROV] Tokens: Only load all tokens if it can be done in one request
Change-Id: I48f3424399c82083c7f13481f0d103780113fcb1 --- M pywikibot/site.py 1 file changed, 15 insertions(+), 6 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index 82a7299..70356d9 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1191,7 +1191,15 @@ self.failed_cache = set() # cache unavailable tokens.
def load_tokens(self, types, all=False): - """Preload one or multiple tokens.""" + """ + Preload one or multiple tokens. + + @param types: the types of token. + @type types: iterable + @param all: load all available tokens, if None only if it can be done + in one request. + @type all: bool + """ assert(self.site.logged_in())
self._tokens.setdefault(self.site.user(), {}).update( @@ -1201,7 +1209,7 @@ # When all=True types is extended in site.get_tokens(). # Keys not recognised as tokens, are cached so they are not requested # any longer. - if all: + if all is not False: for key in types: if key not in self._tokens[self.site.user()]: self.failed_cache.add((self.site.user(), key)) @@ -1222,7 +1230,7 @@
if (key not in user_tokens and failed_cache_key not in self.failed_cache): - self.load_tokens([key], all=not user_tokens) + self.load_tokens([key], all=False if user_tokens else None)
if key in user_tokens: return user_tokens[key] @@ -2403,7 +2411,8 @@ @param types: the types of token (e.g., "edit", "move", "delete"); see API documentation for full list of types @type types: iterable - @param all: load all available tokens + @param all: load all available tokens, if None only if it can be done + in one request. @type all: bool
return: a dict with retrieved valid tokens. @@ -2434,12 +2443,12 @@
else: if _version < LV('1.24wmf19'): - if all: + if all is not False: types.extend(self.TOKENS_1) req = api.Request(site=self, action='tokens', type='|'.join(self.validate_tokens(types))) else: - if all: + if all is not False: types.extend(self.TOKENS_2)
req = api.Request(site=self, action='query', meta='tokens',
pywikibot-commits@lists.wikimedia.org