Issue #16531: ipaddress.IPv4Network and ipaddress.IPv6Network now accept an (address, netmask) tuple argument, so as to easily construct network objects from existing addresses.

This commit is contained in:
Antoine Pitrou 2014-05-12 20:36:46 +02:00
parent 3b5162d05d
commit 5fb195f854
4 changed files with 210 additions and 21 deletions

View file

@ -392,6 +392,12 @@ so to avoid duplication they are only documented for :class:`IPv4Network`.
3. An integer packed into a :class:`bytes` object of length 4, big-endian.
The interpretation is similar to an integer *address*.
4. A two-tuple of an address description and a netmask, where the address
description is either a string, a 32-bits integer, a 4-bytes packed
integer, or an existing IPv4Address object; and the netmask is either
an integer representing the prefix length (e.g. ``24``) or a string
representing the prefix mask (e.g. ``255.255.255.0``).
An :exc:`AddressValueError` is raised if *address* is not a valid IPv4
address. A :exc:`NetmaskValueError` is raised if the mask is not valid for
an IPv4 address.
@ -404,6 +410,10 @@ so to avoid duplication they are only documented for :class:`IPv4Network`.
objects will raise :exc:`TypeError` if the argument's IP version is
incompatible to ``self``
.. versionchanged:: 3.5
Added the two-tuple form for the *address* constructor parameter.
.. attribute:: version
.. attribute:: max_prefixlen
@ -568,6 +578,11 @@ so to avoid duplication they are only documented for :class:`IPv4Network`.
3. An integer packed into a :class:`bytes` object of length 16, bit-endian.
The interpretation is similar to an integer *address*.
4. A two-tuple of an address description and a netmask, where the address
description is either a string, a 128-bits integer, a 16-bytes packed
integer, or an existing IPv4Address object; and the netmask is an
integer representing the prefix length.
An :exc:`AddressValueError` is raised if *address* is not a valid IPv6
address. A :exc:`NetmaskValueError` is raised if the mask is not valid for
an IPv6 address.
@ -576,6 +591,10 @@ so to avoid duplication they are only documented for :class:`IPv4Network`.
then :exc:`ValueError` is raised. Otherwise, the host bits are masked out
to determine the appropriate network address.
.. versionchanged:: 3.5
Added the two-tuple form for the *address* constructor parameter.
.. attribute:: version
.. attribute:: max_prefixlen
.. attribute:: is_multicast