summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-07-07 12:15:22 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2012-07-07 12:15:22 (GMT)
commitb582ecc562b0a4c00e2d9fe39f42d22dd9c7f89e (patch)
tree72bf2ff495e65ebaa48c677a62e70ecebb783810 /Lib
parent01ac8b6ab1474d863f364b6c11eb9fce62324169 (diff)
downloadcpython-b582ecc562b0a4c00e2d9fe39f42d22dd9c7f89e.zip
cpython-b582ecc562b0a4c00e2d9fe39f42d22dd9c7f89e.tar.gz
cpython-b582ecc562b0a4c00e2d9fe39f42d22dd9c7f89e.tar.bz2
Issue 14814: Explain how to get more error detail in the ipaddress tutorial, and tweak the display for octet errors in IPv4 (noticed the formatting problem when adding to the docs)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ipaddress.py5
-rw-r--r--Lib/test/test_ipaddress.py6
2 files changed, 6 insertions, 5 deletions
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py
index bd79e2a..e788c0a5 100644
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -1048,7 +1048,7 @@ class _BaseV4:
raise ValueError("Ambiguous leading zero in %r not permitted" %
octet_str)
if octet_int > 255:
- raise ValueError("Octet %d > 255 not permitted" % octet_int)
+ raise ValueError("Octet %d (> 255) not permitted" % octet_int)
return octet_int
def _string_from_ip_int(self, ip_int):
@@ -1591,7 +1591,8 @@ class _BaseV6:
hextet_int = int(hextet_str, 16)
if hextet_int > 0xFFFF:
# This is unreachable due to the string length check above
- raise ValueError("Part %d > 0xFFFF not permitted" % hextet_int)
+ msg = "Part 0x%X (> 0xFFFF) not permitted"
+ raise ValueError(msg % hextet_int)
return hextet_int
def _compress_hextets(self, hextets):
diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py
index 61ec0d6..2ac37e1 100644
--- a/Lib/test/test_ipaddress.py
+++ b/Lib/test/test_ipaddress.py
@@ -126,8 +126,8 @@ class AddressErrors_v4(ErrorReporting):
def test_octet_limit(self):
def assertBadOctet(addr, octet):
- msg = "Octet %d > 255 not permitted in %r"
- with self.assertAddressError(msg, octet, addr):
+ msg = "Octet %d (> 255) not permitted in %r" % (octet, addr)
+ with self.assertAddressError(re.escape(msg)):
ipaddress.IPv4Address(addr)
assertBadOctet("12345.67899.-54321.-98765", 12345)
@@ -310,7 +310,7 @@ class NetmaskErrorsMixin_v4:
assertBadAddress("google.com", "Expected 4 octets")
assertBadAddress("10/8", "Expected 4 octets")
assertBadAddress("::1.2.3.4", "Only decimal digits")
- assertBadAddress("1.2.3.256", "256 > 255")
+ assertBadAddress("1.2.3.256", re.escape("256 (> 255)"))
def test_netmask_errors(self):
def assertBadNetmask(addr, netmask):