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

Method _ip_int_from_string

Lib/ipaddress.py:1183–1206  ·  view source on GitHub ↗

Turn the given IP string into an integer for comparison. Args: ip_str: A string, the IP ip_str. Returns: The IP ip_str as an integer. Raises: AddressValueError: if ip_str isn't a valid IPv4 Address.

(cls, ip_str)

Source from the content-addressed store, hash-verified

1181
1182 @classmethod
1183 def _ip_int_from_string(cls, ip_str):
1184 """Turn the given IP string into an integer for comparison.
1185
1186 Args:
1187 ip_str: A string, the IP ip_str.
1188
1189 Returns:
1190 The IP ip_str as an integer.
1191
1192 Raises:
1193 AddressValueError: if ip_str isn't a valid IPv4 Address.
1194
1195 """
1196 if not ip_str:
1197 raise AddressValueError('Address cannot be empty')
1198
1199 octets = ip_str.split('.')
1200 if len(octets) != 4:
1201 raise AddressValueError("Expected 4 octets in %r" % ip_str)
1202
1203 try:
1204 return int.from_bytes(map(cls._parse_octet, octets), 'big')
1205 except ValueError as exc:
1206 raise AddressValueError("%s in %r" % (exc, ip_str)) from None
1207
1208 @classmethod
1209 def _parse_octet(cls, octet_str):

Callers 3

__init__Method · 0.45
__init__Method · 0.45

Calls 4

AddressValueErrorClass · 0.85
lenFunction · 0.85
splitMethod · 0.45
from_bytesMethod · 0.45

Tested by

no test coverage detected