Return prefix length from a numeric string Args: prefixlen_str: The string to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask
(cls, prefixlen_str)
| 465 | |
| 466 | @classmethod |
| 467 | def _prefix_from_prefix_string(cls, prefixlen_str): |
| 468 | """Return prefix length from a numeric string |
| 469 | |
| 470 | Args: |
| 471 | prefixlen_str: The string to be converted |
| 472 | |
| 473 | Returns: |
| 474 | An integer, the prefix length. |
| 475 | |
| 476 | Raises: |
| 477 | NetmaskValueError: If the input is not a valid netmask |
| 478 | """ |
| 479 | # int allows a leading +/- as well as surrounding whitespace, |
| 480 | # so we ensure that isn't the case |
| 481 | if not (prefixlen_str.isascii() and prefixlen_str.isdigit()): |
| 482 | cls._report_invalid_netmask(prefixlen_str) |
| 483 | try: |
| 484 | prefixlen = int(prefixlen_str) |
| 485 | except ValueError: |
| 486 | cls._report_invalid_netmask(prefixlen_str) |
| 487 | if not (0 <= prefixlen <= cls.max_prefixlen): |
| 488 | cls._report_invalid_netmask(prefixlen_str) |
| 489 | return prefixlen |
| 490 | |
| 491 | @classmethod |
| 492 | def _prefix_from_ip_string(cls, ip_str): |