jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/658559 )
Change subject: [bugfix] BaseSite does not have an _interwikimap attribute ......................................................................
[bugfix] BaseSite does not have an _interwikimap attribute
Therefore move interwiki() interwiki_prefix() and local_interwiki() methods from BaseSite to APISite
Change-Id: If7b9450c287ae7b108dd9b9d18fce1546c0c0afd --- M pywikibot/site/__init__.py M pywikibot/site/_basesite.py 2 files changed, 47 insertions(+), 47 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py index 941fbd5..98b12a7 100644 --- a/pywikibot/site/__init__.py +++ b/pywikibot/site/__init__.py @@ -128,6 +128,53 @@ self._interwikimap = _InterwikiMap(self) self.tokens = TokenWallet(self)
+ def interwiki(self, prefix): + """ + Return the site for a corresponding interwiki prefix. + + @raises pywikibot.exceptions.SiteDefinitionError: if the url given in + the interwiki table doesn't match any of the existing families. + @raises KeyError: if the prefix is not an interwiki prefix. + """ + return self._interwikimap[prefix].site + + def interwiki_prefix(self, site): + """ + Return the interwiki prefixes going to that site. + + The interwiki prefixes are ordered first by length (shortest first) + and then alphabetically. L{interwiki(prefix)} is not guaranteed to + equal C{site} (i.e. the parameter passed to this function). + + @param site: The targeted site, which might be it's own. + @type site: L{BaseSite} + @return: The interwiki prefixes + @rtype: list (guaranteed to be not empty) + @raises KeyError: if there is no interwiki prefix for that site. + """ + assert site is not None, 'Site must not be None' + prefixes = set() + for url in site._interwiki_urls(): + prefixes.update(self._interwikimap.get_by_url(url)) + if not prefixes: + raise KeyError( + "There is no interwiki prefix to '{0}'".format(site)) + return sorted(prefixes, key=lambda p: (len(p), p)) + + def local_interwiki(self, prefix): + """ + Return whether the interwiki prefix is local. + + A local interwiki prefix is handled by the target site like a normal + link. So if that link also contains an interwiki link it does follow + it as long as it's a local link. + + @raises pywikibot.exceptions.SiteDefinitionError: if the url given in + the interwiki table doesn't match any of the existing families. + @raises KeyError: if the prefix is not an interwiki prefix. + """ + return self._interwikimap[prefix].local + @classmethod def fromDBName(cls, dbname, site=None): """ diff --git a/pywikibot/site/_basesite.py b/pywikibot/site/_basesite.py index 4cf3f43..7e88701 100644 --- a/pywikibot/site/_basesite.py +++ b/pywikibot/site/_basesite.py @@ -243,53 +243,6 @@ yield base_path + '?title=' yield self.article_path
- def interwiki(self, prefix): - """ - Return the site for a corresponding interwiki prefix. - - @raises pywikibot.exceptions.SiteDefinitionError: if the url given in - the interwiki table doesn't match any of the existing families. - @raises KeyError: if the prefix is not an interwiki prefix. - """ - return self._interwikimap[prefix].site - - def interwiki_prefix(self, site): - """ - Return the interwiki prefixes going to that site. - - The interwiki prefixes are ordered first by length (shortest first) - and then alphabetically. L{interwiki(prefix)} is not guaranteed to - equal C{site} (i.e. the parameter passed to this function). - - @param site: The targeted site, which might be it's own. - @type site: L{BaseSite} - @return: The interwiki prefixes - @rtype: list (guaranteed to be not empty) - @raises KeyError: if there is no interwiki prefix for that site. - """ - assert site is not None, 'Site must not be None' - prefixes = set() - for url in site._interwiki_urls(): - prefixes.update(self._interwikimap.get_by_url(url)) - if not prefixes: - raise KeyError( - "There is no interwiki prefix to '{0}'".format(site)) - return sorted(prefixes, key=lambda p: (len(p), p)) - - def local_interwiki(self, prefix): - """ - Return whether the interwiki prefix is local. - - A local interwiki prefix is handled by the target site like a normal - link. So if that link also contains an interwiki link it does follow - it as long as it's a local link. - - @raises pywikibot.exceptions.SiteDefinitionError: if the url given in - the interwiki table doesn't match any of the existing families. - @raises KeyError: if the prefix is not an interwiki prefix. - """ - return self._interwikimap[prefix].local - @deprecated('APISite.namespaces.lookup_name', since='20150703', future_warning=True) def ns_index(self, namespace): # pragma: no cover
pywikibot-commits@lists.wikimedia.org