@@ -1790,12 +1790,11 @@ def _split_scope_id(ip_str):
1790
1790
"""Helper function to parse IPv6 string address with scope id.
1791
1791
1792
1792
See RFC 4007 for details.
1793
-
1794
1793
Arg:
1795
1794
ip_str: A string, the IPv6 address.
1796
1795
1797
1796
Returns:
1798
- [ addr, scope_id] tuple.
1797
+ ( addr, scope_id) tuple.
1799
1798
"""
1800
1799
if '%' not in ip_str :
1801
1800
return ip_str , None
@@ -1820,7 +1819,7 @@ class IPv6Address(_BaseV6, _BaseAddress):
1820
1819
1821
1820
"""Represent and manipulate single IPv6 Addresses."""
1822
1821
1823
- __slots__ = ('_ip' , 'scope_id ' , '__weakref__' )
1822
+ __slots__ = ('_ip' , '_scope_id ' , '__weakref__' )
1824
1823
1825
1824
def __init__ (self , address ):
1826
1825
"""Instantiate a new IPv6 address object.
@@ -1839,7 +1838,7 @@ def __init__(self, address):
1839
1838
AddressValueError: If address isn't a valid IPv6 address.
1840
1839
1841
1840
"""
1842
- self .scope_id = None
1841
+ self ._scope_id = None
1843
1842
1844
1843
# Efficient constructor from integer.
1845
1844
if isinstance (address , int ):
@@ -1858,14 +1857,23 @@ def __init__(self, address):
1858
1857
addr_str = str (address )
1859
1858
if '/' in addr_str :
1860
1859
raise AddressValueError ("Unexpected '/' in %r" % address )
1861
- addr_str , self .scope_id = self ._split_scope_id (addr_str )
1860
+ addr_str , self ._scope_id = self ._split_scope_id (addr_str )
1862
1861
1863
1862
self ._ip = self ._ip_int_from_string (addr_str )
1864
1863
1865
1864
def __str__ (self ):
1866
- ip_str = self . _string_from_ip_int ( self . _ip )
1865
+ ip_str = super (). __str__ ( )
1867
1866
return ip_str if self .scope_id is None else ip_str + '%' + self .scope_id
1868
1867
1868
+ @property
1869
+ def scope_id (self ):
1870
+ """Identifier of a particular zone of the address's scope.
1871
+
1872
+ Returns:
1873
+ A string, identifying the zone of the address if specified, else None.
1874
+ """
1875
+ return self ._scope_id
1876
+
1869
1877
@property
1870
1878
def packed (self ):
1871
1879
"""The binary representation of this address."""
0 commit comments