We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a814098 commit 991d81dCopy full SHA for 991d81d
src/requests/utils.py
@@ -714,22 +714,11 @@ def is_valid_cidr(string_network):
714
715
:rtype: bool
716
"""
717
- if string_network.count("/") == 1:
718
- try:
719
- mask = int(string_network.split("/")[1])
720
- except ValueError:
721
- return False
722
-
723
- if mask < 1 or mask > 32:
724
725
726
727
- socket.inet_aton(string_network.split("/")[0])
728
- except OSError:
729
730
- else:
+ try:
+ interface = ipaddress.ip_interface(string_network)
+ except (ipaddress.AddressValueError, ValueError):
731
return False
732
- return True
+ return string_network in (interface.compressed, interface.exploded)
733
734
735
@contextlib.contextmanager
0 commit comments