diff options
author | Bénédikt Tran <10796600+picnixz@users.noreply.github.com> | 2024-09-02 15:05:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-02 15:05:05 (GMT) |
commit | 77a2fb4bf1a1b160d6ce105508288fc77f636943 (patch) | |
tree | 82095c06f8093d197381bec2769c05da730bb572 /Lib/ipaddress.py | |
parent | f95fc4de115ae03d7aa6dece678240df085cb4f6 (diff) | |
download | cpython-77a2fb4bf1a1b160d6ce105508288fc77f636943.zip cpython-77a2fb4bf1a1b160d6ce105508288fc77f636943.tar.gz cpython-77a2fb4bf1a1b160d6ce105508288fc77f636943.tar.bz2 |
gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped addresses (GH-123419)
Fix functionality that was broken with better textual representation for IPv4-mapped addresses (gh-87799)
Diffstat (limited to 'Lib/ipaddress.py')
-rw-r--r-- | Lib/ipaddress.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 9cef275..c165505 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1970,12 +1970,21 @@ class IPv6Address(_BaseV6, _BaseAddress): def _explode_shorthand_ip_string(self): ipv4_mapped = self.ipv4_mapped if ipv4_mapped is None: - long_form = super()._explode_shorthand_ip_string() - else: - prefix_len = 30 - raw_exploded_str = super()._explode_shorthand_ip_string() - long_form = "%s%s" % (raw_exploded_str[:prefix_len], str(ipv4_mapped)) - return long_form + return super()._explode_shorthand_ip_string() + prefix_len = 30 + raw_exploded_str = super()._explode_shorthand_ip_string() + return f"{raw_exploded_str[:prefix_len]}{ipv4_mapped!s}" + + def _reverse_pointer(self): + ipv4_mapped = self.ipv4_mapped + if ipv4_mapped is None: + return super()._reverse_pointer() + prefix_len = 30 + raw_exploded_str = super()._explode_shorthand_ip_string()[:prefix_len] + # ipv4 encoded using hexadecimal nibbles instead of decimals + ipv4_int = ipv4_mapped._ip + reverse_chars = f"{raw_exploded_str}{ipv4_int:008x}"[::-1].replace(':', '') + return '.'.join(reverse_chars) + '.ip6.arpa' def _ipv4_mapped_ipv6_to_str(self): """Return convenient text representation of IPv4-mapped IPv6 address |