jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/580067 )
Change subject: [cleanup] remove deprecated tools.ip.ip_regex ......................................................................
[cleanup] remove deprecated tools.ip.ip_regex
- ipaddress is mandatory for Python 2 and part of Python 3. This dependency is checked by pwb.py and the script fails if the package is missing. Therefore the regex is no longer needed will not be used anymore. - tools.ip.ip_regex was announced to be removed. Remove it from tools.ip and also remove page.ip_regex - Remove ip_address/ip_addr backport test. This should be part of the library itself. - ip_addr is deprecated already in favour of ip_address. Its version can be checked with a patch given here: https://gerrit.wikimedia.org/r/#/c/pywikibot/core/+/577966/
Bug: T174482 Change-Id: Ib7a39cb98a38a552b96679d3a01550e90fc85d7a --- M pywikibot/page/__init__.py M pywikibot/tools/__init__.py M pywikibot/tools/ip.py 3 files changed, 8 insertions(+), 63 deletions(-)
Approvals: Huji: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index 5cdb83c..00b72f9 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -54,7 +54,6 @@ first_upper, redirect_func, remove_last_args, UnicodeType, StringTypes ) -from pywikibot.tools.ip import ip_regexp # deprecated from pywikibot.tools import is_IP
if not PY2: @@ -93,7 +92,6 @@ 'UnicodeToAsciiHtml', 'unicode2html', 'url2unicode', - 'ip_regexp', # unused & deprecated )
logger = logging.getLogger('pywiki.wiki.page') diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index f1987be..a6e7c88 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -390,7 +390,7 @@ method = ip_address if not ip_address: # Python 2 needs ipaddress to be installed issue_deprecation_warning( - 'ipaddr module or tools.ip.ip_regexp', 'ipaddress module', + 'ipaddr module', 'ipaddress module', warning_class=FutureWarning, since='20200120') from pywikibot.tools import ip with suppress_warnings('pywikibot.tools.ip.is_IP is deprecated'): diff --git a/pywikibot/tools/ip.py b/pywikibot/tools/ip.py index b98289d..e935796 100644 --- a/pywikibot/tools/ip.py +++ b/pywikibot/tools/ip.py @@ -7,13 +7,9 @@ # from __future__ import absolute_import, division, unicode_literals
-import re - from distutils.version import StrictVersion -from warnings import warn
-from pywikibot.tools import (DeprecatedRegex, PY2, UnicodeType, - ModuleDeprecationWrapper) +from pywikibot.tools import ModuleDeprecationWrapper
_ipaddress_e = _ipaddr_e = _ipaddr_version = None
@@ -23,7 +19,7 @@ _ipaddress_e = e ip_address = None
-if not ip_address or PY2: +if not ip_address: try: from ipaddr import __version__ as _ipaddr_version except ImportError as e: @@ -35,60 +31,11 @@ else: _ipaddr_e = ImportError('ipaddr %s is broken.' % _ipaddr_version)
-if ip_address and ip_address.__module__ == 'ipaddress': - if PY2: - # This backport fails many tests - # https://pypi.org/project/py2-ipaddress - # It accepts '1111' as a valid IP address. - try: - ip_address('1111') - ip_address = None - raise ImportError('ipaddress backport is broken; install ipaddr') - except ValueError: - pass - - # This backport only fails a few tests if given a unicode object - # https://pypi.org/project/ipaddress - # However while it rejects '1111', it will consider b'1111' valid - try: - ip_address(b'1111') - warn('ipaddress backport is defective; patching; install ipaddr', - ImportWarning) - orig_ip_address = ip_address - # force all input to be a unicode object so it validates correctly - - def ip_address_patched(IP): - """Safe ip_address.""" - return orig_ip_address(UnicodeType(IP)) - - ip_address = ip_address_patched - except ValueError: - # This means ipaddress has correctly determined b'1111' is invalid - pass -elif not ip_address: - warn('Importing ipaddr.IPAddress failed: %s\n' - 'Importing ipaddress.ip_address failed: %s\n' - 'Please install ipaddr 2.1.10+ or ipaddress.' - % (_ipaddr_e, _ipaddress_e), ImportWarning) - - def ip_address_fake(IP): - """Fake ip_address method.""" - warn('ipaddress backport not available.', DeprecationWarning) - if ip_regexp.match(IP) is None: - raise ValueError('Invalid IP address') - - ip_address = ip_address_fake - -# deprecated IP detector -ip_regexp = DeprecatedRegex( - r'^(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}' - r'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|' - r'(((?=(?=(.*?(::)))\3(?!.+\4)))\4?|[\dA-F]{1,4}:)' - r'([\dA-F]{1,4}(\4|:\b)|\2){5}' - 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.is_IP', since='20150212') +if not ip_address: + raise ImportError('Importing ipaddr.IPAddress failed: {}\n' + 'Importing ipaddress.ip_address failed: {}\n' + 'Please install ipaddress.' + .format(_ipaddr_e, _ipaddress_e))
def is_IP(IP):
pywikibot-commits@lists.wikimedia.org