diff -r 3fbfa61634de Lib/ipaddress.py --- a/Lib/ipaddress.py Thu Jul 19 00:14:35 2012 -0500 +++ b/Lib/ipaddress.py Thu Jul 19 12:56:55 2012 +0300 @@ -11,7 +11,6 @@ __version__ = '1.0' -import struct import functools IPV4LENGTH = 32 @@ -135,7 +134,7 @@ """ try: - return struct.pack('!I', address) + return address.to_bytes(4, 'big') except: raise ValueError("Address negative or too large for IPv4") @@ -151,7 +150,7 @@ """ try: - return struct.pack('!QQ', address >> 64, address & (2**64 - 1)) + return address.to_bytes(16, 'big') except: raise ValueError("Address negative or too large for IPv6") @@ -1229,7 +1228,7 @@ # Constructing from a packed address if isinstance(address, bytes): self._check_packed_address(address, 4) - self._ip = struct.unpack('!I', address)[0] + self._ip = int.from_bytes(address, 'big') return # Assume input argument to be string or any object representation @@ -1596,8 +1595,8 @@ best_doublecolon_len = 0 doublecolon_start = -1 doublecolon_len = 0 - for index in range(len(hextets)): - if hextets[index] == '0': + for index, hextet in enumerate(hextets): + if hextet == '0': doublecolon_len += 1 if doublecolon_start == -1: # Start of a sequence of zeros. @@ -1870,8 +1869,7 @@ # Constructing from a packed address if isinstance(address, bytes): self._check_packed_address(address, 16) - tmp = struct.unpack('!QQ', address) - self._ip = (tmp[0] << 64) | tmp[1] + self._ip = int.from_bytes(address, 'big') return # Assume input argument to be string or any object representation