Skip to content

Commit

Permalink
fix: make records optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Feb 28, 2024
1 parent 1a0b892 commit f4310fb
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions abuse_whois/services/contacts.py
Expand Up @@ -68,27 +68,14 @@ async def safe_query(
return await query(hostname, timeout=timeout)


async def get_ip_record(
hostname: str, *, timeout: int = settings.QUERY_TIMEOUT
) -> schemas.WhoisRecord:
ip_f_result = await safe_query(hostname, timeout=timeout)
return unsafe_perform_io(ip_f_result.alt(raise_exception).unwrap())


async def get_optional_ip_record(
hostname: str | None, *, timeout: int = settings.QUERY_TIMEOUT
) -> schemas.WhoisRecord | None:
if hostname is None:
return None

return await get_ip_record(hostname, timeout=timeout)


async def get_domain_record(
hostname: str, *, timeout: int = settings.QUERY_TIMEOUT
) -> schemas.WhoisRecord:
domain_f_result = await safe_query(hostname, timeout=timeout)
return unsafe_perform_io(domain_f_result.alt(raise_exception).unwrap())
ip_f_result = await safe_query(hostname, timeout=timeout)
return unsafe_perform_io(ip_f_result.value_or(None))


async def get_optional_domain_record(
Expand All @@ -98,7 +85,7 @@ async def get_optional_domain_record(
return None

domain_f_result = await safe_query(hostname, timeout=timeout)
return unsafe_perform_io(domain_f_result.alt(raise_exception).unwrap())
return unsafe_perform_io(domain_f_result.value_or(None))


@future_safe
Expand Down

0 comments on commit f4310fb

Please sign in to comment.