@@ -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
0 commit comments