"""
+import struct
+
+
__version__ = '2.1.11'
-import struct
IPV4LENGTH = 32
IPV6LENGTH = 128
return _collapse_address_list_recursive(sorted(
addrs + nets, key=_BaseNet._get_networks_key))
+
# backwards compatibility
CollapseAddrList = collapse_address_list
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
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)
"""Represent and manipulate single IPv4 Addresses."""
def __init__(self, address):
-
"""
Args:
address: A string or integer representing the IP
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):
try:
# Now, parse the hextets into a 128-bit integer.
- ip_int = 0L
+ ip_int = 0
for i in xrange(parts_hi):
ip_int <<= 16
ip_int |= self._parse_hextet(parts[i])
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)