]> granicus.if.org Git - python/commitdiff
#17400: fix documentation, add cache to is_global and correctly handle 100.64.0.0/10
authorPeter Moody <python@hda3.com>
Tue, 22 Oct 2013 19:36:21 +0000 (12:36 -0700)
committerPeter Moody <python@hda3.com>
Tue, 22 Oct 2013 19:36:21 +0000 (12:36 -0700)
Doc/library/ipaddress.rst
Lib/ipaddress.py
Lib/test/test_ipaddress.py

index 7336204d6d381b480aa8f5b006303c223baede25..af1b3b8d1be4caed8a739215807908cc56f1dbeb 100644 (file)
@@ -160,7 +160,7 @@ write code that handles both IP versions correctly.
 
    .. 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
       (for IPv6).
 
index 53423e2ad0687df89b2d6d050d7ed34e3e993d0c..79361920b5e1cb647eb6bc06497a3a85f57e912e 100644 (file)
@@ -984,7 +984,7 @@ class _BaseNetwork(_IPAddressBase):
 
     @property
     def is_global(self):
-        """Test if this address is allocated for private networks.
+        """Test if this address is allocated for public networks.
 
         Returns:
             A boolean, True if the address is not reserved per
@@ -1233,6 +1233,7 @@ class IPv4Address(_BaseV4, _BaseAddress):
         return self in reserved_network
 
     @property
+    @functools.lru_cache()
     def is_private(self):
         """Test if this address is allocated for private networks.
 
@@ -1259,14 +1260,14 @@ class IPv4Address(_BaseV4, _BaseAddress):
 
     @property
     def is_global(self):
-        """Test if this address is allocated for private networks.
+        """Test if this address is allocated for public networks.
 
         Returns:
             A boolean, True if the address is not reserved per
             iana-ipv4-special-registry.
 
         """
-        return not self.is_private
+        return self in IPv4Network('100.64.0.0/10') or not self.is_private
 
 
     @property
@@ -1856,6 +1857,7 @@ class IPv6Address(_BaseV6, _BaseAddress):
         return self in sitelocal_network
 
     @property
+    @functools.lru_cache()
     def is_private(self):
         """Test if this address is allocated for private networks.
 
index c2a2009ac33772744c3f618ca4b0ec1238e4c9b8..25f190c3dc7b3d870bf4d524bcae67a22fb05747 100644 (file)
@@ -1320,6 +1320,7 @@ class IpaddrUnitTest(unittest.TestCase):
                 '127.42.0.0/16').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(False, ipaddress.ip_network('100.64.0.0/10').is_global)
         self.assertEqual(True,
                          ipaddress.ip_network('192.0.2.128/25').is_private)
         self.assertEqual(True,