File tree Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,13 @@ write code that handles both IP versions correctly. Address objects are
219219 ``True `` if the address is reserved for link-local usage. See
220220 :RFC: `3927 `.
221221
222+ .. attribute :: ipv6_mapped
223+
224+ :class: `IPv4Address ` object representing the IPv4-mapped IPv6 address. See :RFC: `4291 `.
225+
226+ .. versionadded :: 3.13
227+
228+
222229.. _iana-ipv4-special-registry : https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
223230.. _iana-ipv6-special-registry : https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
224231
Original file line number Diff line number Diff line change @@ -185,6 +185,12 @@ and only logged in :ref:`Python Development Mode <devmode>` or on :ref:`Python
185185built on debug mode <debug-build>`.
186186(Contributed by Victor Stinner in :gh: `62948 `.)
187187
188+ ipaddress
189+ ---------
190+
191+ * Add the :attr: `ipaddress.IPv4Address.ipv6_mapped ` property, which returns the IPv4-mapped IPv6 address.
192+ (Contributed by Charles Machalow in :gh: `109466 `.)
193+
188194opcode
189195------
190196
Original file line number Diff line number Diff line change @@ -1389,6 +1389,16 @@ def is_link_local(self):
13891389 """
13901390 return self in self ._constants ._linklocal_network
13911391
1392+ @property
1393+ def ipv6_mapped (self ):
1394+ """Return the IPv4-mapped IPv6 address.
1395+
1396+ Returns:
1397+ The IPv4-mapped IPv6 address per RFC 4291.
1398+
1399+ """
1400+ return IPv6Address (f'::ffff:{ self } ' )
1401+
13921402
13931403class IPv4Interface (IPv4Address ):
13941404
Original file line number Diff line number Diff line change @@ -303,6 +303,14 @@ def test_pickle(self):
303303 def test_weakref (self ):
304304 weakref .ref (self .factory ('192.0.2.1' ))
305305
306+ def test_ipv6_mapped (self ):
307+ self .assertEqual (ipaddress .IPv4Address ('192.168.1.1' ).ipv6_mapped ,
308+ ipaddress .IPv6Address ('::ffff:192.168.1.1' ))
309+ self .assertEqual (ipaddress .IPv4Address ('192.168.1.1' ).ipv6_mapped ,
310+ ipaddress .IPv6Address ('::ffff:c0a8:101' ))
311+ self .assertEqual (ipaddress .IPv4Address ('192.168.1.1' ).ipv6_mapped .ipv4_mapped ,
312+ ipaddress .IPv4Address ('192.168.1.1' ))
313+
306314
307315class AddressTestCase_v6 (BaseTestCase , CommonTestMixin_v6 ):
308316 factory = ipaddress .IPv6Address
Original file line number Diff line number Diff line change 1+ Add the :attr: `ipaddress.IPv4Address.ipv6_mapped ` property, which retuns the IPv4-mapped IPv6 address.
You can’t perform that action at this time.
0 commit comments