|
|
badbda |
From 80071f4450261b70b70f537bc2b54d2c97d9f562 Mon Sep 17 00:00:00 2001
|
|
|
badbda |
From: "David P. D. Moss" <drkjam@gmail.com>
|
|
|
badbda |
Date: Thu, 25 Nov 2010 08:53:49 +0000
|
|
|
badbda |
Subject: [PATCH] Fixed github Issue no. 2. Thanks keesbos.
|
|
|
badbda |
|
|
|
badbda |
---
|
|
|
badbda |
netaddr/ip/__init__.py | 2 ++
|
|
|
badbda |
netaddr/tests/2.x/ip/constructor.txt | 11 +++++++++++
|
|
|
badbda |
netaddr/tests/3.x/ip/constructor.txt | 11 +++++++++++
|
|
|
badbda |
3 files changed, 24 insertions(+), 0 deletions(-)
|
|
|
badbda |
|
|
|
badbda |
diff --git a/netaddr/ip/__init__.py b/netaddr/ip/__init__.py
|
|
|
badbda |
index 0179c38..e4a6b7b 100644
|
|
|
badbda |
--- a/netaddr/ip/__init__.py
|
|
|
badbda |
+++ b/netaddr/ip/__init__.py
|
|
|
badbda |
@@ -779,6 +779,8 @@ def parse_ip_network(module, addr, implicit_prefix=False, flags=0):
|
|
|
badbda |
# Try a partial IPv4 network address...
|
|
|
badbda |
expanded_addr = _ipv4.expand_partial_address(val1)
|
|
|
badbda |
ip = IPAddress(expanded_addr, module.version, flags=INET_PTON)
|
|
|
badbda |
+ else:
|
|
|
badbda |
+ raise AddrFormatError('invalid IPNetwork address %s!' % addr)
|
|
|
badbda |
value = ip._value
|
|
|
badbda |
|
|
|
badbda |
try:
|
|
|
badbda |
diff --git a/netaddr/tests/2.x/ip/constructor.txt b/netaddr/tests/2.x/ip/constructor.txt
|
|
|
badbda |
index f67f5e4..5a9e978 100644
|
|
|
badbda |
--- a/netaddr/tests/2.x/ip/constructor.txt
|
|
|
badbda |
+++ b/netaddr/tests/2.x/ip/constructor.txt
|
|
|
badbda |
@@ -209,3 +209,14 @@ IPNetwork('172.24.0.0/16')
|
|
|
badbda |
|
|
|
badbda |
|
|
|
badbda |
}}}
|
|
|
badbda |
+
|
|
|
badbda |
+Negative testing
|
|
|
badbda |
+
|
|
|
badbda |
+{{{
|
|
|
badbda |
+
|
|
|
badbda |
+>>> IPNetwork('foo')
|
|
|
badbda |
+Traceback (most recent call last):
|
|
|
badbda |
+...
|
|
|
badbda |
+AddrFormatError: invalid IPNetwork foo
|
|
|
badbda |
+
|
|
|
badbda |
+}}}
|
|
|
badbda |
diff --git a/netaddr/tests/3.x/ip/constructor.txt b/netaddr/tests/3.x/ip/constructor.txt
|
|
|
badbda |
index 2ec47c0..35a5cd6 100644
|
|
|
badbda |
--- a/netaddr/tests/3.x/ip/constructor.txt
|
|
|
badbda |
+++ b/netaddr/tests/3.x/ip/constructor.txt
|
|
|
badbda |
@@ -209,3 +209,14 @@ IPNetwork('172.24.0.0/16')
|
|
|
badbda |
|
|
|
badbda |
|
|
|
badbda |
}}}
|
|
|
badbda |
+
|
|
|
badbda |
+Negative testing
|
|
|
badbda |
+
|
|
|
badbda |
+{{{
|
|
|
badbda |
+
|
|
|
badbda |
+>>> IPNetwork('foo')
|
|
|
badbda |
+Traceback (most recent call last):
|
|
|
badbda |
+...
|
|
|
badbda |
+netaddr.core.AddrFormatError: invalid IPNetwork foo
|
|
|
badbda |
+
|
|
|
badbda |
+}}}
|
|
|
badbda |
--
|
|
|
badbda |
1.7.5.2
|
|
|
badbda |
|