Merge "Move ipaddr to netaddr"

This commit is contained in:
Jenkins 2015-05-29 13:04:49 +00:00 committed by Gerrit Code Review
commit 43e125ded9
4 changed files with 11 additions and 10 deletions

View File

@ -2,3 +2,4 @@ six>=1.9.0
WebOb>=1.2.3
simplegeneric
pytz
netaddr>=0.7.12

View File

@ -1,5 +1,5 @@
six>=1.9.0
WebOb>=1.2.3
simplegeneric
ipaddr
pytz
netaddr>=0.7.12

View File

@ -339,20 +339,24 @@ Value: 'v3'. Value should be one of: v., v.",
v = types.IPv4AddressType()
self.assertEqual(v.validate('127.0.0.1'), '127.0.0.1')
self.assertEqual(v.validate('192.168.0.1'), '192.168.0.1')
self.assertEqual(v.validate(u'8.8.1.1'), u'8.8.1.1')
self.assertRaises(ValueError, v.validate, '')
self.assertRaises(ValueError, v.validate, 'foo')
self.assertRaises(ValueError, v.validate,
'2001:0db8:bd05:01d2:288a:1fc0:0001:10ee')
self.assertRaises(ValueError, v.validate, '1.2.3')
def test_validate_ipv6_address_type(self):
v = types.IPv6AddressType()
self.assertEqual(v.validate('0:0:0:0:0:0:0:1'),
'0:0:0:0:0:0:0:1')
self.assertEqual(v.validate(u'0:0:0:0:0:0:0:1'), u'0:0:0:0:0:0:0:1')
self.assertEqual(v.validate('2001:0db8:bd05:01d2:288a:1fc0:0001:10ee'),
'2001:0db8:bd05:01d2:288a:1fc0:0001:10ee')
self.assertRaises(ValueError, v.validate, '')
self.assertRaises(ValueError, v.validate, 'foo')
self.assertRaises(ValueError, v.validate, '192.168.0.1')
self.assertRaises(ValueError, v.validate, '0:0:0:0:0:0:1')
def test_validate_uuid_type(self):
v = types.UuidType()

View File

@ -3,17 +3,13 @@ import datetime
import decimal
import inspect
import logging
import netaddr
import re
import six
import sys
import uuid
import weakref
try:
import ipaddress
except ImportError:
import ipaddr as ipaddress
from wsme import exc
log = logging.getLogger(__name__)
@ -234,8 +230,8 @@ class IPv4AddressType(UserType):
@staticmethod
def validate(value):
try:
ipaddress.IPv4Address(value)
except ipaddress.AddressValueError:
netaddr.IPAddress(value, version=4, flags=netaddr.INET_PTON)
except netaddr.AddrFormatError:
error = 'Value should be IPv4 format'
raise ValueError(error)
else:
@ -254,8 +250,8 @@ class IPv6AddressType(UserType):
@staticmethod
def validate(value):
try:
ipaddress.IPv6Address(value)
except ipaddress.AddressValueError:
netaddr.IPAddress(value, version=6, flags=netaddr.INET_PTON)
except netaddr.AddrFormatError:
error = 'Value should be IPv6 format'
raise ValueError(error)
else: