jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/960172 )
Change subject: [cleanup] cleanup redirect methods
......................................................................
[cleanup] cleanup redirect methods
- add a new redirects method to BaseSite that returns the generic
redirect tag list (previously returned by BaseSite.redirect()
- add a new redirects method to APISite that returns the
redirect tag list extracted from getmagicwords('redirect')
- return the default redirect tag with BaseSite.redirect() instead of
a list. This enables to get the default tag also from APISite if
APISite.redirects is defined
- move redirect_regex method from APISite to BaseSite but simplify
the implementation. It is not necessary to assume that
getmagicwords('redirect') does not exists; it was a guess of of the
very first 2.0 implemetation and was implemented as the redirect tags
were part of the family files sometime in 2008.
- remove deprecated redirectRegex
Bug: T347226
Change-Id: I3647cf8cb154686f075bc53a054b937675d74765
---
M ROADMAP.rst
M pywikibot/site/_apisite.py
M pywikibot/site/_basesite.py
3 files changed, 65 insertions(+), 46 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index 9814645..d91c5b4 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -76,4 +76,3 @@
* 6.2.0: Throttle.multiplydelay attribute is deprecated
* 6.2.0: SequenceOutputter.format_list() is deprecated in favour of 'out' property
* 6.0.0: config.register_family_file() is deprecated
-* 5.5.0: APISite.redirectRegex() will be removed in favour of APISite.redirect_regex()
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 33d1752..ba3e8ca 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -17,7 +17,7 @@
from pywikibot import login
from pywikibot.backports import DefaultDict, Dict, List, Match
from pywikibot.backports import OrderedDict as OrderedDictType
-from pywikibot.backports import Iterable, Pattern, Set, Tuple, removesuffix
+from pywikibot.backports import Iterable, Set, Tuple, removesuffix
from pywikibot.comms import http
from pywikibot.data import api
from pywikibot.exceptions import (
@@ -1036,32 +1036,18 @@
return self._magicwords[word]
return [word]
- def redirect(self) -> str:
- """Return the localized #REDIRECT keyword."""
- # return the magic word without the preceding '#' character
- return self.getmagicwords('redirect')[0].lstrip('#')
+ def redirects(self) -> List[str]:
+ """Return a list of localized tags for the site without preceding '#'.
- @deprecated('redirect_regex', since='5.5.0')
- def redirectRegex(self) -> Pattern[str]: # noqa: N802
- """Return a compiled regular expression matching on redirect pages."""
- return self.redirect_regex
+ .. seealso::
+ :meth:`BaseSite.redirect()
+ <pywikibot.site._basesite.BaseSite.redirect>` and
+ :meth:`BaseSite.redirects()
+ <pywikibot.site._basesite.BaseSite.redirects>`
- @property
- def redirect_regex(self) -> Pattern[str]:
- """Return a compiled regular expression matching on redirect pages.
-
- Group 1 in the regex match object will be the target title.
-
+ .. versionadded:: 8.4
"""
- # NOTE: this is needed, since the API can give false positives!
- try:
- keywords = {s.lstrip('#') for s in self.getmagicwords('redirect')}
- keywords.add('REDIRECT') # just in case
- pattern = '(?:' + '|'.join(keywords) + ')'
- except KeyError:
- # no localized keyword for redirects
- pattern = None
- return super().redirectRegex(pattern)
+ return [s.lstrip('#') for s in self.getmagicwords('redirect')]
def pagenamecodes(self) -> List[str]:
"""Return list of localized PAGENAME tags for the site."""
diff --git a/pywikibot/site/_basesite.py b/pywikibot/site/_basesite.py
index 7292efc..ea47b94 100644
--- a/pywikibot/site/_basesite.py
+++ b/pywikibot/site/_basesite.py
@@ -11,7 +11,7 @@
from warnings import warn
import pywikibot
-from pywikibot.backports import Pattern
+from pywikibot.backports import List, Pattern
from pywikibot.exceptions import (
Error,
FamilyMaintenanceWarning,
@@ -242,26 +242,36 @@
"""Return dict of valid namespaces on this wiki."""
return NamespacesDict(self._build_namespaces())
- def ns_normalize(self, value):
- """
- Return canonical local form of namespace name.
+ def ns_normalize(self, value: str):
+ """Return canonical local form of namespace name.
:param value: A namespace name
- :type value: str
-
"""
index = self.namespaces.lookup_name(value)
return self.namespace(index)
- def redirect(self):
- """Return list of localized redirect tags for the site."""
+ def redirect(self) -> str:
+ """Return a default redirect tag for the site.
+
+ .. versionchanged:: 8.4
+ return a single generic redirect tag instead of a list of
+ tags. For the list use :meth:`redirects` instead.
+ """
+ return self.redirects()[0]
+
+ def redirects(self) -> List[str]:
+ """Return list of generic redirect tags for the site.
+
+ .. seealso:: :meth:`redirect` for the default redirect tag.
+ .. versionadded:: 8.4
+ """
return ['REDIRECT']
- def pagenamecodes(self):
+ def pagenamecodes(self) -> List[str]:
"""Return list of localized PAGENAME tags for the site."""
return ['PAGENAME']
- def pagename2codes(self):
+ def pagename2codes(self) -> List[str]:
"""Return list of localized PAGENAMEE tags for the site."""
return ['PAGENAMEE']
@@ -337,22 +347,22 @@
linkfam, linkcode = pywikibot.Link(text, self).parse_site()
return linkfam != self.family.name or linkcode != self.code
- def redirectRegex( # noqa: N802
- self,
- pattern: Optional[str] = None
- ) -> Pattern[str]:
+ @property
+ def redirect_regex(self) -> Pattern[str]:
"""Return a compiled regular expression matching on redirect pages.
Group 1 in the regex match object will be the target title.
+ A redirect starts with hash (#), followed by a keyword, then
+ arbitrary stuff, then a wikilink. The wikilink may contain a
+ label, although this is not useful.
+
+ .. versionadded:: 8.4
+ moved from class:`APISite<pywikibot.site._apisite.APISite>`
"""
- if pattern is None:
- pattern = 'REDIRECT'
- # A redirect starts with hash (#), followed by a keyword, then
- # arbitrary stuff, then a wikilink. The wikilink may contain
- # a label, although this is not useful.
- return re.compile(r'\s*#{pattern}\s*:?\s*\[\[(.+?)(?:\|.*?)?\]\]'
- .format(pattern=pattern), re.IGNORECASE | re.DOTALL)
+ tags = '|'.join(self.redirects())
+ return re.compile(fr'\s*#(?:{tags})\s*:?\s*\[\[(.+?)(?:\|.*?)?\]\]',
+ re.IGNORECASE | re.DOTALL)
def sametitle(self, title1: str, title2: str) -> bool:
"""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/960172
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: I3647cf8cb154686f075bc53a054b937675d74765
Gerrit-Change-Number: 960172
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/960007 )
Change subject: [IMPR] Show a warning if Pywikibot is running with Python 3.6
......................................................................
[IMPR] Show a warning if Pywikibot is running with Python 3.6
Also add an admonition item to documentation and a desupport warning
to ROADMAP.rst
Bug: T347139
Change-Id: Ifa78b3d632d27d39ffc9eeafb3ae5fec21fc6eec
---
M pywikibot/__init__.py
M ROADMAP.rst
M docs/index.rst
M tests/utils.py
4 files changed, 36 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index 9814645..b7b3650 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,6 +1,9 @@
Current release
---------------
+* Python 3.6 support will be discontinued and probably this is the last version supporting it
+* Upcast to :class:`pywikibot.FilePage` for a proper extension only (:phab:`T346889`)
+* Handle missing SDC mediainfo (:phab:`T345038`)
* *modules_only_mode* parameter of :class:`data.api.ParamInfo`, its *paraminfo_keys* class attribute
and its *preloaded_modules* property was deprecated, the :meth:`data.api.ParamInfo.normalize_paraminfo`
method became a staticmethod (:phab:`T306637`)
@@ -19,6 +22,7 @@
Deprecations
------------
+* 8.4.0: Python 3.6 support is deprecated and will be dropped with Pywikibot 9
* 8.4.0: *modules_only_mode* parameter of :class:`data.api.ParamInfo`, its *paraminfo_keys* class attribute
and its preloaded_modules property will be removed
* 8.4.0: *dropdelay* and *releasepid* attributes of :class:`throttle.Throttle` will be removed
diff --git a/docs/index.rst b/docs/index.rst
index 828c52a..f81d4a8 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -24,6 +24,9 @@
Python 3.6.1 or higher is currently required to run the bot, but Python 3.7
or higher is recommended. Python 3.6 support will be dropped with Pywikibot 9.
+.. attention:: Due to a security vulnerability it is strictly recommended to
+ use Python 3.7 or higher. Python 3.6 support will be dropped soon.
+
Pywikibot and this documentation are licensed under the
:ref:`MIT license`;
manual pages on mediawiki.org are licensed under the `CC-BY-SA 3.0`_ license.
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 3e14eb0..b2e7ad8 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -74,7 +74,7 @@
)
from pywikibot.site import APISite, BaseSite
from pywikibot.time import Timestamp
-from pywikibot.tools import normalize_username
+from pywikibot.tools import PYTHON_VERSION, normalize_username
__all__ = (
'__copyright__', '__description__', '__download_url__', '__license__',
@@ -99,6 +99,16 @@
_sites: Dict[str, APISite] = {}
+if PYTHON_VERSION < (3, 7):
+ warn("""
+
+ Python {version} will be dropped soon with Pywikibot 9.0
+ due to vulnerability security alerts.
+ It is recommended to use Python 3.7 or above.
+ See T347026 for further information.
+""".format(version=sys.version.split(maxsplit=1)[0]),
+ FutureWarning) # adjust this line no in utils.execute()
+
@cache
def _code_fam_from_url(url: str, name: Optional[str] = None
diff --git a/tests/utils.py b/tests/utils.py
index 5f93270..6d76c97 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -21,6 +21,8 @@
from pywikibot.exceptions import APIError
from pywikibot.login import LoginStatus
from pywikibot.site import Namespace
+from pywikibot.tools import PYTHON_VERSION
+
from tests import _pwb_py
@@ -470,6 +472,9 @@
:param command: executable to run and arguments to use
"""
+ if PYTHON_VERSION < (3, 7):
+ command.insert(1, '-W ignore::FutureWarning:pywikibot:110')
+
env = os.environ.copy()
# Prevent output by test package; e.g. 'max_retries reduced from x to y'
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/960007
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: Ifa78b3d632d27d39ffc9eeafb3ae5fec21fc6eec
Gerrit-Change-Number: 960007
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/961501 )
Change subject: [mypy] solve typing issue in date.py
......................................................................
[mypy] solve typing issue in date.py
Change-Id: I434e98efd9327c25f04f2428361fdda1c80a9146
---
M pywikibot/date.py
1 file changed, 22 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py
index c344cba..38d9565 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -69,17 +69,23 @@
@singledispatch
-def multi(value: int, tuplst: tuplst_type) -> Any:
- """
- Run multiple pattern checks for the same entry.
+def multi(value, tuplst: tuplst_type) -> Any:
+ """Run multiple pattern checks for the same entry.
For example: 1st century, 2nd century, etc.
- The tuplst is a list of tuples. Each tuple must contain two functions:
- first to encode/decode a single value (e.g. simpleInt), second is a
- predicate function with an integer parameter that returns true or false.
- When the 2nd function evaluates to true, the 1st function is used.
+ The tuplst is a list of tuples. Each tuple must contain two
+ functions: first to encode/decode a single value (e.g. simpleInt),
+ second is a predicate function with an integer parameter that
+ returns true or false. When the 2nd function evaluates to true, the
+ 1st function is used.
"""
+ raise NotImplementedError(
+ f'multi funtion is not implemented for type {type(value).__name__}')
+
+
+(a)multi.register(int)
+def _(value: int, tuplst: tuplst_type) -> Any:
# Find a predicate that gives true for this int value, and run a
# function
for func, pred in tuplst:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/961501
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: I434e98efd9327c25f04f2428361fdda1c80a9146
Gerrit-Change-Number: 961501
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/961416 )
Change subject: [mypy] Fix some typing issues in family.py
......................................................................
[mypy] Fix some typing issues in family.py
Change-Id: I3b7a32545a1dacc7ef999e014f590df00dbb20ab
---
M pywikibot/family.py
1 file changed, 14 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 198b649..52c6d3a 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -25,6 +25,7 @@
FrozenSet,
List,
Mapping,
+ Sequence,
Set,
Tuple,
removesuffix,
@@ -95,7 +96,7 @@
# Allocator will override this classproperty.
return cls()
- name = None
+ name: Optional[str] = None
#: Not open for edits; stewards can still edit.
closed_wikis: List[str] = []
@@ -113,7 +114,7 @@
langs: Dict[str, str] = {}
# A list of category redirect template names in different languages
- category_redirect_templates = {
+ category_redirect_templates: Dict[str, Sequence[str]] = {
'_default': []
}
@@ -121,7 +122,7 @@
use_hard_category_redirects = []
# A list of disambiguation template names in different languages
- disambiguationTemplates = {
+ disambiguationTemplates: Dict[str, Sequence[str]] = {
'_default': []
}
@@ -187,7 +188,7 @@
# forward interlanguage links to another family (wikipedia).
# These families can set this variable to the name of the target
# family.
- interwiki_forward = None
+ interwiki_forward: Optional[str] = None
# Language codes of the largest wikis. They should be roughly sorted
# by size.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/961416
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: I3b7a32545a1dacc7ef999e014f590df00dbb20ab
Gerrit-Change-Number: 961416
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged