mirror of
https://github.com/python/cpython.git
synced 2025-10-04 22:20:46 +00:00
gh-82836: fix private network check (GH-97733)
Fixes private checks for network objects. The previous method would incorrectly return True for a private check in cases such as "0.0.0.0/0".
(cherry picked from commit ed391090cc
)
Co-authored-by: Pete Wicken <2273100+JamoBox@users.noreply.github.com>
This commit is contained in:
parent
d7c2e0a537
commit
8dafefcace
3 changed files with 50 additions and 4 deletions
|
@ -1077,15 +1077,16 @@ class _BaseNetwork(_IPAddressBase):
|
|||
|
||||
@property
|
||||
def is_private(self):
|
||||
"""Test if this address is allocated for private networks.
|
||||
"""Test if this network belongs to a private range.
|
||||
|
||||
Returns:
|
||||
A boolean, True if the address is reserved per
|
||||
A boolean, True if the network is reserved per
|
||||
iana-ipv4-special-registry or iana-ipv6-special-registry.
|
||||
|
||||
"""
|
||||
return (self.network_address.is_private and
|
||||
self.broadcast_address.is_private)
|
||||
return any(self.network_address in priv_network and
|
||||
self.broadcast_address in priv_network
|
||||
for priv_network in self._constants._private_networks)
|
||||
|
||||
@property
|
||||
def is_global(self):
|
||||
|
@ -1122,6 +1123,15 @@ class _BaseNetwork(_IPAddressBase):
|
|||
return (self.network_address.is_loopback and
|
||||
self.broadcast_address.is_loopback)
|
||||
|
||||
|
||||
class _BaseConstants:
|
||||
|
||||
_private_networks = []
|
||||
|
||||
|
||||
_BaseNetwork._constants = _BaseConstants
|
||||
|
||||
|
||||
class _BaseV4:
|
||||
|
||||
"""Base IPv4 object.
|
||||
|
@ -1561,6 +1571,7 @@ class _IPv4Constants:
|
|||
|
||||
|
||||
IPv4Address._constants = _IPv4Constants
|
||||
IPv4Network._constants = _IPv4Constants
|
||||
|
||||
|
||||
class _BaseV6:
|
||||
|
@ -2285,3 +2296,4 @@ class _IPv6Constants:
|
|||
|
||||
|
||||
IPv6Address._constants = _IPv6Constants
|
||||
IPv6Network._constants = _IPv6Constants
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue