jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Yield interwiki URLs separately ......................................................................
[IMPROV] Yield interwiki URLs separately
Instead of returning one list with all URLs it can yield one URL at a time. This way it's possible to only query the article path if nothing else matched first.
This also adds a parameter to avoid manually skipping the first entry which isn't actually a suffix for an article URL.
Change-Id: Idd20f0757856299d2ae21608bb29d12c3e4cae11 --- M pywikibot/cosmetic_changes.py M pywikibot/site.py 2 files changed, 9 insertions(+), 8 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py index 3010ef3..c27f9bc 100755 --- a/pywikibot/cosmetic_changes.py +++ b/pywikibot/cosmetic_changes.py @@ -703,8 +703,8 @@ exceptions = ['nowiki', 'comment', 'math', 'pre', 'source', 'startspace'] # link to the wiki working on - # Do not use the first entry as it is not actually a prefix - for suffix in self.site._interwiki_urls()[1:]: + # Only use suffixes for article paths + for suffix in self.site._interwiki_urls(True): http_url = self.site.base_url(suffix, 'http') if self.site.protocol() == 'http': https_url = None diff --git a/pywikibot/site.py b/pywikibot/site.py index 16d3e99..c6381b5 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -917,12 +917,13 @@ return [lang for lang in self.languages() if self.namespaces.lookup_normalized_name(lang) is None]
- def _interwiki_urls(self): - site_paths = [self.path()] * 3 - site_paths[1] += '/' - site_paths[2] += '?title=' - site_paths += [self.article_path] - return site_paths + def _interwiki_urls(self, only_article_suffixes=False): + base_path = self.path() + if not only_article_suffixes: + yield base_path + yield base_path + '/' + yield base_path + '?title=' + yield self.article_path
def interwiki(self, prefix): """
pywikibot-commits@lists.wikimedia.org