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

Method _make_netmask

Lib/ipaddress.py:1154–1177  ·  view source on GitHub ↗

Make a (netmask, prefix_len) tuple from the given argument. Argument can be: - an integer (the prefix length) - a string representing the prefix length (e.g. "24") - a string representing the prefix netmask (e.g. "255.255.255.0")

(cls, arg)

Source from the content-addressed store, hash-verified

1152
1153 @classmethod
1154 def _make_netmask(cls, arg):
1155 """Make a (netmask, prefix_len) tuple from the given argument.
1156
1157 Argument can be:
1158 - an integer (the prefix length)
1159 - a string representing the prefix length (e.g. "24")
1160 - a string representing the prefix netmask (e.g. "255.255.255.0")
1161 """
1162 if arg not in cls._netmask_cache:
1163 if isinstance(arg, int):
1164 prefixlen = arg
1165 if not (0 <= prefixlen <= cls.max_prefixlen):
1166 cls._report_invalid_netmask(prefixlen)
1167 else:
1168 try:
1169 # Check for a netmask in prefix length form
1170 prefixlen = cls._prefix_from_prefix_string(arg)
1171 except NetmaskValueError:
1172 # Check for a netmask or hostmask in dotted-quad form.
1173 # This may raise NetmaskValueError.
1174 prefixlen = cls._prefix_from_ip_string(arg)
1175 netmask = IPv4Address(cls._ip_int_from_prefix(prefixlen))
1176 cls._netmask_cache[arg] = netmask, prefixlen
1177 return cls._netmask_cache[arg]
1178
1179 @classmethod
1180 def _ip_int_from_string(cls, ip_str):

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 5

IPv4AddressClass · 0.85
_ip_int_from_prefixMethod · 0.80

Tested by

no test coverage detected