summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2011-09-09 16:50:27 +0000
committerpmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2011-09-09 16:50:27 +0000
commit8715efc66cbcf19d06a3089309bc12a504a9f445 (patch)
treef5ade8d73d2e6a6c6a4816f3562225977637bacb
parentc46392216d31d87f131151ed8e960b04c694b415 (diff)
downloadipaddr-py-8715efc66cbcf19d06a3089309bc12a504a9f445.tar.gz
remove strict from the ipinterface classes and have the network code check that host bits are not set prior to deleting the ip attribute
git-svn-id: https://ipaddr-py.googlecode.com/svn@232 09200d28-7f98-11dd-ad27-0f66e57d2035
-rw-r--r--branches/3144/ipaddr.py24
-rwxr-xr-xbranches/3144/ipaddr_test.py15
2 files changed, 20 insertions, 19 deletions
diff --git a/branches/3144/ipaddr.py b/branches/3144/ipaddr.py
index 653dcf3..5f00301 100644
--- a/branches/3144/ipaddr.py
+++ b/branches/3144/ipaddr.py
@@ -1279,7 +1279,7 @@ class IPv4Interface(_BaseV4, _BaseInterface):
# the valid octets for host and netmasks. only useful for IPv4.
_valid_mask_octets = set((255, 254, 252, 248, 240, 224, 192, 128, 0))
- def __init__(self, address, strict=False):
+ def __init__(self, address):
"""Instantiate a new IPv4 network object.
Args:
@@ -1377,10 +1377,6 @@ class IPv4Interface(_BaseV4, _BaseInterface):
self._prefixlen = self._max_prefixlen
self.netmask = IPv4Address(self._ip_int_from_prefix(
self._prefixlen))
- if strict:
- if self.ip != self.network_address:
- raise ValueError('%s has host bits set' %
- self.ip)
def _is_hostmask(self, ip_str):
"""Test if the IP string is a hostmask (rather than a netmask).
@@ -1438,7 +1434,10 @@ class IPv4Interface(_BaseV4, _BaseInterface):
class IPv4Network(IPv4Interface):
def __init__(self, address):
- IPv4Interface.__init__(self, address, strict=True)
+ IPv4Interface.__init__(self, address)
+ if self.ip != self.network_address:
+ raise ValueError('%s has host bits set' %
+ self.ip)
del self.__dict__['ip']
def __str__(self):
@@ -1882,7 +1881,7 @@ class IPv6Interface(_BaseV6, _BaseInterface):
"""
- def __init__(self, address, strict=False):
+ def __init__(self, address):
"""Instantiate a new IPv6 Network object.
Args:
@@ -1957,10 +1956,6 @@ class IPv6Interface(_BaseV6, _BaseInterface):
self.netmask = IPv6Address(self._ip_int_from_prefix(self._prefixlen))
- if strict:
- if self.ip != self.network_address:
- raise ValueError('%s has host bits set' %
- self.ip)
def _is_valid_netmask(self, prefixlen):
"""Verify that the netmask/prefixlen is valid.
@@ -1986,9 +1981,14 @@ class IPv6Interface(_BaseV6, _BaseInterface):
class IPv6Network(IPv6Interface):
def __init__(self, address):
- IPv6Interface.__init__(self, address, strict=True)
+ IPv6Interface.__init__(self, address)
+
+ if self.ip != self.network_address:
+ raise ValueError('%s has host bits set' %
+ self.ip)
del self.__dict__['ip']
+
def __str__(self):
return '%s/%d' % (str(self.network_address),
self.prefixlen)
diff --git a/branches/3144/ipaddr_test.py b/branches/3144/ipaddr_test.py
index b219b16..054166d 100755
--- a/branches/3144/ipaddr_test.py
+++ b/branches/3144/ipaddr_test.py
@@ -31,11 +31,10 @@ else:
class IpaddrUnitTest(unittest.TestCase):
def setUp(self):
- self.ipv4 = ipaddr.IPv4Interface('1.2.3.4/24', strict=False)
- self.ipv4_hostmask = ipaddr.IPv4Interface('10.0.0.1/0.255.255.255',
- strict=False)
- self.ipv6 = ipaddr.IPv6Interface('2001:658:22a:cafe:200:0:0:1/64',
- strict=False)
+ self.ipv4 = ipaddr.IPv4Interface('1.2.3.4/24')
+ self.ipv4_hostmask = ipaddr.IPv4Interface('10.0.0.1/0.255.255.255')
+
+ self.ipv6 = ipaddr.IPv6Interface('2001:658:22a:cafe:200:0:0:1/64')
def tearDown(self):
del(self.ipv4)
@@ -689,8 +688,10 @@ class IpaddrUnitTest(unittest.TestCase):
unsorted = [ip4, ip1, ip3, ip2]
unsorted.sort()
self.assertEqual(sorted, unsorted)
- self.assertRaises(TypeError, ip1.__lt__, ipaddr.ip_address('10.10.10.0'))
- self.assertRaises(TypeError, ip2.__lt__, ipaddr.ip_address('10.10.10.0'))
+ self.assertRaises(TypeError, ip1.__lt__,
+ ipaddr.ip_address('10.10.10.0'))
+ self.assertRaises(TypeError, ip2.__lt__,
+ ipaddr.ip_address('10.10.10.0'))
# <=, >=
self.assertTrue(ipaddr.ip_network('1.1.1.1') <=