Very simple check of the cidr format in no_proxy variable. :rtype: bool
(string_network: str)
| 761 | |
| 762 | |
| 763 | def 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 |
no outgoing calls