Skip to content

Commit

Permalink
feat: add cache for compressed (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 23, 2024
1 parent 4b70152 commit 4afea62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cached_ipaddress/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def reverse_pointer(self) -> str: # type: ignore[override]
"""Return the reverse DNS pointer name for the IPv4 address."""
return super().reverse_pointer

@cached_property
def compressed(self) -> str: # type: ignore[override]
"""Return the compressed value IPv4 address."""
return super().compressed


class CachedIPv6Address(IPv6Address):

Expand Down Expand Up @@ -96,6 +101,11 @@ def reverse_pointer(self) -> str: # type: ignore[override]
"""Return the reverse DNS pointer name for the IPv6 address."""
return super().reverse_pointer

@cached_property
def compressed(self) -> str: # type: ignore[override]
"""Return the compressed value IPv6 address."""
return super().compressed


@lru_cache(maxsize=535)
def _cached_ip_addresses(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_cached_ip_addresses_wrapper():
assert ipv4.is_unspecified is True
assert ipv4.is_loopback is False
assert ipv4.is_multicast is False
assert ipv4.compressed == IPv4Address(str(ipv4)).compressed

ipv6 = ipaddress.cached_ip_addresses("fe80::1")
assert ipv6 is not None
Expand All @@ -57,3 +58,4 @@ def test_cached_ip_addresses_wrapper():
assert hash(ipv6) == hash(IPv6Address(str(ipv6)))
assert int(ipv4) == int(IPv4Address(str(ipv4)))
assert int(ipv6) == int(IPv6Address(str(ipv6)))
assert ipv6.compressed == IPv6Address(str(ipv6)).compressed

0 comments on commit 4afea62

Please sign in to comment.