Files
rengine/shared/utils/coerce.py
T
Yogesh Ojha 4792f70305 Implement WHOIS service with RDAP provider integration
- Added models for WHOIS responses including WhoisDomainResponse, WhoisIPResponse, and WhoisASNResponse.
- Created a parser for WHOIS data to convert raw responses into structured models.
- Developed an RDAPProvider class to handle RDAP lookups using the whoisit library.
- Implemented a WhoisService class for performing WHOIS lookups with optional database caching.
- Added methods for finding correlations between WHOIS records based on registrant, registrar, network, country, and nameservers.
- Updated Dockerfile to include tools directory and added rengine-tools dependency in pyproject.toml.
2026-02-07 10:43:08 +05:30

46 lines
1.1 KiB
Python

# safe converters
from datetime import datetime
from typing import Any
def safe_str(value: Any, default: str = "") -> str:
"""Safely convert a value to a stripped string."""
if value is None:
return default
s = str(value).strip()
return s if s else default
def safe_int(value: Any, default: int | None = None) -> int | None:
"""Safely convert a value to int."""
if value is None:
return default
try:
return int(value)
except (ValueError, TypeError):
return default
def safe_datetime(value: Any) -> datetime | None:
"""Safely extract a datetime, returning None if not a datetime."""
if isinstance(value, datetime):
return value
return None
def safe_list(value: Any) -> list:
"""Safely convert to list."""
if value is None:
return []
if isinstance(value, list):
return value
return [value]
def safe_bool(value: Any, default: bool = False) -> bool:
"""Safely convert to bool."""
if isinstance(value, bool):
return value
return default