File tree 3 files changed +13
-0
lines changed 3 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -1311,6 +1311,11 @@ def is_private(self):
1311
1311
"""
1312
1312
return any (self in net for net in self ._constants ._private_networks )
1313
1313
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
+
1314
1319
@property
1315
1320
def is_multicast (self ):
1316
1321
"""Test if the address is reserved for multicast use.
@@ -1557,6 +1562,8 @@ class _IPv4Constants:
1557
1562
1558
1563
_multicast_network = IPv4Network ('224.0.0.0/4' )
1559
1564
1565
+ _public_network = IPv4Network ('100.64.0.0/10' )
1566
+
1560
1567
_private_networks = [
1561
1568
IPv4Network ('0.0.0.0/8' ),
1562
1569
IPv4Network ('10.0.0.0/8' ),
Original file line number Diff line number Diff line change @@ -1626,6 +1626,9 @@ def testReservedIpv4(self):
1626
1626
self .assertEqual (False ,
1627
1627
ipaddress .ip_address ('169.255.100.200' ).is_link_local )
1628
1628
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
+
1629
1632
self .assertEqual (True ,
1630
1633
ipaddress .ip_address ('127.100.200.254' ).is_loopback )
1631
1634
self .assertEqual (True , ipaddress .ip_address ('127.42.0.0' ).is_loopback )
Original file line number Diff line number Diff line change @@ -139,6 +139,9 @@ Core and Builtins
139
139
Library
140
140
-------
141
141
142
+ - Issue #21386: Implement missing IPv4Address.is_global property. It was
143
+ documented since 07a5610bae9d. Initial patch by Roger Luethi.
144
+
142
145
- Issue #20900: distutils register command now decodes HTTP responses
143
146
correctly. Initial patch by ingrid.
144
147
You can’t perform that action at this time.
0 commit comments