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

Class IPv4Address

Lib/ipaddress.py:1266–1413  ·  view source on GitHub ↗

Represent and manipulate single IPv4 Addresses.

Source from the content-addressed store, hash-verified

1264 return '.'.join(reverse_octets) + '.in-addr.arpa'
1265
1266class IPv4Address(_BaseV4, _BaseAddress):
1267
1268 """Represent and manipulate single IPv4 Addresses."""
1269
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):
1309 """The binary representation of this address."""
1310 return v4_int_to_packed(self._ip)
1311
1312 @property
1313 def is_reserved(self):
1314 """Test if the address is otherwise IETF reserved.
1315
1316 Returns:
1317 A boolean, True if the address is within the
1318 reserved IPv4 Network range.
1319
1320 """
1321 return self in self._constants._reserved_network
1322
1323 @property

Callers 10

ip_addressFunction · 0.85
_make_netmaskMethod · 0.85
ipMethod · 0.85
__init__Method · 0.85
_IPv4ConstantsClass · 0.85
_ip_int_from_stringMethod · 0.85
ipv4_mappedMethod · 0.85
teredoMethod · 0.85
sixtofourMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected