MCPcopy
hub / github.com/psf/requests / is_valid_cidr

Function is_valid_cidr

src/requests/utils.py:763–784  ·  view source on GitHub ↗

Very simple check of the cidr format in no_proxy variable. :rtype: bool

(string_network: str)

Source from the content-addressed store, hash-verified

761
762
763def is_valid_cidr(string_network: str) -> bool:
764 """
765 Very simple check of the cidr format in no_proxy variable.
766
767 :rtype: bool
768 """
769 if string_network.count("/") == 1:
770 try:
771 mask = int(string_network.split("/")[1])
772 except ValueError:
773 return False
774
775 if mask < 1 or mask > 32:
776 return False
777
778 try:
779 socket.inet_aton(string_network.split("/")[0])
780 except OSError:
781 return False
782 else:
783 return False
784 return True
785
786
787@contextlib.contextmanager

Callers 3

test_validMethod · 0.90
test_invalidMethod · 0.90
should_bypass_proxiesFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_validMethod · 0.72
test_invalidMethod · 0.72