mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-28577: Special case added to IP v4 and v6 hosts for /32 and /128 networks (GH-18757)
The `.hosts()` method now returns the single address present in a /32 or /128 network.
This commit is contained in:
parent
9229eeee10
commit
8e9c47a947
5 changed files with 25 additions and 5 deletions
|
|
@ -1509,6 +1509,8 @@ class IPv4Network(_BaseV4, _BaseNetwork):
|
|||
|
||||
if self._prefixlen == (self._max_prefixlen - 1):
|
||||
self.hosts = self.__iter__
|
||||
elif self._prefixlen == (self._max_prefixlen):
|
||||
self.hosts = lambda: [IPv4Address(addr)]
|
||||
|
||||
@property
|
||||
@functools.lru_cache()
|
||||
|
|
@ -2212,6 +2214,8 @@ class IPv6Network(_BaseV6, _BaseNetwork):
|
|||
|
||||
if self._prefixlen == (self._max_prefixlen - 1):
|
||||
self.hosts = self.__iter__
|
||||
elif self._prefixlen == self._max_prefixlen:
|
||||
self.hosts = lambda: [IPv6Address(addr)]
|
||||
|
||||
def hosts(self):
|
||||
"""Generate Iterator over usable hosts in a network.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue