10000 Actually fix the shared address space too · jstasiak/cpython@d3ee80d · GitHub
[go: up one dir, main page]

Skip to content

Commit d3ee80d

Browse files
committed
Actually fix the shared address space too
1 parent f031f6e commit d3ee80d

File tree

4 files changed

+29
-37
lines changed

4 files changed

+29
-37
lines changed

Doc/library/ipaddress.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,15 @@ write code that handles both IP versions correctly. Address objects are
180180

181181
``True`` if the address is defined as not globally reachable by
182182
iana-ipv4-special-registry_ (for IPv4) or iana-ipv6-special-registry_
183-
(for IPv6) with the following exceptions:
183+
(for IPv6) with the following exception:
184184

185-
* ``is_private`` is ``False`` for the shared address space (``100.64.0.0/10``)
186-
* For IPv4-mapped IPv6-addresses the ``is_private`` value is determined by the
187-
semantics of the underlying IPv4 addresses and the following condition holds
188-
(see :attr:`IPv6Address.ipv4_mapped`)::
185+
For IPv4-mapped IPv6-addresses the ``is_private`` value is determined by the
186+
semantics of the underlying IPv4 addresses and the following condition holds
187+
(see :attr:`IPv6Address.ipv4_mapped`)::
189188

190-
address.is_private == address.ipv4_mapped.is_private
189+
address.is_private == address.ipv4_mapped.is_private
191190

192-
``is_private`` has value opposite to :attr:`is_global`, except for the shared address space
193-
(``100.64.0.0/10`` range) where they are both ``False``.
191+
``is_private`` has value opposite to :attr:`is_global`.
194192

195193
.. versionchanged:: 3.13
196194

@@ -203,6 +201,8 @@ write code that handles both IP versions correctly. Address objects are
203201
* There are exceptions within ``2001::/23`` (otherwise considered private): ``2001:1::1/128``,
204202
``2001:1::2/128``, ``2001:3::/32``, ``2001:4:112::/48``, ``2001:20::/28``, ``2001:30::/28``.
205203
The exceptions are not considered private.
204+
* The shared address space (``100.64.0.0/10``) is not treated in any special way anymore,
205+
previously it was considered both not private and not global. It is considered private now.
206206

207207
.. attribute:: is_global
208208

@@ -216,8 +216,7 @@ write code that handles both IP versions correctly. Address objects are
216216

217217
address.is_global == address.ipv4_mapped.is_global
218218

219-
``is_global`` has value opposite to :attr:`is_private`, except for the shared address space
220-
(``100.64.0.0/10`` range) where they are both ``False``.
219+
``is_global`` has value opposite to :attr:`is_private`.
221220

222221
.. versionadded:: 3.4
223222

Lib/ipaddress.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,17 +1339,15 @@ def is_reserved(self):
13391339
def is_private(self):
13401340
"""``True`` if the address is defined as not globally reachable by
13411341
iana-ipv4-special-registry_ (for IPv4) or iana-ipv6-special-registry_
1342-
(for IPv6) with the following exceptions:
1342+
(for IPv6) with the following exception:
13431343
1344-
* ``is_private`` is ``False`` for ``100.64.0.0/10``
1345-
* For IPv4-mapped IPv6-addresses the ``is_private`` value is determined by the
1346-
semantics of the underlying IPv4 addresses and the following condition holds
1347-
(see :attr:`IPv6Address.ipv4_mapped`)::
1344+
For IPv4-mapped IPv6-addresses the ``is_private`` value is determined by the
1345+
semantics of the underlying IPv4 addresses and the following condition holds
1346+
(see :attr:`IPv6Address.ipv4_mapped`)::
13481347
1349-
address.is_private == address.ipv4_mapped.is_private
1348+
address.is_private == address.ipv4_mapped.is_private
13501349
1351-
``is_private`` has value opposite to :attr:`is_global`, except for the ``100.64.0.0/10``
1352-
IPv4 range where they are both ``False``.
1350+
``is_private`` has value opposite to :attr:`is_global`.
13531351
"""
13541352
return (
13551353
any(self in net for net in self._constants._private_networks)
@@ -1369,10 +1367,9 @@ def is_global(self):
13691367
13701368
address.is_global == address.ipv4_mapped.is_global
13711369
1372-
``is_global`` has value opposite to :attr:`is_private`, except for the ``100.64.0.0/10``
1373-
IPv4 range where they are both ``False``.
1370+
``is_global`` has value opposite to :attr:`is_private`.
13741371
"""
1375-
return self not in self._constants._public_network and not self.is_private
1372+
return not self.is_private
13761373

13771374
@property
13781375
def is_multicast(self):
@@ -1571,9 +1568,7 @@ def is_global(self):
15711568
iana-ipv4-special-registry.
15721569
15731570
"""
1574-
return (not (self.network_address in IPv4Network('100.64.0.0/10') and
1575-
self.broadcast_address in IPv4Network('100.64.0.0/10')) and
1576-
not self.is_private)
1571+
return not self.is_private
15771572

15781573

15791574
class _IPv4Constants:
@@ -1583,13 +1578,12 @@ class _IPv4Constants:
15831578

15841579
_multicast_network = IPv4Network('224.0.0.0/4')
15851580

1586-
_public_network = IPv4Network('100.64.0.0/10')
1587-
15881581
# Not globally reachable address blocks listed on
15891582
# https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
15901583
_private_networks = [
15911584
IPv4Network('0.0.0.0/8'),
15921585
IPv4Network('10.0.0.0/8'),
1586+
IPv4Network('100.64.0.0/10'),
15931587
IPv4Network('127.0.0.0/8'),
15941588
IPv4Network('169.254.0.0/16'),
15951589
IPv4Network('172.16.0.0/12'),
@@ -2085,17 +2079,15 @@ def is_site_local(self):
20852079
def is_private(self):
20862080
"""``True`` if the address is defined as not globally reachable by
20872081
iana-ipv4-special-registry_ (for IPv4) or iana-ipv6-special-registry_
2088-
(for IPv6) with the following exceptions:
2082+
(for IPv6) with the following exception:
20892083
2090-
* ``is_private`` is ``False`` for ``100.64.0.0/10``
2091-
* For IPv4-mapped IPv6-addresses the ``is_private`` value is determined by the
2092-
semantics of the underlying IPv4 addresses and the following condition holds
2093-
(see :attr:`IPv6Address.ipv4_mapped`)::
2084+
For IPv4-mapped IPv6-addresses the ``is_private`` value is determined by the
2085+
semantics of the underlying IPv4 addresses and the following condition holds
2086+
(see :attr:`IPv6Address.ipv4_mapped`)::
20942087
2095-
address.is_private == address.ipv4_mapped.is_private
2088+
address.is_private == address.ipv4_mapped.is_private
20962089
2097-
``is_private`` has value opposite to :attr:`is_global`, except for the ``100.64.0.0/10``
2098-
IPv4 range where they are both ``False``.
2090+
``is_private`` has value opposite to :attr:`is_global`.
20992091
"""
21002092
ipv4_mapped = self.ipv4_mapped
21012093
if ipv4_mapped is not None:
@@ -2117,8 +2109,7 @@ def is_global(self):
21172109
21182110
address.is_global == address.ipv4_mapped.is_global
21192111
2120-
``is_global`` has value opposite to :attr:`is_private`, except for the ``100.64.0.0/10``
2121-
IPv4 range where they are both ``False``.
2112+
``is_global`` has value opposite to :attr:`is_private`.
21222113
"""
21232114
return not self.is_private
21242115

Lib/test/test_ipaddress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ def testReservedIpv4(self):
22632263
self.assertEqual(True, ipaddress.ip_network(
22642264
'127.42.0.0/16').is_loopback)
22652265
self.assertEqual(False, ipaddress.ip_network('128.0.0.0').is_loopback)
2266-
self.assertEqual(False,
2266+
self.assertEqual(True,
22672267
ipaddress.ip_network('100.64.0.0/10').is_private)
22682268
self.assertEqual(False, ipaddress.ip_network('100.64.0.0/10').is_global)
22692269

Misc/NEWS.d/next/Library/2024-03-14-01-38-44.gh-issue-113171.VFnObz.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ The new behavior:
1717
* There are exceptions within ``2001::/23`` (otherwise considered private): ``2001:1::1/128``,
1818
``2001:1::2/128``, ``2001:3::/32``, ``2001:4:112::/48``, ``2001:20::/28``, ``2001:30::/28``.
1919
The exceptions are not considered private.
20+
* The shared address space (``100.64.0.0/10``) is not treated in any special way anymore,
21+
previously it was considered both not private and not global. It is considered private now.

0 commit comments

Comments
 (0)
0