jenkins-bot has submitted this change and it was merged.
Change subject: Only allow ipaddr 2.1.10+
......................................................................
Only allow ipaddr 2.1.10+
Enable use-system-packages for Python 2.7 to test ipaddr
Bug: T105443
Change-Id: Ia58d2c6715acc0d9207846e9f6da9005843a6869
---
M .travis.yml
M pywikibot/tools/ip.py
M requirements.txt
M setup.py
M tests/tools_ip_tests.py
5 files changed, 37 insertions(+), 13 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.travis.yml b/.travis.yml
index c8fb5c7..203d846 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,6 +20,7 @@
- djvulibre-bin
- graphviz
- liblua5.1-0-dev
+ - python-ipaddr
before_install:
# When PYSETUP_TEST_EXTRAS is not enabled, do not allow the
@@ -92,7 +93,7 @@
matrix:
include:
- - python: '2.7'
+ - python: '2.7_with_system_site_packages' # equivalent to virtualenv:
system_site_packages: true
env: LANGUAGE=he FAMILY=wikivoyage SITE_ONLY=1
- python: '2.7'
env: LANGUAGE=wikia FAMILY=wikia PYWIKIBOT2_TEST_NO_RC=1
diff --git a/pywikibot/tools/ip.py b/pywikibot/tools/ip.py
index 41a5f41..b50f8d5 100644
--- a/pywikibot/tools/ip.py
+++ b/pywikibot/tools/ip.py
@@ -14,24 +14,30 @@
import re
import sys
+from distutils.version import StrictVersion
from warnings import warn
from pywikibot.tools import DeprecatedRegex
-ipaddress_e = ipaddr_e = None
+_ipaddress_e = _ipaddr_e = _ipaddr_version = None
try:
from ipaddress import ip_address
-except ImportError as ipaddress_e:
+except ImportError as e:
+ _ipaddress_e = e
ip_address = None
- pass
if not ip_address or sys.version_info[0] < 3:
try:
- from ipaddr import IPAddress as ip_address
- ip_address.__T76286__ = False
- except ImportError as ipaddr_e:
- pass
+ from ipaddr import __version__ as _ipaddr_version
+ except ImportError as e:
+ _ipaddr_e = e
+ else:
+ _ipaddr_version = StrictVersion(_ipaddr_version)
+ if _ipaddr_version >= StrictVersion('2.1.10'):
+ from ipaddr import IPAddress as ip_address
+ else:
+ _ipaddr_e = ImportError('ipaddr %s is broken.' % _ipaddr_version)
if ip_address and ip_address.__module__ == 'ipaddress':
if sys.version_info[0] < 3:
@@ -66,8 +72,8 @@
elif not ip_address:
warn('Importing ipaddr.IPAddress failed: %s\n'
'Importing ipaddress.ip_address failed: %s\n'
- 'Please install ipaddr.'
- % (ipaddr_e, ipaddress_e), ImportWarning)
+ 'Please install ipaddr 2.1.10+ or ipaddress.'
+ % (_ipaddr_e, _ipaddress_e), ImportWarning)
def ip_address_fake(IP):
"""Fake ip_address method."""
diff --git a/requirements.txt b/requirements.txt
index e0f5a1f..7febc63 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -31,6 +31,9 @@
pyasn1 ; python_full_version < '2.7.9'
future ; python_version < '2.7'
+
+ipaddr>=2.1.10 ; python_version < '3'
+
# core interwiki_graph.py:
git+https://github.com/nlhepler/pydot#egg=pydot-1.0.29
diff --git a/setup.py b/setup.py
index c07fdbe..0e9dab9 100644
--- a/setup.py
+++ b/setup.py
@@ -92,7 +92,8 @@
# However the Debian package python-ipaddr is also supported:
#
https://pypi.python.org/pypi/ipaddr
# Other backports are likely broken.
- dependencies.append('ipaddr')
+ # ipaddr 2.1.10+ is distributed with Debian and Fedora. See T105443.
+ dependencies.append('ipaddr>=2.1.10')
if sys.version_info < (2, 7, 9):
# Python versions before 2.7.9 will cause urllib3 to trigger
diff --git a/tests/tools_ip_tests.py b/tests/tools_ip_tests.py
index 659b756..80cd776 100644
--- a/tests/tools_ip_tests.py
+++ b/tests/tools_ip_tests.py
@@ -9,6 +9,8 @@
__version__ = '$Id$'
+from distutils.version import StrictVersion
+
from pywikibot.tools import ip
from tests.aspects import unittest, TestCase, DeprecationTestCase
@@ -69,8 +71,6 @@
self.ipv6test(True, "FF02:0000:0000:0000:0000:0000:0000:0001")
self.ipv6test(True, "0000:0000:0000:0000:0000:0000:0000:0001")
self.ipv6test(True, "0000:0000:0000:0000:0000:0000:0000:0000")
- self.ipv6test(False, "02001:0000:1234:0000:0000:C1C0:ABCD:0876") #
extra 0 not allowed!
- self.ipv6test(False, "2001:0000:1234:0000:00001:C1C0:ABCD:0876") #
extra 0 not allowed!
self.ipv6test(False, " 2001:0000:1234:0000:0000:C1C0:ABCD:0876") #
leading space
self.ipv6test(False, "2001:0000:1234:0000:0000:C1C0:ABCD:0876 ") #
trailing space
# leading and trailing space
@@ -631,6 +631,11 @@
self.ipv6test(False, "1111:2222:3333:4444:5555:6666:00.00.00.00")
self.ipv6test(False, "1111:2222:3333:4444:5555:6666:000.000.000.000")
+ def _test_T105443_failures(self):
+ """Test known bugs with ipaddr v2.1.10."""
+ self.ipv6test(False, "02001:0000:1234:0000:0000:C1C0:ABCD:0876") #
extra 0 not allowed!
+ self.ipv6test(False, "2001:0000:1234:0000:00001:C1C0:ABCD:0876") #
extra 0 not allowed!
+
class IPRegexTestCase(TestIPBase, DeprecationTestCase):
@@ -643,6 +648,7 @@
"""Test IP regex."""
self._run_tests()
self._test_T76286_failures()
+ self._test_T105443_failures()
self.assertEqual(self.fail, 0)
self.assertDeprecation(
'page.ip_regexp is deprecated, use tools.ip.is_IP instead.')
@@ -676,6 +682,13 @@
self._test_T76286_failures()
self.assertEqual(self.fail, 0)
+ @expected_failure_if(ip.ip_address.__module__ == 'ipaddr' and
+ ip._ipaddr_version == StrictVersion('2.1.10'))
+ def test_T105443_failures(self):
+ """Test known bugs in the ipaddr module."""
+ self._test_T105443_failures()
+ self.assertEqual(self.fail, 0)
+
if __name__ == "__main__":
try:
unittest.main()
--
To view, visit
https://gerrit.wikimedia.org/r/224020
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia58d2c6715acc0d9207846e9f6da9005843a6869
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>