changeset: 101879:d65191861599 branch: 3.5 parent: 101877:222c1d461aa8 user: Berker Peksag date: Sat Jun 11 22:11:47 2016 +0300 files: Lib/ipaddress.py Lib/test/test_ipaddress.py Misc/NEWS description: Issue #21386: Implement missing IPv4Address.is_global property It was documented since 07a5610bae9d. Initial patch by Roger Luethi. diff -r 222c1d461aa8 -r d65191861599 Lib/ipaddress.py --- a/Lib/ipaddress.py Sat Jun 11 15:02:54 2016 -0400 +++ b/Lib/ipaddress.py Sat Jun 11 22:11:47 2016 +0300 @@ -1312,6 +1312,11 @@ return any(self in net for net in self._constants._private_networks) @property + @functools.lru_cache() + def is_global(self): + return self not in self._constants._public_network and not self.is_private + + @property def is_multicast(self): """Test if the address is reserved for multicast use. @@ -1557,6 +1562,8 @@ _multicast_network = IPv4Network('224.0.0.0/4') + _public_network = IPv4Network('100.64.0.0/10') + _private_networks = [ IPv4Network('0.0.0.0/8'), IPv4Network('10.0.0.0/8'), diff -r 222c1d461aa8 -r d65191861599 Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py Sat Jun 11 15:02:54 2016 -0400 +++ b/Lib/test/test_ipaddress.py Sat Jun 11 22:11:47 2016 +0300 @@ -1626,6 +1626,9 @@ self.assertEqual(False, ipaddress.ip_address('169.255.100.200').is_link_local) + self.assertTrue(ipaddress.ip_address('192.0.7.1').is_global) + self.assertFalse(ipaddress.ip_address('203.0.113.1').is_global) + self.assertEqual(True, ipaddress.ip_address('127.100.200.254').is_loopback) self.assertEqual(True, ipaddress.ip_address('127.42.0.0').is_loopback) diff -r 222c1d461aa8 -r d65191861599 Misc/NEWS --- a/Misc/NEWS Sat Jun 11 15:02:54 2016 -0400 +++ b/Misc/NEWS Sat Jun 11 22:11:47 2016 +0300 @@ -139,6 +139,9 @@ Library ------- +- Issue #21386: Implement missing IPv4Address.is_global property. It was + documented since 07a5610bae9d. Initial patch by Roger Luethi. + - Issue #20900: distutils register command now decodes HTTP responses correctly. Initial patch by ingrid.