summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2010-04-29 17:15:43 +0000
committerpmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2010-04-29 17:15:43 +0000
commit256c09753d0faed5a371e4181800015e5628b601 (patch)
tree17643dbb3183fca72213e565e898d1879c5b71f4
parent0f749d257bcdef7b4e88262bb3eaa0f60c289dfc (diff)
downloadipaddr-py-256c09753d0faed5a371e4181800015e5628b601.tar.gz
+ one more address_exclude cleanup, to make sure network/address exclusions
fail as expected. git-svn-id: https://ipaddr-py.googlecode.com/svn@163 09200d28-7f98-11dd-ad27-0f66e57d2035
-rw-r--r--trunk/ipaddr.py9
-rwxr-xr-xtrunk/ipaddr_test.py2
2 files changed, 8 insertions, 3 deletions
diff --git a/trunk/ipaddr.py b/trunk/ipaddr.py
index 80b04b9..6b636eb 100644
--- a/trunk/ipaddr.py
+++ b/trunk/ipaddr.py
@@ -198,7 +198,7 @@ def summarize_address_range(first, last):
raise TypeError('first and last must be IP addresses, not networks')
if first.version != last.version:
raise TypeError("%s and %s are not of the same version" % (
- str(self), str(other)))
+ str(self), str(other)))
if first > last:
raise ValueError('last IP address must be greater than first')
@@ -356,7 +356,7 @@ def get_mixed_type_key(obj):
doesn't make any sense. There are some times however, where you may wish
to have ipaddr sort these for you anyway. If you need to do this, you
can use this function as the key= argument to sorted().
-
+
Args:
obj: either a Network or Address object.
Returns:
@@ -684,7 +684,7 @@ class _BaseNet(_IPAddrBase):
Raises:
TypeError: If self and other are of difffering address
- versions.
+ versions, or if other is not a network object.
ValueError: If other is not completely contained by self.
"""
@@ -692,6 +692,9 @@ class _BaseNet(_IPAddrBase):
raise TypeError("%s and %s are not of the same version" % (
str(self), str(other)))
+ if not isinstance(other, _BaseNet):
+ raise TypeError("%s is not a network object" % str(other))
+
if other not in self:
raise ValueError('%s not contained in %s' % (str(other),
str(self)))
diff --git a/trunk/ipaddr_test.py b/trunk/ipaddr_test.py
index 04cf8d9..8d14940 100755
--- a/trunk/ipaddr_test.py
+++ b/trunk/ipaddr_test.py
@@ -788,10 +788,12 @@ class IpaddrUnitTest(unittest.TestCase):
addr1 = ipaddr.IPNetwork('10.1.1.0/24')
addr2 = ipaddr.IPNetwork('10.1.1.0/26')
addr3 = ipaddr.IPNetwork('10.2.1.0/24')
+ addr4 = ipaddr.IPAddress('10.1.1.0')
self.assertEqual(addr1.address_exclude(addr2),
[ipaddr.IPNetwork('10.1.1.64/26'),
ipaddr.IPNetwork('10.1.1.128/25')])
self.assertRaises(ValueError, addr1.address_exclude, addr3)
+ self.assertRaises(TypeError, addr1.address_exclude, addr4)
self.assertEqual(addr1.address_exclude(addr1), [])
def testHash(self):