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

Method _prefix_from_ip_int

Lib/ipaddress.py:440–462  ·  view source on GitHub ↗

Return prefix length from the bitwise netmask. Args: ip_int: An integer, the netmask in expanded bitwise format Returns: An integer, the prefix length. Raises: ValueError: If the input intermingles zeroes & ones

(cls, ip_int)

Source from the content-addressed store, hash-verified

438
439 @classmethod
440 def _prefix_from_ip_int(cls, ip_int):
441 """Return prefix length from the bitwise netmask.
442
443 Args:
444 ip_int: An integer, the netmask in expanded bitwise format
445
446 Returns:
447 An integer, the prefix length.
448
449 Raises:
450 ValueError: If the input intermingles zeroes & ones
451 """
452 trailing_zeroes = _count_righthand_zero_bits(ip_int,
453 cls.max_prefixlen)
454 prefixlen = cls.max_prefixlen - trailing_zeroes
455 leading_ones = ip_int >> trailing_zeroes
456 all_ones = (1 << prefixlen) - 1
457 if leading_ones != all_ones:
458 byteslen = cls.max_prefixlen // 8
459 details = ip_int.to_bytes(byteslen, 'big')
460 msg = 'Netmask pattern %r mixes zeroes & ones'
461 raise ValueError(msg % details)
462 return prefixlen
463
464 @classmethod
465 def _report_invalid_netmask(cls, netmask_str):

Callers 1

Calls 2

to_bytesMethod · 0.80

Tested by

no test coverage detected