XZise has uploaded a new change for review. https://gerrit.wikimedia.org/r/208510
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/page.py 1 file changed, 15 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/10/208510/1 diff --git a/pywikibot/page.py b/pywikibot/page.py index bd98c0c..16f9162 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 @@ -4450,19 +4453,15 @@ if ns: # The prefix is a namespace in the source wiki return (fam.name, code) - 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): -- To view, visit https://gerrit.wikimedia.org/r/208510 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9a85925e26e1dadb1c60d00d45e7ad0cfad3272f Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XZise <commodorefabia...@gmx.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits