jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
pywikibot.tools.DeprecatedRegex: Make `since` a param of __init__

It does not make sense to hardcode `since` in DeprecatedRegex, different
regexes may get deprecated at different times.
Add `since` as a parameter for __init__ and fix the only two usages of this
class.

Change-Id: I52843e5e4b27cb3ea5993a9c22e915cf1f2dfd80
---
M pywikibot/textlib.py
M pywikibot/tools/__init__.py
M pywikibot/tools/ip.py
3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index e6ee2c1..b9cc974 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -63,15 +63,17 @@
# that allows system variables, but does not match nested templates.
# It exists for backwards compatibility to the old 'TEMP_REGEX'
# which was the _ETP_REGEX.
-TEMP_REGEX = DeprecatedRegex(r"""
-{{\s*(?:msg:\s*)?
- (?P<name>[^{\|]+?)\s*
- (?:\|(?P<params>[^{]*
- (?:(?:{}|{{[A-Z]+(?:\:[^}])?}}|{{{[^}]+}}}) [^{]*)*
- )?
- )?
-}}
-""", re.VERBOSE, 'textlib.TEMP_REGEX', 'textlib.NESTED_TEMPLATE_REGEX')
+TEMP_REGEX = DeprecatedRegex(
+ r"""
+ {{\s*(?:msg:\s*)?
+ (?P<name>[^{\|]+?)\s*
+ (?:\|(?P<params>[^{]*
+ (?:(?:{}|{{[A-Z]+(?:\:[^}])?}}|{{{[^}]+}}}) [^{]*)*
+ )?
+ )?
+ }}
+ """, re.VERBOSE, 'textlib.TEMP_REGEX', 'textlib.NESTED_TEMPLATE_REGEX',
+ since='20150212')

# The regex below collects nested templates, providing simpler
# identification of templates used at the top-level of wikitext.
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index d3b0b94..e35b2cb 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -410,7 +410,7 @@

"""Regex object that issues a deprecation notice."""

- def __init__(self, pattern, flags=0, name=None, instead=None):
+ def __init__(self, pattern, flags=0, name=None, instead=None, since=None):
"""
Initializer.

@@ -426,11 +426,12 @@
super(DeprecatedRegex, self).__init__(pattern, flags)
self._name = name or self.raw
self._instead = instead
+ self._since = since

def __getattr__(self, attr):
"""Issue deprecation warning."""
issue_deprecation_warning(
- self._name, self._instead, 2, since='20150212')
+ self._name, self._instead, 2, since=self._since)
return super(DeprecatedRegex, self).__getattr__(attr)


diff --git a/pywikibot/tools/ip.py b/pywikibot/tools/ip.py
index a4d131d..3fba28c 100644
--- a/pywikibot/tools/ip.py
+++ b/pywikibot/tools/ip.py
@@ -88,7 +88,7 @@
r'(([\dA-F]{1,4}(\4|:\b|$)|\2){2}|'
r'(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\Z',
re.IGNORECASE,
- 'page.ip_regexp', 'tools.ip.is_IP')
+ 'page.ip_regexp', 'tools.ip.is_IP', since='20150212')


def is_IP(IP):

To view, visit change 453088. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I52843e5e4b27cb3ea5993a9c22e915cf1f2dfd80
Gerrit-Change-Number: 453088
Gerrit-PatchSet: 2
Gerrit-Owner: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)