#17400: fix documentation, add cache to is_global and correctly handl… · python/cpython@be9c1b1 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ write code that handles both IP versions correctly.
160 160
161 161 .. attribute:: is_global
162 162
163 - ``True`` if the address is allocated for private networks. See
163 + ``True`` if the address is allocated for public networks. See
164 164 iana-ipv4-special-registry (for IPv4) or iana-ipv6-special-registry
165 165 (for IPv6).
166 166
Original file line number Diff line number Diff line change
@@ -984,7 +984,7 @@ def is_private(self):
984 984
985 985 @property
986 986 def is_global(self):
987 -"""Test if this address is allocated for private networks.
987 +"""Test if this address is allocated for public networks.
988 988
989 989 Returns:
990 990 A boolean, True if the address is not reserved per
@@ -1233,6 +1233,7 @@ def is_reserved(self):
1233 1233 return self in reserved_network
1234 1234
1235 1235 @property
1236 +@functools.lru_cache()
1236 1237 def is_private(self):
1237 1238 """Test if this address is allocated for private networks.
1238 1239
@@ -1259,14 +1260,14 @@ def is_private(self):
1259 1260
1260 1261 @property
1261 1262 def is_global(self):
1262 -"""Test if this address is allocated for private networks.
1263 +"""Test if this address is allocated for public networks.
1263 1264
1264 1265 Returns:
1265 1266 A boolean, True if the address is not reserved per
1266 1267 iana-ipv4-special-registry.
1267 1268
1268 1269 """
1269 -return not self.is_private
1270 +return self in IPv4Network('100.64.0.0/10') or not self.is_private
1270 1271
1271 1272
1272 1273 @property
@@ -1856,6 +1857,7 @@ def is_site_local(self):
1856 1857 return self in sitelocal_network
1857 1858
1858 1859 @property
1860 +@functools.lru_cache()
1859 1861 def is_private(self):
1860 1862 """Test if this address is allocated for private networks.
1861 1863
Original file line number Diff line number Diff line change
@@ -1320,6 +1320,7 @@ def testReservedIpv4(self):
1320 1320 '127.42.0.0/16').is_loopback)
1321 1321 self.assertEqual(False, ipaddress.ip_network('128.0.0.0').is_loopback)
1322 1322 self.assertEqual(True, ipaddress.ip_network('100.64.0.0/10').is_private)
1323 +self.assertEqual(False, ipaddress.ip_network('100.64.0.0/10').is_global)
1323 1324 self.assertEqual(True,
1324 1325 ipaddress.ip_network('192.0.2.128/25').is_private)
1325 1326 self.assertEqual(True,