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)
def iterhosts(self):
"""Generate Iterator over usable hosts in a network.
- This is like __iter__ except it doesn't return the network
- or broadcast addresses.
+ This is like __iter__ except it doesn't return the network
+ or broadcast addresses.
"""
cur = int(self.network) + 1
s1, s2 = s2.subnet()
else:
# If we got here, there's a bug somewhere.
- assert False, (
- "Error performing exclusion: "
- "s1: %s s2: %s other: %s" % (str(s1), str(s2), str(other))
+ assert (
+ False
+ ), "Error performing exclusion: " "s1: %s s2: %s other: %s" % (
+ str(s1),
+ str(s2),
+ str(other),
)
if s1 == other:
ret_addrs.append(s2)
"""
# 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()
class IPv6Address(_BaseV6, _BaseIP):
- """Represent and manipulate single IPv6 Addresses.
- """
+ """Represent and manipulate single IPv6 Addresses."""
def __init__(self, address):
"""Instantiate a new IPv6 address object.
_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