jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Link: Use iwmap for parse_site ......................................................................
[IMPROV] Link: Use iwmap for parse_site
Instead of a statically configured dict Link.parse_site is using the interwikimap reported by the API. This changes the output marginally as the tuple now can contain None (when there is such configured site).
Bug: T97932 Change-Id: I9a85925e26e1dadb1c60d00d45e7ad0cfad3272f --- M pywikibot/family.py M pywikibot/page.py 2 files changed, 17 insertions(+), 13 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py index 5f5d1b2..e7f97e4 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -871,6 +871,9 @@ issue_deprecation_warning('nocapitalize', "APISite.siteinfo['case'] or " "Namespace.case == 'case-sensitive'", 2) + elif name == 'known_families': + issue_deprecation_warning('known_families', + 'APISite.interwiki(prefix)', 2) return super(Family, self).__getattribute__(name)
@staticmethod diff --git a/pywikibot/page.py b/pywikibot/page.py index bd98c0c..5195f59 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -4426,14 +4426,17 @@ return "pywikibot.page.Link(%r, %r)" % (self.title, self.site)
def parse_site(self): - """Parse only enough text to determine which site the link points to. + """ + Parse only enough text to determine which site the link points to.
This method does not parse anything after the first ":"; links with multiple interwiki prefixes (such as "wikt:fr:Parlais") need to be re-parsed on the first linked wiki to get the actual site.
- @return: tuple of (family-name, language-code) for the linked site. - + @return: The family name and site code for the linked site. If the site + is not supported by the configured families it returns None instead + of a str. + @rtype: str or None, str or None """ t = self._text fam = self._source.family @@ -4453,16 +4456,14 @@ if prefix in fam.langs: # prefix is a language code within the source wiki family return (fam.name, prefix) - known = fam.get_known_families(site=self._source) - if prefix in known: - if known[prefix] == fam.name: - # interwiki prefix links back to source family - t = t[t.index(u":") + 1:].lstrip(u" ") - # strip off the prefix and retry - continue - # prefix is a different wiki family - return (known[prefix], code) - break + try: + newsite = self._source.interwiki(prefix) + except KeyError: + break # text before : doesn't match any known prefix + except SiteDefinitionError: + return (None, None) + else: + return (newsite.family.name, newsite.code) return (fam.name, code) # text before : doesn't match any known prefix
def parse(self):
pywikibot-commits@lists.wikimedia.org