Page MenuHomePhabricator

Use ipaddress module
Closed, ResolvedPublic

Description

We should replace our ipaddress detection library with the python ipaddress library, however it has some minor problems which we may want to have fixed first.

http://bugs.python.org/issue22282

Event Timeline

jayvdb claimed this task.
jayvdb raised the priority of this task from to Medium.
jayvdb updated the task description. (Show Details)
jayvdb added a project: Pywikibot.
jayvdb changed Security from none to None.
jayvdb moved this task from Backlog to Upstream issues on the Pywikibot board.
jayvdb added a subscriber: XZise.

For more information see @jayvdb's upload: https://gerrit.wikimedia.org/r/#/c/155698/

As discussed in the comments, we still need to fix the remaining issues for ourselves even if it's get backported to Python 3.3 as others might use Python versions prior to that.

On the other hand the invalid but accepted IPv6 addresses are really corner cases so I don't think we require the fix for productive purposes but the test suite only. If someone has a problem in the future that module they should update their Python version as it's broken (similar to the Unicode normalization bug).

gerritbot subscribed.

Change 155698 had a related patch set uploaded (by John Vandenberg):
Use ipaddress module if installed

https://gerrit.wikimedia.org/r/155698

Patch-For-Review

Our primary python version is still 2.x. This patch shouldn't throw (tons of) warnings when running on Python 2.x without the (buggy) python ipaddress library installed.

Our primary python version is still 2.x. This patch shouldn't throw (tons of) warnings when running on Python 2.x ...

The current patch is ready for review; it uses DeprecationWarning which are not shown by default.

Python 2.x without the (buggy) python ipaddress library installed.

The bugs in the Python 2 library are the same that exist in the Python 3 library, which have been reported upstream and received no response from python devs so far. Note that the bug does not reject valid IP addresses - i.e. any IP address which is an IP address will be detected as an IP address.

The only known potential for a regression is that a user called "1111:2222:3333:4444:5555:6666:00.00.00.00" could be considered an IP address instead of a user, and AFAIK the MW title algorithm doesnt allow colon (:) in usernames so that isnt a problem.

If you can see any potential for actual regressions, please raise them.

It is also using the regex if no module is installed so for Python 2 users there will be no difference.

And what John said: The module works almost exactly like the regex. The only difference is that it allows leading zeros in the IPv4 part of an IPv6 address. Those could be interpreted as octal numbers so it is disallowed to avoid ambiguity. And after that is fixed, the chance that Python 2 users will have it sooner is higher as they are using the backport (so all versions are fixed and it's not like 3.4.2 which will still have that problem).

Change 155698 merged by jenkins-bot:
Use ipaddress module if installed

https://gerrit.wikimedia.org/r/155698