]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #21386: Implement missing IPv4Address.is_global property
authorBerker Peksag <berker.peksag@gmail.com>
Sat, 11 Jun 2016 19:11:47 +0000 (22:11 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Sat, 11 Jun 2016 19:11:47 +0000 (22:11 +0300)
It was documented since 07a5610bae9d.

Initial patch by Roger Luethi.

Lib/ipaddress.py
Lib/test/test_ipaddress.py
Misc/NEWS

index ca3031abb41faa0f158dc001efd4d080f5b34a2c..1f900583826a80088ba9f72686b0cbdfac574208 100644 (file)
@@ -1311,6 +1311,11 @@ class IPv4Address(_BaseV4, _BaseAddress):
         """
         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 @@ class _IPv4Constants:
 
     _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'),
index 3edea08de4bbd00d15e1bba5411cf7ea059965e4..be62fadf0d9140c7bebed745fe7e5f4635a720cd 100644 (file)
@@ -1626,6 +1626,9 @@ class IpaddrUnitTest(unittest.TestCase):
         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)
index f59ed1ec8cae51a1d24acb5d959bc8c5fb79d147..cc5ba7de83be4398faa9736a65433cb8b21bef6a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -139,6 +139,9 @@ Core and Builtins
 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.