Eliminate USE_RFC8040
[integration/test.git] / csit / libraries / BGPCEP / ipaddr.py
index eb90e2d32d22821daabcf8d217991696d980d4f6..7b6d746386dcd7f465825b91c52bd6d28c3a6e7d 100644 (file)
@@ -146,7 +146,7 @@ def v6_int_to_packed(address):
     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):
@@ -255,7 +255,7 @@ def summarize_address_range(first, last):
         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:
@@ -529,7 +529,7 @@ class _BaseIP(_IPAddrBase):
         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)
@@ -557,8 +557,8 @@ class _BaseNet(_IPAddrBase):
     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
@@ -784,9 +784,12 @@ class _BaseNet(_IPAddrBase):
                 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)
@@ -1091,7 +1094,7 @@ class _BaseV4(object):
     """
 
     # 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):
@@ -1160,7 +1163,7 @@ class _BaseV4(object):
 
         """
         octets = []
-        for _ in xrange(4):
+        for _ in range(4):
             octets.insert(0, str(ip_int & 0xFF))
             ip_int >>= 8
         return ".".join(octets)
@@ -1269,7 +1272,7 @@ class IPv4Address(_BaseV4, _BaseIP):
         _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)
@@ -1348,7 +1351,7 @@ class IPv4Network(_BaseV4, _BaseNet):
         _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
@@ -1407,7 +1410,7 @@ class _BaseV6(object):
 
     """
 
-    _ALL_ONES = (2 ** IPV6LENGTH) - 1
+    _ALL_ONES = (2**IPV6LENGTH) - 1
     _HEXTET_COUNT = 8
     _HEX_DIGITS = frozenset("0123456789ABCDEFabcdef")
 
@@ -1447,7 +1450,7 @@ class _BaseV6(object):
         # 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:
@@ -1483,11 +1486,11 @@ class _BaseV6(object):
         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
@@ -1607,7 +1610,7 @@ class _BaseV6(object):
 
         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()
@@ -1768,8 +1771,7 @@ class _BaseV6(object):
 
 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.
@@ -1791,7 +1793,7 @@ class IPv6Address(_BaseV6, _BaseIP):
         _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)
@@ -1865,7 +1867,7 @@ class IPv6Network(_BaseV6, _BaseNet):
         _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