jenkins-bot has submitted this change and it was merged.
Change subject: mediawiki_messages reuses QueryGenerator ......................................................................
mediawiki_messages reuses QueryGenerator
When mediawiki_messages is called with a specific set of keys requested, it inefficiently and incorrectly iterates the generator for each key. This breaks a fundamental assumption of a 'generator' - that it can not be re-used. It is assuming that QueryGenerator was able to fetch all the requested messages without continuation, as only the last fetch will exist in QueryGenerator.data after the first iteration is complete.
Change-Id: Ia50ec73d33caa548227dfcbd52119117720787dc --- M pywikibot/site.py 1 file changed, 9 insertions(+), 12 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index d83a098..bca8612 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1831,22 +1831,19 @@ amlang=self.lang, )
+ for msg in msg_query: + if 'missing' not in msg: + self._msgcache[msg['name']] = msg['*'] + # Return all messages if keys == u'*' or keys == [u'*']: - for msg in msg_query: - if 'missing' not in msg: - self._msgcache[msg['name']] = msg['*'] return self._msgcache - # Return only given keys else: - for _key in keys: - for msg in msg_query: - if msg['name'] == _key and 'missing' not in msg: - self._msgcache[_key] = msg['*'] - break - else: - raise KeyError("Site %(self)s has no message '%(_key)s'" - % locals()) + # Check requested keys + for key in keys: + if key not in self._msgcache: + raise KeyError("Site %s has no message '%s'" + % (self, key))
return dict((_key, self._msgcache[_key]) for _key in keys)