Represent and manipulate single IPv4 Addresses.
| 1261 | return '.'.join(reverse_octets) + '.in-addr.arpa' |
| 1262 | |
| 1263 | class IPv4Address(_BaseV4, _BaseAddress): |
| 1264 | |
| 1265 | """Represent and manipulate single IPv4 Addresses.""" |
| 1266 | |
| 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): |
| 1306 | """The binary representation of this address.""" |
| 1307 | return v4_int_to_packed(self._ip) |
| 1308 | |
| 1309 | @property |
| 1310 | def is_reserved(self): |
| 1311 | """Test if the address is otherwise IETF reserved. |
| 1312 | |
| 1313 | Returns: |
| 1314 | A boolean, True if the address is within the |
| 1315 | reserved IPv4 Network range. |
| 1316 | |
| 1317 | """ |
| 1318 | return self in self._constants._reserved_network |
| 1319 | |
| 1320 | @property |
no outgoing calls
no test coverage detected
searching dependent graphs…