Skip to content

Commit 250a20d

Browse files
777GE90Killer Kode
authored andcommitted
Update docs
1 parent b949fb9 commit 250a20d

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

Doc/library/ipaddress.rst

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ dictionaries.
739739
Traceback (most recent call last):
740740
File "<stdin>", line 1, in <module>
741741
raise ValueError(
742-
ValueError: next prefix must be between 1 and 32
742+
ValueError: prefix must be between 1 and 32
743743
>>> IPv4Network('255.255.255.0/24').next_network()
744744
Traceback (most recent call last):
745745
File "<stdin>", line 1, in <module>
@@ -748,6 +748,36 @@ dictionaries.
748748

749749
.. versionadded:: 3.16
750750

751+
.. method:: prev_network(prev_prefix=None)
752+
753+
Finds the previous closest network of prefix size *prev_prefix*. If
754+
*prev_prefix=None*, then the current network prefix will be used.
755+
Returns a single network object.
756+
757+
Raises :exc:`ValueError` if *prev_prefix* is out of range or no further
758+
network of the requested size exists.
759+
760+
>>> IPv4Network('192.0.2.0/24').prev_network()
761+
IPv4Network('192.0.1.0/24')
762+
>>> IPv4Network('192.0.2.0/24').prev_network(prev_prefix=25)
763+
IPv4Network('192.0.1.128/25')
764+
>>> IPv4Network('192.0.2.0/24').prev_network(prev_prefix=23)
765+
IPv4Network('192.0.0.0/23')
766+
>>> IPv4Network('192.0.80.0/22').prev_network(prev_prefix=18)
767+
IPv4Network('192.0.0.0/18')
768+
>>> IPv4Network('192.0.80.0/22').prev_network(prev_prefix=50)
769+
Traceback (most recent call last):
770+
File "<stdin>", line 1, in <module>
771+
raise ValueError(
772+
ValueError: prefix must be between 1 and 32
773+
>>> IPv4Network('0.0.0.0/24').prev_network()
774+
Traceback (most recent call last):
775+
File "<stdin>", line 1, in <module>
776+
raise ValueError(
777+
ValueError: out of address space, cannot make another /24 network
778+
779+
.. versionadded:: 3.16
780+
751781
.. class:: IPv6Network(address, strict=True)
752782

753783
Construct an IPv6 network definition. *address* can be one of the following:
@@ -820,6 +850,7 @@ dictionaries.
820850
.. method:: subnet_of(other)
821851
.. method:: supernet_of(other)
822852
.. method:: next_network(next_prefix=None)
853+
.. method:: prev_network(prev_prefix=None)
823854
.. method:: compare_networks(other)
824855

825856
Refer to the corresponding attribute documentation in

Doc/whatsnew/3.16.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ ipaddress
321321
Add :meth:`~ipaddress.IPv4Network.next_network` and
322322
:meth:`~ipaddress.IPv6Network.next_network` methods to find the next nearest
323323
network with a specific prefix size.
324+
Add :meth:`~ipaddress.IPv4Network.prev_network` and
325+
:meth:`~ipaddress.IPv6Network.prev_network` methods to find the previous nearest
326+
network with a specific prefix size.
324327

325328

326329
logging
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
Add :meth:`~ipaddress.IPv4Network.next_network` and
2-
:meth:`~ipaddress.IPv6Network.next_network`. Patch by Faisal Mahmood.
1+
Add :meth:`~ipaddress.IPv4Network.next_network`,
2+
:meth:`~ipaddress.IPv6Network.next_network`,
3+
:meth:`~ipaddress.IPv4Network.prev_network` and
4+
:meth:`~ipaddress.IPv6Network.prev_network`. Patch by Faisal Mahmood.

0 commit comments

Comments
 (0)