Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/python2..../site-pac...
File: ipaddress.py
# Copyright 2007 Google Inc.
[0] Fix | Delete
# Licensed to PSF under a Contributor Agreement.
[1] Fix | Delete
[2] Fix | Delete
"""A fast, lightweight IPv4/IPv6 manipulation library in Python.
[3] Fix | Delete
[4] Fix | Delete
This library is used to create/poke/manipulate IPv4 and IPv6 addresses
[5] Fix | Delete
and networks.
[6] Fix | Delete
[7] Fix | Delete
"""
[8] Fix | Delete
[9] Fix | Delete
from __future__ import unicode_literals
[10] Fix | Delete
[11] Fix | Delete
[12] Fix | Delete
import itertools
[13] Fix | Delete
import struct
[14] Fix | Delete
[15] Fix | Delete
__version__ = '1.0.18'
[16] Fix | Delete
[17] Fix | Delete
# Compatibility functions
[18] Fix | Delete
_compat_int_types = (int,)
[19] Fix | Delete
try:
[20] Fix | Delete
_compat_int_types = (int, long)
[21] Fix | Delete
except NameError:
[22] Fix | Delete
pass
[23] Fix | Delete
try:
[24] Fix | Delete
_compat_str = unicode
[25] Fix | Delete
except NameError:
[26] Fix | Delete
_compat_str = str
[27] Fix | Delete
assert bytes != str
[28] Fix | Delete
if b'\0'[0] == 0: # Python 3 semantics
[29] Fix | Delete
def _compat_bytes_to_byte_vals(byt):
[30] Fix | Delete
return byt
[31] Fix | Delete
else:
[32] Fix | Delete
def _compat_bytes_to_byte_vals(byt):
[33] Fix | Delete
return [struct.unpack(b'!B', b)[0] for b in byt]
[34] Fix | Delete
try:
[35] Fix | Delete
_compat_int_from_byte_vals = int.from_bytes
[36] Fix | Delete
except AttributeError:
[37] Fix | Delete
def _compat_int_from_byte_vals(bytvals, endianess):
[38] Fix | Delete
assert endianess == 'big'
[39] Fix | Delete
res = 0
[40] Fix | Delete
for bv in bytvals:
[41] Fix | Delete
assert isinstance(bv, _compat_int_types)
[42] Fix | Delete
res = (res << 8) + bv
[43] Fix | Delete
return res
[44] Fix | Delete
[45] Fix | Delete
[46] Fix | Delete
def _compat_to_bytes(intval, length, endianess):
[47] Fix | Delete
assert isinstance(intval, _compat_int_types)
[48] Fix | Delete
assert endianess == 'big'
[49] Fix | Delete
if length == 4:
[50] Fix | Delete
if intval < 0 or intval >= 2 ** 32:
[51] Fix | Delete
raise struct.error("integer out of range for 'I' format code")
[52] Fix | Delete
return struct.pack(b'!I', intval)
[53] Fix | Delete
elif length == 16:
[54] Fix | Delete
if intval < 0 or intval >= 2 ** 128:
[55] Fix | Delete
raise struct.error("integer out of range for 'QQ' format code")
[56] Fix | Delete
return struct.pack(b'!QQ', intval >> 64, intval & 0xffffffffffffffff)
[57] Fix | Delete
else:
[58] Fix | Delete
raise NotImplementedError()
[59] Fix | Delete
[60] Fix | Delete
[61] Fix | Delete
if hasattr(int, 'bit_length'):
[62] Fix | Delete
# Not int.bit_length , since that won't work in 2.7 where long exists
[63] Fix | Delete
def _compat_bit_length(i):
[64] Fix | Delete
return i.bit_length()
[65] Fix | Delete
else:
[66] Fix | Delete
def _compat_bit_length(i):
[67] Fix | Delete
for res in itertools.count():
[68] Fix | Delete
if i >> res == 0:
[69] Fix | Delete
return res
[70] Fix | Delete
[71] Fix | Delete
[72] Fix | Delete
def _compat_range(start, end, step=1):
[73] Fix | Delete
assert step > 0
[74] Fix | Delete
i = start
[75] Fix | Delete
while i < end:
[76] Fix | Delete
yield i
[77] Fix | Delete
i += step
[78] Fix | Delete
[79] Fix | Delete
[80] Fix | Delete
class _TotalOrderingMixin(object):
[81] Fix | Delete
__slots__ = ()
[82] Fix | Delete
[83] Fix | Delete
# Helper that derives the other comparison operations from
[84] Fix | Delete
# __lt__ and __eq__
[85] Fix | Delete
# We avoid functools.total_ordering because it doesn't handle
[86] Fix | Delete
# NotImplemented correctly yet (http://bugs.python.org/issue10042)
[87] Fix | Delete
def __eq__(self, other):
[88] Fix | Delete
raise NotImplementedError
[89] Fix | Delete
[90] Fix | Delete
def __ne__(self, other):
[91] Fix | Delete
equal = self.__eq__(other)
[92] Fix | Delete
if equal is NotImplemented:
[93] Fix | Delete
return NotImplemented
[94] Fix | Delete
return not equal
[95] Fix | Delete
[96] Fix | Delete
def __lt__(self, other):
[97] Fix | Delete
raise NotImplementedError
[98] Fix | Delete
[99] Fix | Delete
def __le__(self, other):
[100] Fix | Delete
less = self.__lt__(other)
[101] Fix | Delete
if less is NotImplemented or not less:
[102] Fix | Delete
return self.__eq__(other)
[103] Fix | Delete
return less
[104] Fix | Delete
[105] Fix | Delete
def __gt__(self, other):
[106] Fix | Delete
less = self.__lt__(other)
[107] Fix | Delete
if less is NotImplemented:
[108] Fix | Delete
return NotImplemented
[109] Fix | Delete
equal = self.__eq__(other)
[110] Fix | Delete
if equal is NotImplemented:
[111] Fix | Delete
return NotImplemented
[112] Fix | Delete
return not (less or equal)
[113] Fix | Delete
[114] Fix | Delete
def __ge__(self, other):
[115] Fix | Delete
less = self.__lt__(other)
[116] Fix | Delete
if less is NotImplemented:
[117] Fix | Delete
return NotImplemented
[118] Fix | Delete
return not less
[119] Fix | Delete
[120] Fix | Delete
[121] Fix | Delete
IPV4LENGTH = 32
[122] Fix | Delete
IPV6LENGTH = 128
[123] Fix | Delete
[124] Fix | Delete
[125] Fix | Delete
class AddressValueError(ValueError):
[126] Fix | Delete
"""A Value Error related to the address."""
[127] Fix | Delete
[128] Fix | Delete
[129] Fix | Delete
class NetmaskValueError(ValueError):
[130] Fix | Delete
"""A Value Error related to the netmask."""
[131] Fix | Delete
[132] Fix | Delete
[133] Fix | Delete
def ip_address(address):
[134] Fix | Delete
"""Take an IP string/int and return an object of the correct type.
[135] Fix | Delete
[136] Fix | Delete
Args:
[137] Fix | Delete
address: A string or integer, the IP address. Either IPv4 or
[138] Fix | Delete
IPv6 addresses may be supplied; integers less than 2**32 will
[139] Fix | Delete
be considered to be IPv4 by default.
[140] Fix | Delete
[141] Fix | Delete
Returns:
[142] Fix | Delete
An IPv4Address or IPv6Address object.
[143] Fix | Delete
[144] Fix | Delete
Raises:
[145] Fix | Delete
ValueError: if the *address* passed isn't either a v4 or a v6
[146] Fix | Delete
address
[147] Fix | Delete
[148] Fix | Delete
"""
[149] Fix | Delete
try:
[150] Fix | Delete
return IPv4Address(address)
[151] Fix | Delete
except (AddressValueError, NetmaskValueError):
[152] Fix | Delete
pass
[153] Fix | Delete
[154] Fix | Delete
try:
[155] Fix | Delete
return IPv6Address(address)
[156] Fix | Delete
except (AddressValueError, NetmaskValueError):
[157] Fix | Delete
pass
[158] Fix | Delete
[159] Fix | Delete
if isinstance(address, bytes):
[160] Fix | Delete
raise AddressValueError(
[161] Fix | Delete
'%r does not appear to be an IPv4 or IPv6 address. '
[162] Fix | Delete
'Did you pass in a bytes (str in Python 2) instead of'
[163] Fix | Delete
' a unicode object?' % address)
[164] Fix | Delete
[165] Fix | Delete
raise ValueError('%r does not appear to be an IPv4 or IPv6 address' %
[166] Fix | Delete
address)
[167] Fix | Delete
[168] Fix | Delete
[169] Fix | Delete
def ip_network(address, strict=True):
[170] Fix | Delete
"""Take an IP string/int and return an object of the correct type.
[171] Fix | Delete
[172] Fix | Delete
Args:
[173] Fix | Delete
address: A string or integer, the IP network. Either IPv4 or
[174] Fix | Delete
IPv6 networks may be supplied; integers less than 2**32 will
[175] Fix | Delete
be considered to be IPv4 by default.
[176] Fix | Delete
[177] Fix | Delete
Returns:
[178] Fix | Delete
An IPv4Network or IPv6Network object.
[179] Fix | Delete
[180] Fix | Delete
Raises:
[181] Fix | Delete
ValueError: if the string passed isn't either a v4 or a v6
[182] Fix | Delete
address. Or if the network has host bits set.
[183] Fix | Delete
[184] Fix | Delete
"""
[185] Fix | Delete
try:
[186] Fix | Delete
return IPv4Network(address, strict)
[187] Fix | Delete
except (AddressValueError, NetmaskValueError):
[188] Fix | Delete
pass
[189] Fix | Delete
[190] Fix | Delete
try:
[191] Fix | Delete
return IPv6Network(address, strict)
[192] Fix | Delete
except (AddressValueError, NetmaskValueError):
[193] Fix | Delete
pass
[194] Fix | Delete
[195] Fix | Delete
if isinstance(address, bytes):
[196] Fix | Delete
raise AddressValueError(
[197] Fix | Delete
'%r does not appear to be an IPv4 or IPv6 network. '
[198] Fix | Delete
'Did you pass in a bytes (str in Python 2) instead of'
[199] Fix | Delete
' a unicode object?' % address)
[200] Fix | Delete
[201] Fix | Delete
raise ValueError('%r does not appear to be an IPv4 or IPv6 network' %
[202] Fix | Delete
address)
[203] Fix | Delete
[204] Fix | Delete
[205] Fix | Delete
def ip_interface(address):
[206] Fix | Delete
"""Take an IP string/int and return an object of the correct type.
[207] Fix | Delete
[208] Fix | Delete
Args:
[209] Fix | Delete
address: A string or integer, the IP address. Either IPv4 or
[210] Fix | Delete
IPv6 addresses may be supplied; integers less than 2**32 will
[211] Fix | Delete
be considered to be IPv4 by default.
[212] Fix | Delete
[213] Fix | Delete
Returns:
[214] Fix | Delete
An IPv4Interface or IPv6Interface object.
[215] Fix | Delete
[216] Fix | Delete
Raises:
[217] Fix | Delete
ValueError: if the string passed isn't either a v4 or a v6
[218] Fix | Delete
address.
[219] Fix | Delete
[220] Fix | Delete
Notes:
[221] Fix | Delete
The IPv?Interface classes describe an Address on a particular
[222] Fix | Delete
Network, so they're basically a combination of both the Address
[223] Fix | Delete
and Network classes.
[224] Fix | Delete
[225] Fix | Delete
"""
[226] Fix | Delete
try:
[227] Fix | Delete
return IPv4Interface(address)
[228] Fix | Delete
except (AddressValueError, NetmaskValueError):
[229] Fix | Delete
pass
[230] Fix | Delete
[231] Fix | Delete
try:
[232] Fix | Delete
return IPv6Interface(address)
[233] Fix | Delete
except (AddressValueError, NetmaskValueError):
[234] Fix | Delete
pass
[235] Fix | Delete
[236] Fix | Delete
raise ValueError('%r does not appear to be an IPv4 or IPv6 interface' %
[237] Fix | Delete
address)
[238] Fix | Delete
[239] Fix | Delete
[240] Fix | Delete
def v4_int_to_packed(address):
[241] Fix | Delete
"""Represent an address as 4 packed bytes in network (big-endian) order.
[242] Fix | Delete
[243] Fix | Delete
Args:
[244] Fix | Delete
address: An integer representation of an IPv4 IP address.
[245] Fix | Delete
[246] Fix | Delete
Returns:
[247] Fix | Delete
The integer address packed as 4 bytes in network (big-endian) order.
[248] Fix | Delete
[249] Fix | Delete
Raises:
[250] Fix | Delete
ValueError: If the integer is negative or too large to be an
[251] Fix | Delete
IPv4 IP address.
[252] Fix | Delete
[253] Fix | Delete
"""
[254] Fix | Delete
try:
[255] Fix | Delete
return _compat_to_bytes(address, 4, 'big')
[256] Fix | Delete
except (struct.error, OverflowError):
[257] Fix | Delete
raise ValueError("Address negative or too large for IPv4")
[258] Fix | Delete
[259] Fix | Delete
[260] Fix | Delete
def v6_int_to_packed(address):
[261] Fix | Delete
"""Represent an address as 16 packed bytes in network (big-endian) order.
[262] Fix | Delete
[263] Fix | Delete
Args:
[264] Fix | Delete
address: An integer representation of an IPv6 IP address.
[265] Fix | Delete
[266] Fix | Delete
Returns:
[267] Fix | Delete
The integer address packed as 16 bytes in network (big-endian) order.
[268] Fix | Delete
[269] Fix | Delete
"""
[270] Fix | Delete
try:
[271] Fix | Delete
return _compat_to_bytes(address, 16, 'big')
[272] Fix | Delete
except (struct.error, OverflowError):
[273] Fix | Delete
raise ValueError("Address negative or too large for IPv6")
[274] Fix | Delete
[275] Fix | Delete
[276] Fix | Delete
def _split_optional_netmask(address):
[277] Fix | Delete
"""Helper to split the netmask and raise AddressValueError if needed"""
[278] Fix | Delete
addr = _compat_str(address).split('/')
[279] Fix | Delete
if len(addr) > 2:
[280] Fix | Delete
raise AddressValueError("Only one '/' permitted in %r" % address)
[281] Fix | Delete
return addr
[282] Fix | Delete
[283] Fix | Delete
[284] Fix | Delete
def _find_address_range(addresses):
[285] Fix | Delete
"""Find a sequence of sorted deduplicated IPv#Address.
[286] Fix | Delete
[287] Fix | Delete
Args:
[288] Fix | Delete
addresses: a list of IPv#Address objects.
[289] Fix | Delete
[290] Fix | Delete
Yields:
[291] Fix | Delete
A tuple containing the first and last IP addresses in the sequence.
[292] Fix | Delete
[293] Fix | Delete
"""
[294] Fix | Delete
it = iter(addresses)
[295] Fix | Delete
first = last = next(it)
[296] Fix | Delete
for ip in it:
[297] Fix | Delete
if ip._ip != last._ip + 1:
[298] Fix | Delete
yield first, last
[299] Fix | Delete
first = ip
[300] Fix | Delete
last = ip
[301] Fix | Delete
yield first, last
[302] Fix | Delete
[303] Fix | Delete
[304] Fix | Delete
def _count_righthand_zero_bits(number, bits):
[305] Fix | Delete
"""Count the number of zero bits on the right hand side.
[306] Fix | Delete
[307] Fix | Delete
Args:
[308] Fix | Delete
number: an integer.
[309] Fix | Delete
bits: maximum number of bits to count.
[310] Fix | Delete
[311] Fix | Delete
Returns:
[312] Fix | Delete
The number of zero bits on the right hand side of the number.
[313] Fix | Delete
[314] Fix | Delete
"""
[315] Fix | Delete
if number == 0:
[316] Fix | Delete
return bits
[317] Fix | Delete
return min(bits, _compat_bit_length(~number & (number - 1)))
[318] Fix | Delete
[319] Fix | Delete
[320] Fix | Delete
def summarize_address_range(first, last):
[321] Fix | Delete
"""Summarize a network range given the first and last IP addresses.
[322] Fix | Delete
[323] Fix | Delete
Example:
[324] Fix | Delete
>>> list(summarize_address_range(IPv4Address('192.0.2.0'),
[325] Fix | Delete
... IPv4Address('192.0.2.130')))
[326] Fix | Delete
... #doctest: +NORMALIZE_WHITESPACE
[327] Fix | Delete
[IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'),
[328] Fix | Delete
IPv4Network('192.0.2.130/32')]
[329] Fix | Delete
[330] Fix | Delete
Args:
[331] Fix | Delete
first: the first IPv4Address or IPv6Address in the range.
[332] Fix | Delete
last: the last IPv4Address or IPv6Address in the range.
[333] Fix | Delete
[334] Fix | Delete
Returns:
[335] Fix | Delete
An iterator of the summarized IPv(4|6) network objects.
[336] Fix | Delete
[337] Fix | Delete
Raise:
[338] Fix | Delete
TypeError:
[339] Fix | Delete
If the first and last objects are not IP addresses.
[340] Fix | Delete
If the first and last objects are not the same version.
[341] Fix | Delete
ValueError:
[342] Fix | Delete
If the last object is not greater than the first.
[343] Fix | Delete
If the version of the first address is not 4 or 6.
[344] Fix | Delete
[345] Fix | Delete
"""
[346] Fix | Delete
if (not (isinstance(first, _BaseAddress) and
[347] Fix | Delete
isinstance(last, _BaseAddress))):
[348] Fix | Delete
raise TypeError('first and last must be IP addresses, not networks')
[349] Fix | Delete
if first.version != last.version:
[350] Fix | Delete
raise TypeError("%s and %s are not of the same version" % (
[351] Fix | Delete
first, last))
[352] Fix | Delete
if first > last:
[353] Fix | Delete
raise ValueError('last IP address must be greater than first')
[354] Fix | Delete
[355] Fix | Delete
if first.version == 4:
[356] Fix | Delete
ip = IPv4Network
[357] Fix | Delete
elif first.version == 6:
[358] Fix | Delete
ip = IPv6Network
[359] Fix | Delete
else:
[360] Fix | Delete
raise ValueError('unknown IP version')
[361] Fix | Delete
[362] Fix | Delete
ip_bits = first._max_prefixlen
[363] Fix | Delete
first_int = first._ip
[364] Fix | Delete
last_int = last._ip
[365] Fix | Delete
while first_int <= last_int:
[366] Fix | Delete
nbits = min(_count_righthand_zero_bits(first_int, ip_bits),
[367] Fix | Delete
_compat_bit_length(last_int - first_int + 1) - 1)
[368] Fix | Delete
net = ip((first_int, ip_bits - nbits))
[369] Fix | Delete
yield net
[370] Fix | Delete
first_int += 1 << nbits
[371] Fix | Delete
if first_int - 1 == ip._ALL_ONES:
[372] Fix | Delete
break
[373] Fix | Delete
[374] Fix | Delete
[375] Fix | Delete
def _collapse_addresses_internal(addresses):
[376] Fix | Delete
"""Loops through the addresses, collapsing concurrent netblocks.
[377] Fix | Delete
[378] Fix | Delete
Example:
[379] Fix | Delete
[380] Fix | Delete
ip1 = IPv4Network('192.0.2.0/26')
[381] Fix | Delete
ip2 = IPv4Network('192.0.2.64/26')
[382] Fix | Delete
ip3 = IPv4Network('192.0.2.128/26')
[383] Fix | Delete
ip4 = IPv4Network('192.0.2.192/26')
[384] Fix | Delete
[385] Fix | Delete
_collapse_addresses_internal([ip1, ip2, ip3, ip4]) ->
[386] Fix | Delete
[IPv4Network('192.0.2.0/24')]
[387] Fix | Delete
[388] Fix | Delete
This shouldn't be called directly; it is called via
[389] Fix | Delete
collapse_addresses([]).
[390] Fix | Delete
[391] Fix | Delete
Args:
[392] Fix | Delete
addresses: A list of IPv4Network's or IPv6Network's
[393] Fix | Delete
[394] Fix | Delete
Returns:
[395] Fix | Delete
A list of IPv4Network's or IPv6Network's depending on what we were
[396] Fix | Delete
passed.
[397] Fix | Delete
[398] Fix | Delete
"""
[399] Fix | Delete
# First merge
[400] Fix | Delete
to_merge = list(addresses)
[401] Fix | Delete
subnets = {}
[402] Fix | Delete
while to_merge:
[403] Fix | Delete
net = to_merge.pop()
[404] Fix | Delete
supernet = net.supernet()
[405] Fix | Delete
existing = subnets.get(supernet)
[406] Fix | Delete
if existing is None:
[407] Fix | Delete
subnets[supernet] = net
[408] Fix | Delete
elif existing != net:
[409] Fix | Delete
# Merge consecutive subnets
[410] Fix | Delete
del subnets[supernet]
[411] Fix | Delete
to_merge.append(supernet)
[412] Fix | Delete
# Then iterate over resulting networks, skipping subsumed subnets
[413] Fix | Delete
last = None
[414] Fix | Delete
for net in sorted(subnets.values()):
[415] Fix | Delete
if last is not None:
[416] Fix | Delete
# Since they are sorted,
[417] Fix | Delete
# last.network_address <= net.network_address is a given.
[418] Fix | Delete
if last.broadcast_address >= net.broadcast_address:
[419] Fix | Delete
continue
[420] Fix | Delete
yield net
[421] Fix | Delete
last = net
[422] Fix | Delete
[423] Fix | Delete
[424] Fix | Delete
def collapse_addresses(addresses):
[425] Fix | Delete
"""Collapse a list of IP objects.
[426] Fix | Delete
[427] Fix | Delete
Example:
[428] Fix | Delete
collapse_addresses([IPv4Network('192.0.2.0/25'),
[429] Fix | Delete
IPv4Network('192.0.2.128/25')]) ->
[430] Fix | Delete
[IPv4Network('192.0.2.0/24')]
[431] Fix | Delete
[432] Fix | Delete
Args:
[433] Fix | Delete
addresses: An iterator of IPv4Network or IPv6Network objects.
[434] Fix | Delete
[435] Fix | Delete
Returns:
[436] Fix | Delete
An iterator of the collapsed IPv(4|6)Network objects.
[437] Fix | Delete
[438] Fix | Delete
Raises:
[439] Fix | Delete
TypeError: If passed a list of mixed version objects.
[440] Fix | Delete
[441] Fix | Delete
"""
[442] Fix | Delete
addrs = []
[443] Fix | Delete
ips = []
[444] Fix | Delete
nets = []
[445] Fix | Delete
[446] Fix | Delete
# split IP addresses and networks
[447] Fix | Delete
for ip in addresses:
[448] Fix | Delete
if isinstance(ip, _BaseAddress):
[449] Fix | Delete
if ips and ips[-1]._version != ip._version:
[450] Fix | Delete
raise TypeError("%s and %s are not of the same version" % (
[451] Fix | Delete
ip, ips[-1]))
[452] Fix | Delete
ips.append(ip)
[453] Fix | Delete
elif ip._prefixlen == ip._max_prefixlen:
[454] Fix | Delete
if ips and ips[-1]._version != ip._version:
[455] Fix | Delete
raise TypeError("%s and %s are not of the same version" % (
[456] Fix | Delete
ip, ips[-1]))
[457] Fix | Delete
try:
[458] Fix | Delete
ips.append(ip.ip)
[459] Fix | Delete
except AttributeError:
[460] Fix | Delete
ips.append(ip.network_address)
[461] Fix | Delete
else:
[462] Fix | Delete
if nets and nets[-1]._version != ip._version:
[463] Fix | Delete
raise TypeError("%s and %s are not of the same version" % (
[464] Fix | Delete
ip, nets[-1]))
[465] Fix | Delete
nets.append(ip)
[466] Fix | Delete
[467] Fix | Delete
# sort and dedup
[468] Fix | Delete
ips = sorted(set(ips))
[469] Fix | Delete
[470] Fix | Delete
# find consecutive address ranges in the sorted sequence and summarize them
[471] Fix | Delete
if ips:
[472] Fix | Delete
for first, last in _find_address_range(ips):
[473] Fix | Delete
addrs.extend(summarize_address_range(first, last))
[474] Fix | Delete
[475] Fix | Delete
return _collapse_addresses_internal(addrs + nets)
[476] Fix | Delete
[477] Fix | Delete
[478] Fix | Delete
def get_mixed_type_key(obj):
[479] Fix | Delete
"""Return a key suitable for sorting between networks and addresses.
[480] Fix | Delete
[481] Fix | Delete
Address and Network objects are not sortable by default; they're
[482] Fix | Delete
fundamentally different so the expression
[483] Fix | Delete
[484] Fix | Delete
IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24')
[485] Fix | Delete
[486] Fix | Delete
doesn't make any sense. There are some times however, where you may wish
[487] Fix | Delete
to have ipaddress sort these for you anyway. If you need to do this, you
[488] Fix | Delete
can use this function as the key= argument to sorted().
[489] Fix | Delete
[490] Fix | Delete
Args:
[491] Fix | Delete
obj: either a Network or Address object.
[492] Fix | Delete
Returns:
[493] Fix | Delete
appropriate key.
[494] Fix | Delete
[495] Fix | Delete
"""
[496] Fix | Delete
if isinstance(obj, _BaseNetwork):
[497] Fix | Delete
return obj._get_networks_key()
[498] Fix | Delete
elif isinstance(obj, _BaseAddress):
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function