File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1883,14 +1883,18 @@ def _explode_shorthand_ip_string(self):
18831883 elif isinstance (self , IPv6Interface ):
18841884 ip_str = str (self .ip )
18851885 else :
1886- ip_str = str (self )
1886+ ip_str = self . _string_from_ip_int (self . _ip )
18871887
18881888 ip_int = self ._ip_int_from_string (ip_str )
18891889 hex_str = '%032x' % ip_int
1890- parts = [hex_str [x :x + 4 ] for x in range (0 , 32 , 4 )]
1891- if isinstance (self , (_BaseNetwork , IPv6Interface )):
1892- return '%s/%d' % (':' .join (parts ), self ._prefixlen )
1893- return ':' .join (parts )
1890+ exploded = ':' .join ([hex_str [x :x + 4 ] for x in range (0 , 32 , 4 )])
1891+ if isinstance (self , _BaseNetwork ):
1892+ return '%s/%d' % (exploded , self ._prefixlen )
1893+ if self ._scope_id :
1894+ exploded = '%s%%%s' % (exploded , self ._scope_id )
1895+ if isinstance (self , IPv6Interface ):
1896+ return '%s/%d' % (exploded , self ._prefixlen )
1897+ return exploded
18941898
18951899 def _reverse_pointer (self ):
18961900 """Return the reverse DNS pointer name for the IPv6 address.
Original file line number Diff line number Diff line change @@ -2667,6 +2667,12 @@ def testExplodeShortHandIpStr(self):
26672667 addr1 .exploded )
26682668 self .assertEqual ('0000:0000:0000:0000:0000:0000:0000:0001/128' ,
26692669 ipaddress .IPv6Interface ('::1/128' ).exploded )
2670+ self .assertEqual ('fe80:0000:0000:0000:0000:0000:0000:0001%1' ,
2671+ ipaddress .IPv6Address ('fe80::1%1' ).exploded )
2672+ self .assertEqual ('fe80:0000:0000:0000:0000:0000:0000:0001%eth0' ,
2673+ ipaddress .IPv6Address ('fe80::1%eth0' ).exploded )
2674+ self .assertEqual ('fe80:0000:0000:0000:0000:0000:0000:0001%1/64' ,
2675+ ipaddress .IPv6Interface ('fe80::1%1/64' ).exploded )
26702676 # issue 77
26712677 self .assertEqual ('2001:0000:5ef5:79fd:0000:059d:a0e5:0ba1' ,
26722678 addr2 .exploded )
Original file line number Diff line number Diff line change 1+ The ``exploded `` attribute of :class: `ipaddress.IPv6Address ` and
2+ :class: `ipaddress.IPv6Interface ` now supports addresses with a scope ID
3+ (link-local addresses).
4+ Previously the former raised :exc: `~ipaddress.AddressValueError `
5+ and the latter omitted the scope ID.
You can’t perform that action at this time.
0 commit comments