@classmethod<EOL><INDENT>def _prefix_from_ip_string(cls, ip_str):<DEDENT>
<EOL>try:<EOL><INDENT>ip_int = cls._ip_int_from_string(ip_str)<EOL><DEDENT>except AddressValueError:<EOL><INDENT>cls._report_invalid_netmask(ip_str)<EOL><DEDENT>try:<EOL><INDENT>return cls._prefix_from_ip_int(ip_int)<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT>ip_int ^= cls._ALL_ONES<EOL>try:<EOL><INDENT>return cls._prefix_from_ip_int(ip_int)<EOL><DEDENT>except ValueError:<EOL><INDENT>cls._report_invalid_netmask(ip_str)<EOL><DEDENT>
Turn a netmask/hostmask string into a prefix length

        Args:
            ip_str: The netmask/hostmask to be converted

        Returns:
            An integer, the prefix length.

        Raises:
            NetmaskValueError: If the input is not a valid netmask/hostmask