MCPcopy Index your code
hub / github.com/python/cpython / _prefix_from_prefix_string

Method _prefix_from_prefix_string

Lib/ipaddress.py:467–489  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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):

Callers 3

_make_netmaskMethod · 0.80
_make_netmaskMethod · 0.80
testZeroNetmaskMethod · 0.80

Calls 3

isasciiMethod · 0.80
isdigitMethod · 0.80

Tested by 1

testZeroNetmaskMethod · 0.64