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

Method __init__

Lib/ipaddress.py:1272–1305  ·  view source on GitHub ↗

Args: address: A string or integer representing the IP Additionally, an integer can be passed, so IPv4Address('192.0.2.1') == IPv4Address(3221225985). or, more generally IPv4Address(int(IPv4Address('192.0.2.1'))) ==

(self, address)

Source from the content-addressed store, hash-verified

1270 __slots__ = ('_ip', '__weakref__')
1271
1272 def __init__(self, address):
1273
1274 """
1275 Args:
1276 address: A string or integer representing the IP
1277
1278 Additionally, an integer can be passed, so
1279 IPv4Address('192.0.2.1') == IPv4Address(3221225985).
1280 or, more generally
1281 IPv4Address(int(IPv4Address('192.0.2.1'))) ==
1282 IPv4Address('192.0.2.1')
1283
1284 Raises:
1285 AddressValueError: If ipaddress isn't a valid IPv4 address.
1286
1287 """
1288 # Efficient constructor from integer.
1289 if isinstance(address, int):
1290 self._check_int_address(address)
1291 self._ip = address
1292 return
1293
1294 # Constructing from a packed address
1295 if isinstance(address, bytes):
1296 self._check_packed_address(address, 4)
1297 self._ip = int.from_bytes(address) # big endian
1298 return
1299
1300 # Assume input argument to be string or any object representation
1301 # which converts into a formatted IP string.
1302 addr_str = str(address)
1303 if '/' in addr_str:
1304 raise AddressValueError(f"Unexpected '/' in {address!r}")
1305 self._ip = self._ip_int_from_string(addr_str)
1306
1307 @property
1308 def packed(self):

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 7

isinstanceFunction · 0.85
strFunction · 0.85
AddressValueErrorClass · 0.85
_check_int_addressMethod · 0.80
_check_packed_addressMethod · 0.80
from_bytesMethod · 0.45
_ip_int_from_stringMethod · 0.45

Tested by

no test coverage detected