mirror of https://github.com/python/cpython.git
#17400: fix documentation, add cache to is_global and correctly handle 100.64.0.0/10
This commit is contained in:
parent
a4df90ceb9
commit
be9c1b133b
|
@ -160,7 +160,7 @@ write code that handles both IP versions correctly.
|
||||||
|
|
||||||
.. attribute:: is_global
|
.. attribute:: is_global
|
||||||
|
|
||||||
``True`` if the address is allocated for private networks. See
|
``True`` if the address is allocated for public networks. See
|
||||||
iana-ipv4-special-registry (for IPv4) or iana-ipv6-special-registry
|
iana-ipv4-special-registry (for IPv4) or iana-ipv6-special-registry
|
||||||
(for IPv6).
|
(for IPv6).
|
||||||
|
|
||||||
|
|
|
@ -984,7 +984,7 @@ def is_private(self):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_global(self):
|
def is_global(self):
|
||||||
"""Test if this address is allocated for private networks.
|
"""Test if this address is allocated for public networks.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A boolean, True if the address is not reserved per
|
A boolean, True if the address is not reserved per
|
||||||
|
@ -1233,6 +1233,7 @@ def is_reserved(self):
|
||||||
return self in reserved_network
|
return self in reserved_network
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@functools.lru_cache()
|
||||||
def is_private(self):
|
def is_private(self):
|
||||||
"""Test if this address is allocated for private networks.
|
"""Test if this address is allocated for private networks.
|
||||||
|
|
||||||
|
@ -1259,14 +1260,14 @@ def is_private(self):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_global(self):
|
def is_global(self):
|
||||||
"""Test if this address is allocated for private networks.
|
"""Test if this address is allocated for public networks.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A boolean, True if the address is not reserved per
|
A boolean, True if the address is not reserved per
|
||||||
iana-ipv4-special-registry.
|
iana-ipv4-special-registry.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return not self.is_private
|
return self in IPv4Network('100.64.0.0/10') or not self.is_private
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -1856,6 +1857,7 @@ def is_site_local(self):
|
||||||
return self in sitelocal_network
|
return self in sitelocal_network
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@functools.lru_cache()
|
||||||
def is_private(self):
|
def is_private(self):
|
||||||
"""Test if this address is allocated for private networks.
|
"""Test if this address is allocated for private networks.
|
||||||
|
|
||||||
|
|
|
@ -1320,6 +1320,7 @@ def testReservedIpv4(self):
|
||||||
'127.42.0.0/16').is_loopback)
|
'127.42.0.0/16').is_loopback)
|
||||||
self.assertEqual(False, ipaddress.ip_network('128.0.0.0').is_loopback)
|
self.assertEqual(False, ipaddress.ip_network('128.0.0.0').is_loopback)
|
||||||
self.assertEqual(True, ipaddress.ip_network('100.64.0.0/10').is_private)
|
self.assertEqual(True, ipaddress.ip_network('100.64.0.0/10').is_private)
|
||||||
|
self.assertEqual(False, ipaddress.ip_network('100.64.0.0/10').is_global)
|
||||||
self.assertEqual(True,
|
self.assertEqual(True,
|
||||||
ipaddress.ip_network('192.0.2.128/25').is_private)
|
ipaddress.ip_network('192.0.2.128/25').is_private)
|
||||||
self.assertEqual(True,
|
self.assertEqual(True,
|
||||||
|
|
Loading…
Reference in New Issue