Merge pull request #1540 from ilvalle/fix_ipaddress

Replaced ipaddr with ipaddress.py (backported from py3)
This commit is contained in:
mdipierro
2016-12-23 21:58:13 -06:00
committed by GitHub
5 changed files with 2434 additions and 1936 deletions
+2
View File
@@ -32,6 +32,7 @@ if PY2:
import cgi import cgi
import cookielib import cookielib
from xmlrpclib import ProtocolError from xmlrpclib import ProtocolError
from gluon.contrib import ipaddress
BytesIO = StringIO BytesIO = StringIO
reduce = reduce reduce = reduce
hashlib_md5 = hashlib.md5 hashlib_md5 = hashlib.md5
@@ -97,6 +98,7 @@ else:
from http import cookiejar as cookielib from http import cookiejar as cookielib
from xmlrpc.client import ProtocolError from xmlrpc.client import ProtocolError
import html # warning, this is the python3 module and not the web2py html module import html # warning, this is the python3 module and not the web2py html module
import ipaddress
hashlib_md5 = lambda s: hashlib.md5(bytes(s, 'utf8')) hashlib_md5 = lambda s: hashlib.md5(bytes(s, 'utf8'))
iterkeys = lambda d: iter(d.keys()) iterkeys = lambda d: iter(d.keys())
itervalues = lambda d: iter(d.values()) itervalues = lambda d: iter(d.values())
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2 -3
View File
@@ -1029,12 +1029,11 @@ this is the content of the fake file
self.assertEqual(rtn, ('2001::126c:8ffa:fe22:b3af', 'Enter valid IPv6 address')) self.assertEqual(rtn, ('2001::126c:8ffa:fe22:b3af', 'Enter valid IPv6 address'))
rtn = IS_IPV6(is_multicast=True)('ff00::126c:8ffa:fe22:b3af') rtn = IS_IPV6(is_multicast=True)('ff00::126c:8ffa:fe22:b3af')
self.assertEqual(rtn, ('ff00::126c:8ffa:fe22:b3af', None)) self.assertEqual(rtn, ('ff00::126c:8ffa:fe22:b3af', None))
# TODO:
# with py3.ipaddress '2001::126c:8ffa:fe22:b3af' is considered private # with py3.ipaddress '2001::126c:8ffa:fe22:b3af' is considered private
# with py2.ipaddress '2001::126c:8ffa:fe22:b3af' is considered private # with py2.ipaddress '2001::126c:8ffa:fe22:b3af' is considered private
# with gluon.contrib.ipaddr(both current and trunk) is not considered private # with gluon.contrib.ipaddr(both current and trunk) is not considered private
# rtn = IS_IPV6(is_routeable=True)('2001::126c:8ffa:fe22:b3af') rtn = IS_IPV6(is_routeable=False)('2001::126c:8ffa:fe22:b3af')
# self.assertEqual(rtn, ('2001::126c:8ffa:fe22:b3af', None)) self.assertEqual(rtn, ('2001::126c:8ffa:fe22:b3af', None))
rtn = IS_IPV6(is_routeable=True)('ff00::126c:8ffa:fe22:b3af') rtn = IS_IPV6(is_routeable=True)('ff00::126c:8ffa:fe22:b3af')
self.assertEqual(rtn, ('ff00::126c:8ffa:fe22:b3af', 'Enter valid IPv6 address')) self.assertEqual(rtn, ('ff00::126c:8ffa:fe22:b3af', 'Enter valid IPv6 address'))
rtn = IS_IPV6(subnets='2001::/32')('2001::8ffa:fe22:b3af') rtn = IS_IPV6(subnets='2001::/32')('2001::8ffa:fe22:b3af')
+5 -10
View File
@@ -3505,10 +3505,7 @@ class IS_IPV6(Validator):
self.error_message = error_message self.error_message = error_message
def __call__(self, value): def __call__(self, value):
try: from gluon._compat import ipaddress
import ipaddress
except ImportError:
from gluon.contrib import ipaddr as ipaddress
try: try:
ip = ipaddress.IPv6Address(to_unicode(value)) ip = ipaddress.IPv6Address(to_unicode(value))
@@ -3732,12 +3729,10 @@ class IS_IPADDRESS(Validator):
self.error_message = error_message self.error_message = error_message
def __call__(self, value): def __call__(self, value):
try: from gluon._compat import ipaddress
from ipaddress import ip_address as IPAddress IPAddress = ipaddress.ip_address
from ipaddress import IPv6Address, IPv4Address IPv6Address = ipaddress.IPv6Address
except ImportError: IPv4Address = ipaddress.IPv4Address
from gluon.contrib.ipaddr import (IPAddress, IPv4Address,
IPv6Address)
try: try:
ip = IPAddress(to_unicode(value)) ip = IPAddress(to_unicode(value))