MCPcopy Index your code
hub / github.com/RustPython/RustPython / _prefix_from_ip_string

Method _prefix_from_ip_string

Lib/ipaddress.py:495–526  ·  view source on GitHub ↗

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

(cls, ip_str)

Source from the content-addressed store, hash-verified

493
494 @classmethod
495 def _prefix_from_ip_string(cls, ip_str):
496 """Turn a netmask/hostmask string into a prefix length
497
498 Args:
499 ip_str: The netmask/hostmask to be converted
500
501 Returns:
502 An integer, the prefix length.
503
504 Raises:
505 NetmaskValueError: If the input is not a valid netmask/hostmask
506 """
507 # Parse the netmask/hostmask like an IP address.
508 try:
509 ip_int = cls._ip_int_from_string(ip_str)
510 except AddressValueError:
511 cls._report_invalid_netmask(ip_str)
512
513 # Try matching a netmask (this would be /1*0*/ as a bitwise regexp).
514 # Note that the two ambiguous cases (all-ones and all-zeroes) are
515 # treated as netmasks.
516 try:
517 return cls._prefix_from_ip_int(ip_int)
518 except ValueError:
519 pass
520
521 # Invert the bits, and try matching a /0+1+/ hostmask instead.
522 ip_int ^= cls._ALL_ONES
523 try:
524 return cls._prefix_from_ip_int(ip_int)
525 except ValueError:
526 cls._report_invalid_netmask(ip_str)
527
528 @classmethod
529 def _split_addr_prefix(cls, address):

Callers 1

_make_netmaskMethod · 0.80

Calls 3

_prefix_from_ip_intMethod · 0.80
_ip_int_from_stringMethod · 0.45

Tested by

no test coverage detected