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

Method _ip_int_from_string

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

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

Callers 3

__init__Method · 0.45
__init__Method · 0.45

Calls 2

AddressValueErrorClass · 0.85
splitMethod · 0.45

Tested by

no test coverage detected