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)
| 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): |
no test coverage detected