diff -r 23beb7f8561a Lib/ipaddress.py --- a/Lib/ipaddress.py Fri Jun 29 15:12:54 2012 +0300 +++ b/Lib/ipaddress.py Fri Jun 29 11:30:27 2012 -0700 @@ -1249,7 +1249,8 @@ return # Constructing from a packed address - if isinstance(address, bytes) and len(address) == 4: + if (not isinstance(address, str) and + isinstance(address, bytes) and len(address) == 4): self._ip = struct.unpack('!I', address)[0] return @@ -1557,6 +1558,8 @@ # Whitelist the characters, since int() allows a lot of bizarre stuff. if not self._HEX_DIGITS.issuperset(hextet_str): raise ValueError + if len(hextet_str) > 4: + raise ValueError hextet_int = int(hextet_str, 16) if hextet_int > 0xFFFF: raise ValueError @@ -1860,7 +1863,8 @@ return # Constructing from a packed address - if isinstance(address, bytes) and len(address) == 16: + if (not isinstance(address, str) and + isinstance(address, bytes) and len(address) == 16): tmp = struct.unpack('!QQ', address) self._ip = (tmp[0] << 64) | tmp[1] return diff -r 23beb7f8561a Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py Fri Jun 29 15:12:54 2012 +0300 +++ b/Lib/test/test_ipaddress.py Fri Jun 29 11:30:27 2012 -0700 @@ -106,6 +106,9 @@ AssertInvalidIP(":1:2:3:4:5:6:7") AssertInvalidIP("1:2:3:4:5:6:7:") AssertInvalidIP(":1:2:3:4:5:6:") + AssertInvalidIP("1000") + AssertInvalidIP("1000000000000000") + AssertInvalidIP("02001:db8::") self.assertRaises(ipaddress.AddressValueError, ipaddress.IPv4Interface, '')