Skip to content

Commit a841e9a

Browse files
author
opavliuk
committed
bpo-34788 Add documentation for scope id support
1 parent 8a5c94f commit a841e9a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Doc/library/ipaddress.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,14 @@ write code that handles both IP versions correctly. Address objects are
219219
``"::abc:7:def"``.
220220
2. An integer that fits into 128 bits.
221221
3. An integer packed into a :class:`bytes` object of length 16, big-endian.
222+
4. String IPv6 address may contain scope (or zone) id in format <address>%<scope_id>.
223+
Scope id could not be blank or negative integer.
224+
See :RFC: `4007` for details.
222225

223226
>>> ipaddress.IPv6Address('2001:db8::1000')
224227
IPv6Address('2001:db8::1000')
228+
>>> ipaddress.IPv6Address('2001:db8::1000%1')
229+
IPv6Address('2001:db8::1000%1')
225230

226231
.. attribute:: compressed
227232

@@ -268,6 +273,12 @@ write code that handles both IP versions correctly. Address objects are
268273
``::FFFF/96``), this property will report the embedded IPv4 address.
269274
For any other address, this property will be ``None``.
270275

276+
.. attribute:: scope_id
277+
278+
For addresses that appear to be scoped addresses (containing
279+
``%<scope_id>``) as defined by :RFC:`4007`, this attribute will consist
280+
scope id. For any other address, this property will be ``None``.
281+
271282
.. attribute:: sixtofour
272283

273284
For addresses that appear to be 6to4 addresses (starting with
@@ -311,15 +322,17 @@ IPv6).
311322
Comparison operators
312323
""""""""""""""""""""
313324

314-
Address objects can be compared with the usual set of comparison operators. Some
315-
examples::
325+
Address objects can be compared with the usual set of comparison operators. Scope id
326+
is not considered while comparing IPv6 address objects. Some examples::
316327

317328
>>> IPv4Address('127.0.0.2') > IPv4Address('127.0.0.1')
318329
True
319330
>>> IPv4Address('127.0.0.2') == IPv4Address('127.0.0.1')
320331
False
321332
>>> IPv4Address('127.0.0.2') != IPv4Address('127.0.0.1')
322333
True
334+
>>> IPv6Address('fe80::1234') == IPv6Address('fe80::1234%1')
335+
True
323336

324337

325338
Arithmetic operators

0 commit comments

Comments
 (0)