Returns:
The binary representation of this address.
"""
- return Bytes(struct.pack("!QQ", address >> 64, address & (2 ** 64 - 1)))
+ return Bytes(struct.pack("!QQ", address >> 64, address & (2**64 - 1)))
def _find_address_range(addresses):
nbits = _count_righthand_zero_bits(first_int, ip_bits)
current = None
while nbits >= 0:
- addend = 2 ** nbits - 1
+ addend = 2**nbits - 1
current = first_int + addend
nbits -= 1
if current <= last_int:
return "%s" % self._string_from_ip_int(self._ip)
def __hash__(self):
- return hash(hex(long(self._ip)))
+ return hash(hex(int(self._ip)))
def _get_address_key(self):
return (self._version, self)
"""
# Equivalent to 255.255.255.255 or 32 bits of 1's.
- _ALL_ONES = (2 ** IPV4LENGTH) - 1
+ _ALL_ONES = (2**IPV4LENGTH) - 1
_DECIMAL_DIGITS = frozenset("0123456789")
def __init__(self, address):
"""
octets = []
- for _ in xrange(4):
+ for _ in range(4):
octets.insert(0, str(ip_int & 0xFF))
ip_int >>= 8
return ".".join(octets)
_BaseV4.__init__(self, address)
# Efficient constructor from integer.
- if isinstance(address, (int, long)):
+ if isinstance(address, int):
self._ip = address
if address < 0 or address > self._ALL_ONES:
raise AddressValueError(address)
_BaseV4.__init__(self, address)
# Constructing from an integer or packed bytes.
- if isinstance(address, (int, long, Bytes)):
+ if isinstance(address, (int, Bytes)):
self.ip = IPv4Address(address)
self._ip = self.ip._ip
self._prefixlen = self._max_prefixlen
"""
- _ALL_ONES = (2 ** IPV6LENGTH) - 1
+ _ALL_ONES = (2**IPV6LENGTH) - 1
_HEXTET_COUNT = 8
_HEX_DIGITS = frozenset("0123456789ABCDEFabcdef")
# Disregarding the endpoints, find '::' with nothing in between.
# This indicates that a run of zeroes has been skipped.
try:
- (skip_index,) = [i for i in xrange(1, len(parts) - 1) if not parts[i]] or [
+ (skip_index,) = [i for i in range(1, len(parts) - 1) if not parts[i]] or [
None
]
except ValueError:
try:
# Now, parse the hextets into a 128-bit integer.
ip_int = 0
- for i in xrange(parts_hi):
+ for i in range(parts_hi):
ip_int <<= 16
ip_int |= self._parse_hextet(parts[i])
ip_int <<= 16 * parts_skipped
- for i in xrange(-parts_lo, 0):
+ for i in range(-parts_lo, 0):
ip_int <<= 16
ip_int |= self._parse_hextet(parts[i])
return ip_int
ip_int = self._ip_int_from_string(ip_str)
parts = []
- for i in xrange(self._HEXTET_COUNT):
+ for i in range(self._HEXTET_COUNT):
parts.append("%04x" % (ip_int & 0xFFFF))
ip_int >>= 16
parts.reverse()
_BaseV6.__init__(self, address)
# Efficient constructor from integer.
- if isinstance(address, (int, long)):
+ if isinstance(address, int):
self._ip = address
if address < 0 or address > self._ALL_ONES:
raise AddressValueError(address)
_BaseV6.__init__(self, address)
# Constructing from an integer or packed bytes.
- if isinstance(address, (int, long, Bytes)):
+ if isinstance(address, (int, Bytes)):
self.ip = IPv6Address(address)
self._ip = self.ip._ip
self._prefixlen = self._max_prefixlen