summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormshields@google.com <mshields@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2011-02-09 23:38:16 +0000
committermshields@google.com <mshields@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2011-02-09 23:38:16 +0000
commitf47de40de973ae0a0218d7d1407b889dfd404d14 (patch)
tree711ad4add67b8cf70d7f7835f32d1053e7c14b4d
parent82702a9402f6a14839268516ab19a835f935c537 (diff)
downloadipaddr-py-f47de40de973ae0a0218d7d1407b889dfd404d14.tar.gz
Merging through r209.
git-svn-id: https://ipaddr-py.googlecode.com/svn@210 09200d28-7f98-11dd-ad27-0f66e57d2035
-rw-r--r--branches/2.1.x/ipaddr.py40
-rwxr-xr-xbranches/2.1.x/ipaddr_test.py15
2 files changed, 33 insertions, 22 deletions
diff --git a/branches/2.1.x/ipaddr.py b/branches/2.1.x/ipaddr.py
index d1d98a2..45b98ae 100644
--- a/branches/2.1.x/ipaddr.py
+++ b/branches/2.1.x/ipaddr.py
@@ -436,14 +436,14 @@ class _BaseIP(_IPAddrBase):
"""
def __init__(self, address):
- if '/' in str(address):
+ if (not (_compat_has_real_bytes and isinstance(address, bytes))
+ and '/' in str(address)):
raise AddressValueError(address)
def __eq__(self, other):
try:
return (self._ip == other._ip
- and self._version == other._version
- and isinstance(other, _BaseIP))
+ and self._version == other._version)
except AttributeError:
return NotImplemented
@@ -608,7 +608,9 @@ class _BaseNet(_IPAddrBase):
and self.network == other.network
and int(self.netmask) == int(other.netmask))
except AttributeError:
- return NotImplemented
+ if isinstance(other, _BaseIP):
+ return (self._version == other._version
+ and self._ip == other._ip)
def __ne__(self, other):
eq = self.__eq__(other)
@@ -696,28 +698,28 @@ class _BaseNet(_IPAddrBase):
For example:
- addr1 = IP('10.1.1.0/24')
- addr2 = IP('10.1.1.0/26')
+ addr1 = IPNetwork('10.1.1.0/24')
+ addr2 = IPNetwork('10.1.1.0/26')
addr1.address_exclude(addr2) =
- [IP('10.1.1.64/26'), IP('10.1.1.128/25')]
+ [IPNetwork('10.1.1.64/26'), IPNetwork('10.1.1.128/25')]
or IPv6:
- addr1 = IP('::1/32')
- addr2 = IP('::1/128')
- addr1.address_exclude(addr2) = [IP('::0/128'),
- IP('::2/127'),
- IP('::4/126'),
- IP('::8/125'),
+ addr1 = IPNetwork('::1/32')
+ addr2 = IPNetwork('::1/128')
+ addr1.address_exclude(addr2) = [IPNetwork('::0/128'),
+ IPNetwork('::2/127'),
+ IPNetwork('::4/126'),
+ IPNetwork('::8/125'),
...
- IP('0:0:8000::/33')]
+ IPNetwork('0:0:8000::/33')]
Args:
- other: An IP object of the same type.
+ other: An IPvXNetwork object of the same type.
Returns:
- A sorted list of IP objects addresses which is self minus
- other.
+ A sorted list of IPvXNetwork objects addresses which is self
+ minus other.
Raises:
TypeError: If self and other are of difffering address
@@ -1685,7 +1687,7 @@ class _BaseV6(object):
RFC 2373 2.5.2.
"""
- return (self == IPv6Network('::') or self == IPv6Address('::'))
+ return self._ip == 0 and getattr(self, '_prefixlen', 128) == 128
@property
def is_loopback(self):
@@ -1696,7 +1698,7 @@ class _BaseV6(object):
RFC 2373 2.5.3.
"""
- return (self == IPv6Network('::1') or self == IPv6Address('::1'))
+ return self._ip == 1 and getattr(self, '_prefixlen', 128) == 128
@property
def is_link_local(self):
diff --git a/branches/2.1.x/ipaddr_test.py b/branches/2.1.x/ipaddr_test.py
index b7be753..5ad815c 100755
--- a/branches/2.1.x/ipaddr_test.py
+++ b/branches/2.1.x/ipaddr_test.py
@@ -423,9 +423,21 @@ class IpaddrUnitTest(unittest.TestCase):
self.assertFalse(self.ipv4 == '')
self.assertFalse(self.ipv4 == [])
self.assertFalse(self.ipv4 == 2)
+ self.assertTrue(ipaddr.IPNetwork('1.1.1.1/32') ==
+ ipaddr.IPAddress('1.1.1.1'))
+ self.assertTrue(ipaddr.IPNetwork('1.1.1.1/24') ==
+ ipaddr.IPAddress('1.1.1.1'))
+ self.assertFalse(ipaddr.IPNetwork('1.1.1.0/24') ==
+ ipaddr.IPAddress('1.1.1.1'))
self.assertTrue(self.ipv6 ==
ipaddr.IPv6Network('2001:658:22a:cafe:200::1/64'))
+ self.assertTrue(ipaddr.IPNetwork('::1/128') ==
+ ipaddr.IPAddress('::1'))
+ self.assertTrue(ipaddr.IPNetwork('::1/127') ==
+ ipaddr.IPAddress('::1'))
+ self.assertFalse(ipaddr.IPNetwork('::0/127') ==
+ ipaddr.IPAddress('::1'))
self.assertFalse(self.ipv6 ==
ipaddr.IPv6Network('2001:658:22a:cafe:200::1/63'))
self.assertFalse(self.ipv6 == ipaddr.IPv4Network('1.2.3.4/23'))
@@ -434,9 +446,7 @@ class IpaddrUnitTest(unittest.TestCase):
self.assertFalse(self.ipv6 == 2)
def testNotEquals(self):
- addr1 = ipaddr.IPAddress('1.2.3.4')
self.assertFalse(self.ipv4 != ipaddr.IPv4Network('1.2.3.4/24'))
- self.assertFalse(self.ipv4 == addr1)
self.assertTrue(self.ipv4 != ipaddr.IPv4Network('1.2.3.4/23'))
self.assertTrue(self.ipv4 != ipaddr.IPv6Network('::1.2.3.4/24'))
self.assertTrue(self.ipv4 != '')
@@ -446,7 +456,6 @@ class IpaddrUnitTest(unittest.TestCase):
addr2 = ipaddr.IPAddress('2001:658:22a:cafe:200::1')
self.assertFalse(self.ipv6 !=
ipaddr.IPv6Network('2001:658:22a:cafe:200::1/64'))
- self.assertFalse(self.ipv6 == addr2)
self.assertTrue(self.ipv6 !=
ipaddr.IPv6Network('2001:658:22a:cafe:200::1/63'))
self.assertTrue(self.ipv6 != ipaddr.IPv4Network('1.2.3.4/23'))