Skip to content

Commit 98f7ae3

Browse files
authored
feat: add reverse_pointer to the cache (#4)
1 parent 43c8837 commit 98f7ae3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/cached_ipaddress/ipaddress.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def is_multicast(self) -> bool: # type: ignore[override]
3737
"""Return True if this is a multicast address."""
3838
return super().is_multicast
3939

40+
@cached_property
41+
def reverse_pointer(self) -> str: # type: ignore[override]
42+
"""Return the reverse DNS pointer name for the IPv4 address."""
43+
return super().reverse_pointer
44+
4045

4146
class CachedIPv6Address(IPv6Address):
4247
def __str__(self) -> str:
@@ -68,8 +73,13 @@ def is_multicast(self) -> bool: # type: ignore[override]
6873
"""Return True if this is a multicast address."""
6974
return super().is_multicast
7075

76+
@cached_property
77+
def reverse_pointer(self) -> str: # type: ignore[override]
78+
"""Return the reverse DNS pointer name for the IPv6 address."""
79+
return super().reverse_pointer
80+
7181

72-
@lru_cache(maxsize=512)
82+
@lru_cache(maxsize=535)
7383
def _cached_ip_addresses(
7484
address: Union[str, bytes, int]
7585
) -> Optional[Union[IPv4Address, IPv6Address]]:

tests/test_ipaddress.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def test_cached_ip_addresses_wrapper():
2424
assert ipv4.is_loopback is False
2525
assert str(ipv4) == "169.254.0.0"
2626
assert str(ipv4) == "169.254.0.0"
27+
assert ipv4.reverse_pointer == "0.0.254.169.in-addr.arpa"
2728

2829
ipv4 = ipaddress.cached_ip_addresses("0.0.0.0") # noqa: S104
2930
assert ipv4 is not None
@@ -38,6 +39,10 @@ def test_cached_ip_addresses_wrapper():
3839
assert ipv6.is_unspecified is False
3940
assert ipv6.is_loopback is False
4041
assert ipv6.is_multicast is False
42+
assert (
43+
ipv6.reverse_pointer
44+
== "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa"
45+
)
4146

4247
ipv6 = ipaddress.cached_ip_addresses("0:0:0:0:0:0:0:0")
4348
assert ipv6 is not None

0 commit comments

Comments
 (0)