[Python-checkins] cpython: #17400: correct handling of 100.64.0.0/10, fixing the docs and updating NEWS

peter.moody python-checkins at python.org
Thu Oct 24 18:47:31 CEST 2013


http://hg.python.org/cpython/rev/b9623fa5a0dd
changeset:   86598:b9623fa5a0dd
user:        Peter Moody <python at hda3.com>
date:        Thu Oct 24 09:47:10 2013 -0700
summary:
  #17400: correct handling of 100.64.0.0/10, fixing the docs and updating NEWS

files:
  Doc/library/ipaddress.rst  |   6 +++++
  Lib/ipaddress.py           |  27 ++++++++++++++-----------
  Lib/test/test_ipaddress.py |   4 ++-
  Misc/NEWS                  |   3 ++
  4 files changed, 27 insertions(+), 13 deletions(-)


diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst
--- a/Doc/library/ipaddress.rst
+++ b/Doc/library/ipaddress.rst
@@ -158,6 +158,12 @@
       ``True`` if the address is reserved for multicast use.  See
       :RFC:`3171` (for IPv4) or :RFC:`2373` (for IPv6).
 
+   .. attribute:: is_private
+
+      ``True`` if the address is allocated for private networks.  See
+      iana-ipv4-special-registry (for IPv4) or iana-ipv6-special-registry
+      (for IPv6).
+
    .. attribute:: is_global
 
       ``True`` if the address is allocated for public networks.  See
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -1244,7 +1244,6 @@
         """
         return (self in IPv4Network('0.0.0.0/8') or
                 self in IPv4Network('10.0.0.0/8') or
-                self in IPv4Network('100.64.0.0/10') or
                 self in IPv4Network('127.0.0.0/8') or
                 self in IPv4Network('169.254.0.0/16') or
                 self in IPv4Network('172.16.0.0/12') or
@@ -1258,17 +1257,6 @@
                 self in IPv4Network('240.0.0.0/4') or
                 self in IPv4Network('255.255.255.255/32'))
 
-    @property
-    def is_global(self):
-        """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 self in IPv4Network('100.64.0.0/10') or not self.is_private
-
 
     @property
     def is_multicast(self):
@@ -1501,6 +1489,21 @@
         if self._prefixlen == (self._max_prefixlen - 1):
             self.hosts = self.__iter__
 
+    @property
+    @functools.lru_cache()
+    def is_global(self):
+        """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.network_address in IPv4Network('100.64.0.0/10') and
+                    self.broadcast_address in IPv4Network('100.64.0.0/10')) and
+                not self.is_private)
+
+
 
 class _BaseV6:
 
diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py
--- a/Lib/test/test_ipaddress.py
+++ b/Lib/test/test_ipaddress.py
@@ -1319,8 +1319,10 @@
         self.assertEqual(True, ipaddress.ip_network(
                 '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_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,
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,9 @@
 Library
 -------
 
+- Issue #17400: New 'is_global' attribute for ipaddress to tell if an address
+  is allocated by IANA for global or private networks.
+
 - Issue #19350: Increasing the test coverage of macurl2path. Patch by Colin
   Williams.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list