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

Method __init__

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

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

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 5

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

Tested by

no test coverage detected