From c81d0938b79f733c76010ac5b056eba01d5ee6d0 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Fri, 15 Sep 2023 12:30:33 -0700 Subject: [PATCH 1/9] Add ipv6_mapped property to IPV4Address --- Doc/library/ipaddress.rst | 7 +++++++ Doc/whatsnew/3.13.rst | 6 ++++++ Lib/ipaddress.py | 10 ++++++++++ Lib/test/test_ipaddress.py | 8 ++++++++ .../2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst | 1 + 5 files changed, 32 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst index 9c2dff55703273..27e455dd606f86 100644 --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -219,6 +219,13 @@ write code that handles both IP versions correctly. Address objects are ``True`` if the address is reserved for link-local usage. See :RFC:`3927`. + .. attribute:: ipv6_mapped + + ``IPV6Address`` object representing the IPv4 Mapped IPv6 Address. See :RFC:`4291`. + + .. versionadded:: 3.13 + + .. _iana-ipv4-special-registry: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml .. _iana-ipv6-special-registry: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index c18e15e0448f05..99805f4b53ec79 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -151,6 +151,12 @@ and only logged in :ref:`Python Development Mode ` or on :ref:`Python built on debug mode `. (Contributed by Victor Stinner in :gh:`62948`.) +ipaddress +--------- + +* Add a `ipv6_mapped` property to :class:`ipaddress.IPV4Address` objects. + (Contributed by Charles Machalow in :gh:`109466`.) + opcode ------ diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index f5aba434fd4253..bc83ffb0eb728e 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1389,6 +1389,16 @@ def is_link_local(self): """ return self in self._constants._linklocal_network + @property + def ipv6_mapped(self): + """Return the IPv6 mapped address. + + Returns: + The IPv4 Mapped IPv6 Address per RFC 4291 + + """ + return IPv6Address(f'::ffff:{self}') + class IPv4Interface(IPv4Address): diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 6f204948c9fc48..d6cc4dd4fa4132 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -302,6 +302,14 @@ def test_pickle(self): def test_weakref(self): weakref.ref(self.factory('192.0.2.1')) + def test_ipv6_mapped(self): + self.assertEqual(ipaddress.IPv4Address('192.168.1.1').ipv6_mapped, + ipaddress.IPv6Address('::ffff:192.168.1.1')) + self.assertEqual(ipaddress.IPv4Address('192.168.1.1').ipv6_mapped, + ipaddress.IPv6Address('::ffff:c0a8:101')) + self.assertEqual(ipaddress.IPv4Address('192.168.1.1').ipv6_mapped.ipv4_mapped, + ipaddress.IPv4Address('192.168.1.1')) + class AddressTestCase_v6(BaseTestCase, CommonTestMixin_v6): factory = ipaddress.IPv6Address diff --git a/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst b/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst new file mode 100644 index 00000000000000..bab82cbb393518 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst @@ -0,0 +1 @@ +Add a `ipv6_mapped` property to :class:`ipaddress.IPV4Address` objects. From 6db895f6b3225bf9179111149cfba871ec176b23 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Fri, 15 Sep 2023 12:34:59 -0700 Subject: [PATCH 2/9] lint --- .../next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst b/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst index bab82cbb393518..416b9ce8c17f4d 100644 --- a/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst +++ b/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst @@ -1 +1 @@ -Add a `ipv6_mapped` property to :class:`ipaddress.IPV4Address` objects. +Add a ``ipv6_mapped`` property to :class:`ipaddress.IPV4Address` objects. From 9bc999d35132b1f3e1ba45d54b16659474394adf Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Fri, 15 Sep 2023 12:37:03 -0700 Subject: [PATCH 3/9] lint --- Doc/whatsnew/3.13.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 99805f4b53ec79..9ee0420c2508b6 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -154,7 +154,7 @@ built on debug mode `. ipaddress --------- -* Add a `ipv6_mapped` property to :class:`ipaddress.IPV4Address` objects. +* Add a ``ipv6_mapped`` property to :class:`ipaddress.IPV4Address` objects. (Contributed by Charles Machalow in :gh:`109466`.) opcode From b48b874b80cd28c453e22df91eaa4e89d7a90789 Mon Sep 17 00:00:00 2001 From: Charles Machalow Date: Fri, 15 Sep 2023 12:44:38 -0700 Subject: [PATCH 4/9] lint --- Doc/library/ipaddress.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- .../next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst index 27e455dd606f86..ab8b9736b4634b 100644 --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -221,7 +221,7 @@ write code that handles both IP versions correctly. Address objects are .. attribute:: ipv6_mapped - ``IPV6Address`` object representing the IPv4 Mapped IPv6 Address. See :RFC:`4291`. + :class:`IPv4Address` object representing the IPv4 Mapped IPv6 Address. See :RFC:`4291`. .. versionadded:: 3.13 diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 9ee0420c2508b6..c4c3de6e33633a 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -154,7 +154,7 @@ built on debug mode `. ipaddress --------- -* Add a ``ipv6_mapped`` property to :class:`ipaddress.IPV4Address` objects. +* Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property. (Contributed by Charles Machalow in :gh:`109466`.) opcode diff --git a/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst b/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst index 416b9ce8c17f4d..fa5b7f4cfe7bd7 100644 --- a/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst +++ b/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst @@ -1 +1 @@ -Add a ``ipv6_mapped`` property to :class:`ipaddress.IPV4Address` objects. +Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property. From 9fc30111b7c6e3e063a815596912e514e6cf52a9 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 5 Nov 2023 08:14:03 -0800 Subject: [PATCH 5/9] Docstring update for ipv6_mapped Co-authored-by: Hugo van Kemenade --- Lib/ipaddress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index bc83ffb0eb728e..ee013af743ba44 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1394,7 +1394,7 @@ def ipv6_mapped(self): """Return the IPv6 mapped address. Returns: - The IPv4 Mapped IPv6 Address per RFC 4291 + The IPv4-mapped IPv6 address per RFC 4291. """ return IPv6Address(f'::ffff:{self}') From f42dd168f048eca0d6afa7aa667bf0e9a2764b57 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 5 Nov 2023 08:14:21 -0800 Subject: [PATCH 6/9] Update Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst Co-authored-by: Hugo van Kemenade --- .../next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst b/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst index fa5b7f4cfe7bd7..e8e5be320ea805 100644 --- a/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst +++ b/Misc/NEWS.d/next/Library/2023-09-15-12-30-21.gh-issue-109466.6ah-aw.rst @@ -1 +1 @@ -Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property. +Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property, which retuns the IPv4-mapped IPv6 address. From d78bf5aba998aeef3fc1fcaa860d96b84b2b0cc2 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 5 Nov 2023 08:14:39 -0800 Subject: [PATCH 7/9] Docstring update. Co-authored-by: Hugo van Kemenade --- Lib/ipaddress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index ee013af743ba44..dc63a13dda1be7 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1391,7 +1391,7 @@ def is_link_local(self): @property def ipv6_mapped(self): - """Return the IPv6 mapped address. + """Return the IPv4-mapped IPv6 address. Returns: The IPv4-mapped IPv6 address per RFC 4291. From 52ce9e901b3fffc2232e5cf79c89ec597f7a9037 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 5 Nov 2023 08:14:53 -0800 Subject: [PATCH 8/9] Update Doc/whatsnew/3.13.rst Co-authored-by: Hugo van Kemenade --- Doc/whatsnew/3.13.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index c4c3de6e33633a..c3b8758b5cd91e 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -154,7 +154,7 @@ built on debug mode `. ipaddress --------- -* Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property. +* Add the :attr:`ipaddress.IPv4Address.ipv6_mapped` property, which returns the IPv4-mapped IPv6 address. (Contributed by Charles Machalow in :gh:`109466`.) opcode From 26c2e377706afb0c1e5f31dc9092c24e08981e68 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 5 Nov 2023 08:15:16 -0800 Subject: [PATCH 9/9] Update Doc/library/ipaddress.rst Co-authored-by: Hugo van Kemenade --- Doc/library/ipaddress.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst index ab8b9736b4634b..1de36b643c4dca 100644 --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -221,7 +221,7 @@ write code that handles both IP versions correctly. Address objects are .. attribute:: ipv6_mapped - :class:`IPv4Address` object representing the IPv4 Mapped IPv6 Address. See :RFC:`4291`. + :class:`IPv4Address` object representing the IPv4-mapped IPv6 address. See :RFC:`4291`. .. versionadded:: 3.13