In other words, probably crash if convert_ip() is fed garbage. That's
OK. We could check the length of the hex string and raise a ValueError
if it isn't 8 or 32, but we might be solving problems that don't exist.
if len(ip) == 8:
# IPv4, eg. "7f000001" -> "7f 00 00 01" -> "127.0.0.1"
return ".".join(map(str, pack(">L", int(ip, 16))))
- elif len(ip) == 32:
- # IPv6 is actually simpler -- it's just a string-slicing operation.
- return ":".join([ip[(4*i) : (4*i+4)] for i in range(8)])
+
+ # IPv6 is actually simpler -- it's just a string-slicing operation.
+ return ":".join([ip[(4*i) : (4*i+4)] for i in range(8)])