Skip to content

Commit 742192a

Browse files
committed
Issue #21386: Implement missing IPv4Address.is_global property
It was documented since 07a5610bae9d. Initial patch by Roger Luethi.
1 parent fa089b9 commit 742192a

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Lib/ipaddress.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,11 @@ def is_private(self):
13111311
"""
13121312
return any(self in net for net in self._constants._private_networks)
13131313

1314+
@property
1315+
@functools.lru_cache()
1316+
def is_global(self):
1317+
return self not in self._constants._public_network and not self.is_private
1318+
13141319
@property
13151320
def is_multicast(self):
13161321
"""Test if the address is reserved for multicast use.
@@ -1557,6 +1562,8 @@ class _IPv4Constants:
15571562

15581563
_multicast_network = IPv4Network('224.0.0.0/4')
15591564

1565+
_public_network = IPv4Network('100.64.0.0/10')
1566+
15601567
_private_networks = [
15611568
IPv4Network('0.0.0.0/8'),
15621569
IPv4Network('10.0.0.0/8'),

Lib/test/test_ipaddress.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,9 @@ def testReservedIpv4(self):
16261626
self.assertEqual(False,
16271627
ipaddress.ip_address('169.255.100.200').is_link_local)
16281628

1629+
self.assertTrue(ipaddress.ip_address('192.0.7.1').is_global)
1630+
self.assertFalse(ipaddress.ip_address('203.0.113.1').is_global)
1631+
16291632
self.assertEqual(True,
16301633
ipaddress.ip_address('127.100.200.254').is_loopback)
16311634
self.assertEqual(True, ipaddress.ip_address('127.42.0.0').is_loopback)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ Core and Builtins
139139
Library
140140
-------
141141

142+
- Issue #21386: Implement missing IPv4Address.is_global property. It was
143+
documented since 07a5610bae9d. Initial patch by Roger Luethi.
144+
142145
- Issue #20900: distutils register command now decodes HTTP responses
143146
correctly. Initial patch by ingrid.
144147

0 commit comments

Comments
 (0)