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

Method _make_netmask

Lib/ipaddress.py:1157–1180  ·  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

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

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 6

isinstanceFunction · 0.85
IPv4AddressClass · 0.85
_ip_int_from_prefixMethod · 0.80

Tested by

no test coverage detected