jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/639088 )
Change subject: [bugfix] Fix get_known_families() for wikipedia_family
......................................................................
[bugfix] Fix get_known_families() for wikipedia_family
get_known_families() never worked for wikipedia_family because
a site delegates that call to family with site.code as parameter
and not by the site itself.
The get_known_families function is already desupported and should be
removed but for full functionality of site.interwiki() method it
should support AutoFamily first which is proposed with
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/584919
Bug: T267196
Change-Id: If3fd4fcbf092ebcf6bf808449d14b8a0d7c22704
---
M pywikibot/families/wikipedia_family.py
M pywikibot/family.py
2 files changed, 5 insertions(+), 5 deletions(-)
Approvals:
Hazard-SJ: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/families/wikipedia_family.py b/pywikibot/families/wikipedia_family.py
index 2f67c08..3cc3f05 100644
--- a/pywikibot/families/wikipedia_family.py
+++ b/pywikibot/families/wikipedia_family.py
@@ -217,17 +217,17 @@
'de': ('Archiv',),
}
- def get_known_families(self, site):
+ def get_known_families(self, code):
"""Override the family interwiki prefixes for each site."""
# In Swedish Wikipedia 's:' is part of page title not a family
# prefix for 'wikisource'.
- if site.code == 'sv':
+ if code == 'sv':
d = self.known_families.copy()
d.pop('s')
d['src'] = 'wikisource'
return d
- else:
- return self.known_families
+
+ return self.known_families
def encodings(self, code):
"""Return a list of historical encodings for a specific site."""
diff --git a/pywikibot/family.py b/pywikibot/family.py
index b4d5ad9..d509e77 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -748,7 +748,7 @@
return list(cls.langs.keys())
@deprecated('APISite.interwiki', since='20151014', future_warning=True)
- def get_known_families(self, site):
+ def get_known_families(self, code):
"""DEPRECATED: Return dict of inter-family interwiki links."""
return self.known_families
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/639088
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If3fd4fcbf092ebcf6bf808449d14b8a0d7c22704
Gerrit-Change-Number: 639088
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Hazard-SJ <hazardsjwiki(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/579737 )
Change subject: [IMPR] Move _InterwikiMap class to site/_interwikimap.py
......................................................................
[IMPR] Move _InterwikiMap class to site/_interwikimap.py
Change-Id: Ib85f22bb704b5421dfd89e7e1fac36bf731ce9f6
---
M docs/api_ref/pywikibot.site.rst
M pywikibot/CONTENT.rst
M pywikibot/site/__init__.py
A pywikibot/site/_interwikimap.py
M tests/textlib_tests.py
5 files changed, 111 insertions(+), 82 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/api_ref/pywikibot.site.rst b/docs/api_ref/pywikibot.site.rst
index 04e0380..6e5796e 100644
--- a/docs/api_ref/pywikibot.site.rst
+++ b/docs/api_ref/pywikibot.site.rst
@@ -2,3 +2,21 @@
=======================
.. automodule:: pywikibot.site
+
+Submodules
+----------
+
+pywikibot.site.\_decorators module
+----------------------------------
+
+.. automodule:: pywikibot.site._decorators
+
+pywikibot.site.\_interwikimap module
+------------------------------------
+
+.. automodule:: pywikibot.site._interwikimap
+
+pywikibot.site.\_siteinfo module
+--------------------------------
+
+.. automodule:: pywikibot.site._siteinfo
diff --git a/pywikibot/CONTENT.rst b/pywikibot/CONTENT.rst
index 59c15a6..f34e7fe 100644
--- a/pywikibot/CONTENT.rst
+++ b/pywikibot/CONTENT.rst
@@ -43,7 +43,7 @@
| i18n.py | Helper functions for both the internal translation |
| | system and for TranslateWiki-based translations |
+----------------------------+------------------------------------------------------+
- | interwiki_graph.py | Possible create graph with interwiki.py. |
+ | interwiki_graph.py | Possible create graph with interwiki.py script |
+----------------------------+------------------------------------------------------+
| logentries.py | Objects representing Mediawiki log entries |
+----------------------------+------------------------------------------------------+
@@ -115,6 +115,8 @@
+----------------------------+------------------------------------------------------+
| _decorators.py | Decorators used by site models. |
+----------------------------+------------------------------------------------------+
+ | _interwikimap.py | Objects representing interwiki map of MediaWiki site |
+ +----------------------------+------------------------------------------------------+
| _siteinfo.py | Objects representing site info data contents. |
+----------------------------+------------------------------------------------------+
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index dbee6f6..16f58c7 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -67,6 +67,7 @@
UnknownSite,
)
from pywikibot.site._decorators import need_extension, need_right, need_version
+from pywikibot.site._interwikimap import _InterwikiMap
from pywikibot.site._siteinfo import Siteinfo
from pywikibot.throttle import Throttle
from pywikibot.tools import (
@@ -594,86 +595,6 @@
return result
-class _IWEntry:
-
- """An entry of the _InterwikiMap with a lazy loading site."""
-
- def __init__(self, local, url):
- self._site = None
- self.local = local
- self.url = url
-
- @property
- def site(self):
- if self._site is None:
- try:
- self._site = pywikibot.Site(url=self.url)
- except Exception as e:
- self._site = e
- return self._site
-
-
-class _InterwikiMap:
-
- """A representation of the interwiki map of a site."""
-
- def __init__(self, site):
- """
- Create an empty uninitialized interwiki map for the given site.
-
- @param site: Given site for which interwiki map is to be created
- @type site: pywikibot.site.APISite
- """
- super().__init__()
- self._site = site
- self._map = None
-
- def reset(self):
- """Remove all mappings to force building a new mapping."""
- self._map = None
-
- @property
- def _iw_sites(self):
- """Fill the interwikimap cache with the basic entries."""
- # _iw_sites is a local cache to return a APISite instance depending
- # on the interwiki prefix of that site
- if self._map is None:
- self._map = {iw['prefix']: _IWEntry('local' in iw, iw['url'])
- for iw in self._site.siteinfo['interwikimap']}
- return self._map
-
- def __getitem__(self, prefix):
- """
- Return the site, locality and url for the requested prefix.
-
- @param prefix: Interwiki prefix
- @type prefix: Dictionary key
- @rtype: _IWEntry
- @raises KeyError: Prefix is not a key
- @raises TypeError: Site for the prefix is of wrong type
- """
- if prefix not in self._iw_sites:
- raise KeyError("'{0}' is not an interwiki prefix.".format(prefix))
- if isinstance(self._iw_sites[prefix].site, BaseSite):
- return self._iw_sites[prefix]
- elif isinstance(self._iw_sites[prefix].site, Exception):
- raise self._iw_sites[prefix].site
- else:
- raise TypeError('_iw_sites[%s] is wrong type: %s'
- % (prefix, type(self._iw_sites[prefix].site)))
-
- def get_by_url(self, url):
- """
- Return a set of prefixes applying to the URL.
-
- @param url: URL for the interwiki
- @type url: str
- @rtype: set
- """
- return {prefix for prefix, iw_entry in self._iw_sites
- if iw_entry.url == url}
-
-
class BaseSite(ComparableMixin):
"""Site methods that are independent of the communication interface."""
diff --git a/pywikibot/site/_interwikimap.py b/pywikibot/site/_interwikimap.py
new file mode 100644
index 0000000..6352d26
--- /dev/null
+++ b/pywikibot/site/_interwikimap.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+"""Objects representing interwiki map of MediaWiki site."""
+#
+# (C) Pywikibot team, 2015-2020
+#
+# Distributed under the terms of the MIT license.
+#
+import pywikibot
+
+
+class _IWEntry:
+
+ """An entry of the _InterwikiMap with a lazy loading site."""
+
+ def __init__(self, local, url):
+ self._site = None
+ self.local = local
+ self.url = url
+
+ @property
+ def site(self):
+ if self._site is None:
+ try:
+ self._site = pywikibot.Site(url=self.url)
+ except Exception as e:
+ self._site = e
+ return self._site
+
+
+class _InterwikiMap:
+
+ """A representation of the interwiki map of a site."""
+
+ def __init__(self, site):
+ """
+ Create an empty uninitialized interwiki map for the given site.
+
+ @param site: Given site for which interwiki map is to be created
+ @type site: pywikibot.site.APISite
+ """
+ super().__init__()
+ self._site = site
+ self._map = None
+
+ def reset(self):
+ """Remove all mappings to force building a new mapping."""
+ self._map = None
+
+ @property
+ def _iw_sites(self):
+ """Fill the interwikimap cache with the basic entries."""
+ # _iw_sites is a local cache to return a APISite instance depending
+ # on the interwiki prefix of that site
+ if self._map is None:
+ self._map = {iw['prefix']: _IWEntry('local' in iw, iw['url'])
+ for iw in self._site.siteinfo['interwikimap']}
+ return self._map
+
+ def __getitem__(self, prefix):
+ """
+ Return the site, locality and url for the requested prefix.
+
+ @param prefix: Interwiki prefix
+ @type prefix: Dictionary key
+ @rtype: _IWEntry
+ @raises KeyError: Prefix is not a key
+ @raises TypeError: Site for the prefix is of wrong type
+ """
+ if prefix not in self._iw_sites:
+ raise KeyError("'{0}' is not an interwiki prefix.".format(prefix))
+ if isinstance(self._iw_sites[prefix].site, pywikibot.site.BaseSite):
+ return self._iw_sites[prefix]
+ elif isinstance(self._iw_sites[prefix].site, Exception):
+ raise self._iw_sites[prefix].site
+ else:
+ raise TypeError('_iw_sites[%s] is wrong type: %s'
+ % (prefix, type(self._iw_sites[prefix].site)))
+
+ def get_by_url(self, url):
+ """
+ Return a set of prefixes applying to the URL.
+
+ @param url: URL for the interwiki
+ @type url: str
+ @rtype: set
+ """
+ return {prefix for prefix, iw_entry in self._iw_sites
+ if iw_entry.url == url}
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 474ae16..3e2ae0a 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -16,7 +16,7 @@
import pywikibot
import pywikibot.textlib as textlib
-from pywikibot.site import _IWEntry
+from pywikibot.site._interwikimap import _IWEntry
from pywikibot.textlib import _MultiTemplateMatchBuilder, extract_sections
from pywikibot import UnknownSite
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/579737
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib85f22bb704b5421dfd89e7e1fac36bf731ce9f6
Gerrit-Change-Number: 579737
Gerrit-PatchSet: 9
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged