Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1870,14 +1870,18 @@ def _explode_shorthand_ip_string(self):
elif isinstance(self, IPv6Interface):
ip_str = str(self.ip)
else:
ip_str = str(self)
ip_str = self._string_from_ip_int(self._ip)

ip_int = self._ip_int_from_string(ip_str)
hex_str = '%032x' % ip_int
parts = [hex_str[x:x+4] for x in range(0, 32, 4)]
if isinstance(self, (_BaseNetwork, IPv6Interface)):
return '%s/%d' % (':'.join(parts), self._prefixlen)
return ':'.join(parts)
exploded = ':'.join([hex_str[x:x+4] for x in range(0, 32, 4)])
if isinstance(self, _BaseNetwork):
return '%s/%d' % (exploded, self._prefixlen)
if self._scope_id:
exploded = '%s%%%s' % (exploded, self._scope_id)
if isinstance(self, IPv6Interface):
return '%s/%d' % (exploded, self._prefixlen)
return exploded

def _reverse_pointer(self):
"""Return the reverse DNS pointer name for the IPv6 address.
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,12 @@ def testExplodeShortHandIpStr(self):
addr1.exploded)
self.assertEqual('0000:0000:0000:0000:0000:0000:0000:0001/128',
ipaddress.IPv6Interface('::1/128').exploded)
self.assertEqual('fe80:0000:0000:0000:0000:0000:0000:0001%1',
ipaddress.IPv6Address('fe80::1%1').exploded)
self.assertEqual('fe80:0000:0000:0000:0000:0000:0000:0001%eth0',
ipaddress.IPv6Address('fe80::1%eth0').exploded)
self.assertEqual('fe80:0000:0000:0000:0000:0000:0000:0001%1/64',
ipaddress.IPv6Interface('fe80::1%1/64').exploded)
# issue 77
self.assertEqual('2001:0000:5ef5:79fd:0000:059d:a0e5:0ba1',
addr2.exploded)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The ``exploded`` attribute of :class:`ipaddress.IPv6Address` and
:class:`ipaddress.IPv6Interface` now supports addresses with a scope ID
(link-local addresses).
Previously the former raised :exc:`~ipaddress.AddressValueError`
and the latter omitted the scope ID.
Loading