FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-117566: fix IPv6Address.is_loopback for IPv4-mapped loopbacks by paravoid · Pull Request #117567 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 4 additions & 1 deletion Lib/ipaddress.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,9 @@ def is_loopback(self):
RFC 2373 2.5.3.

"""
ipv4_mapped = self.ipv4_mapped
if ipv4_mapped is not None:
return ipv4_mapped.is_loopback
return self._ip == 1

@property
Expand Down Expand Up @@ -2258,7 +2261,7 @@ def is_unspecified(self):

@property
def is_loopback(self):
return self._ip == 1 and self.network.is_loopback
return super().is_loopback and self.network.is_loopback


class IPv6Network(_BaseV6, _BaseNetwork):
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_ipaddress.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2446,6 +2446,22 @@ def testIpv4MappedPrivateCheck(self):
self.assertEqual(
False, ipaddress.ip_address('::ffff:172.32.0.0').is_private)

def testIpv4MappedLoopbackCheck(self):
# test networks
self.assertEqual(True, ipaddress.ip_network(
'::ffff:127.100.200.254/128').is_loopback)
self.assertEqual(True, ipaddress.ip_network(
'::ffff:127.42.0.0/112').is_loopback)
self.assertEqual(False, ipaddress.ip_network(
'::ffff:128.0.0.0').is_loopback)
# test addresses
self.assertEqual(True, ipaddress.ip_address(
'::ffff:127.100.200.254').is_loopback)
self.assertEqual(True, ipaddress.ip_address(
'::ffff:127.42.0.0').is_loopback)
self.assertEqual(False, ipaddress.ip_address(
'::ffff:128.0.0.0').is_loopback)

def testAddrExclude(self):
addr1 = ipaddress.ip_network('10.1.1.0/24')
addr2 = ipaddress.ip_network('10.1.1.0/26')
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:meth:`ipaddress.IPv6Address.is_loopback` will now return ``True`` for
IPv4-mapped loopback addresses, i.e. addresses in the
``::ffff:127.0.0.0/104`` address space.

Back | FazBrowse Home | New Git URL