Added __len__ method to _BaseNetwork class in ipaddress module.

This enables a call such as random.choice(ipaddress.ip_network("192.169.0.0/16")).
This commit is contained in:
Marty 2020-02-01 23:15:39 -08:00
parent 78c7183f47
commit da7d29347c
1 changed files with 3 additions and 0 deletions

View File

@ -750,6 +750,9 @@ class _BaseNetwork(_IPAddressBase):
# address
return other._ip & self.netmask._ip == self.network_address._ip
def __len__(self):
return self.num_addresses
def overlaps(self, other):
"""Tell if self is partly contained in other."""
return self.network_address in other or (