diff options
author | opavlyuk <40970635+opavlyuk@users.noreply.github.com> | 2020-02-26 14:33:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-26 14:33:57 (GMT) |
commit | 21da76d1f1b527d62b2e9ef79dd9aa514d996341 (patch) | |
tree | 30f79bd48835216ed7d4e5275f5ccab93a8b688e /Doc/library/ipaddress.rst | |
parent | be7ead62db9a1db3e2cd997b0beffd4480e51f5c (diff) | |
download | cpython-21da76d1f1b527d62b2e9ef79dd9aa514d996341.zip cpython-21da76d1f1b527d62b2e9ef79dd9aa514d996341.tar.gz cpython-21da76d1f1b527d62b2e9ef79dd9aa514d996341.tar.bz2 |
bpo-34788: Add support for scoped IPv6 addresses (GH-13772)
Automerge-Triggered-By: @asvetlov
Diffstat (limited to 'Doc/library/ipaddress.rst')
-rw-r--r-- | Doc/library/ipaddress.rst | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst index 140401d..5938439 100644 --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -217,11 +217,20 @@ write code that handles both IP versions correctly. Address objects are :RFC:`4291` for details. For example, ``"0000:0000:0000:0000:0000:0abc:0007:0def"`` can be compressed to ``"::abc:7:def"``. + + Optionally, the string may also have a scope zone ID, expressed + with a suffix ``%scope_id``. If present, the scope ID must be non-empty, + and may not contain ``%``. + See :RFC:`4007` for details. + For example, ``fe80::1234%1`` might identify address ``fe80::1234`` on the first link of the node. 2. An integer that fits into 128 bits. 3. An integer packed into a :class:`bytes` object of length 16, big-endian. + >>> ipaddress.IPv6Address('2001:db8::1000') IPv6Address('2001:db8::1000') + >>> ipaddress.IPv6Address('ff02::5678%1') + IPv6Address('ff02::5678%1') .. attribute:: compressed @@ -268,6 +277,12 @@ write code that handles both IP versions correctly. Address objects are ``::FFFF/96``), this property will report the embedded IPv4 address. For any other address, this property will be ``None``. + .. attribute:: scope_id + + For scoped addresses as defined by :RFC:`4007`, this property identifies + the particular zone of the address's scope that the address belongs to, + as a string. When no scope zone is specified, this property will be ``None``. + .. attribute:: sixtofour For addresses that appear to be 6to4 addresses (starting with @@ -299,6 +314,8 @@ the :func:`str` and :func:`int` builtin functions:: >>> int(ipaddress.IPv6Address('::1')) 1 +Note that IPv6 scoped addresses are converted to integers without scope zone ID. + Operators ^^^^^^^^^ @@ -311,8 +328,9 @@ IPv6). Comparison operators """""""""""""""""""" -Address objects can be compared with the usual set of comparison operators. Some -examples:: +Address objects can be compared with the usual set of comparison operators. +Same IPv6 addresses with different scope zone IDs are not equal. +Some examples:: >>> IPv4Address('127.0.0.2') > IPv4Address('127.0.0.1') True @@ -320,6 +338,10 @@ examples:: False >>> IPv4Address('127.0.0.2') != IPv4Address('127.0.0.1') True + >>> IPv6Address('fe80::1234') == IPv6Address('fe80::1234%1') + False + >>> IPv6Address('fe80::1234%1') != IPv6Address('fe80::1234%2') + True Arithmetic operators |