COE-43: Check for stale veth ports
[integration/test.git] / csit / libraries / ipaddr.py
index 35bc994abb67afd439afd3015e4e5a94e43e68ae..7208218683e16875018dc23094e99037f9085f85 100644 (file)
@@ -22,9 +22,11 @@ and networks.
 
 """
 
+import struct
+
+
 __version__ = '2.1.11'
 
-import struct
 
 IPV4LENGTH = 32
 IPV6LENGTH = 128
@@ -369,6 +371,7 @@ def collapse_address_list(addresses):
     return _collapse_address_list_recursive(sorted(
         addrs + nets, key=_BaseNet._get_networks_key))
 
+
 # backwards compatibility
 CollapseAddrList = collapse_address_list
 
@@ -455,8 +458,8 @@ class _BaseIP(_IPAddrBase):
 
     def __eq__(self, other):
         try:
-            return (self._ip == other._ip
-                    and self._version == other._version)
+            return (self._ip == other._ip and
+                    self._version == other._version)
         except AttributeError:
             return NotImplemented
 
@@ -617,13 +620,13 @@ class _BaseNet(_IPAddrBase):
 
     def __eq__(self, other):
         try:
-            return (self._version == other._version
-                    and self.network == other.network
-                    and int(self.netmask) == int(other.netmask))
+            return (self._version == other._version and
+                    self.network == other.network and
+                    int(self.netmask) == int(other.netmask))
         except AttributeError:
             if isinstance(other, _BaseIP):
-                return (self._version == other._version
-                        and self._ip == other._ip)
+                return (self._version == other._version and
+                        self._ip == other._ip)
 
     def __ne__(self, other):
         eq = self.__eq__(other)
@@ -1226,7 +1229,6 @@ class IPv4Address(_BaseV4, _BaseIP):
     """Represent and manipulate single IPv4 Addresses."""
 
     def __init__(self, address):
-
         """
         Args:
             address: A string or integer representing the IP
@@ -1362,10 +1364,17 @@ class IPv4Network(_BaseV4, _BaseNet):
             self.iterhosts = self.__iter__
 
     # backwards compatibility
-    IsRFC1918 = lambda self: self.is_private
-    IsMulticast = lambda self: self.is_multicast
-    IsLoopback = lambda self: self.is_loopback
-    IsLinkLocal = lambda self: self.is_link_local
+    def IsRFC1918(self):
+        return self.is_private
+
+    def IsMulticast(self):
+        return self.is_multicast
+
+    def IsLoopback(self):
+        return self.is_loopback
+
+    def IsLinkLocal(self):
+        return self.is_link_local
 
 
 class _BaseV6(object):
@@ -1556,7 +1565,7 @@ class _BaseV6(object):
         hex_str = '%032x' % ip_int
         hextets = []
         for x in range(0, 32, 4):
-            hextets.append('%x' % int(hex_str[x:x+4], 16))
+            hextets.append('%x' % int(hex_str[x:x + 4], 16))
 
         hextets = self._compress_hextets(hextets)
         return ':'.join(hextets)