Files
rengine/shared/utils/coerce.py
T
Yogesh Ojha 69239333bc Refactor validation and DNS tools, implementation of onboarding wizard
- Added `clean_name` function to `validation.py` for name validation with max length.
- Simplified docstrings in `dnsx` client, parser, and service files for clarity.
- Enhanced error handling in `ViewDNSService` to prevent disabling keys on rate limits.
- Improved WHOIS service to handle concurrent inserts gracefully with integrity checks.
- Updated `Settings` class in worker config to inherit from `BaseAppSettings`.
- Added new dependencies in `pyproject.toml` for `apprise` and `cryptography`.
2026-06-21 21:56:20 +05:30

58 lines
1.2 KiB
Python

import uuid
from datetime import datetime
from typing import Any
def safe_str(value: Any, default: str = "") -> str:
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:
if value is None:
return default
try:
return int(value)
except (ValueError, TypeError):
return default
def safe_datetime(value: Any) -> datetime | None:
if isinstance(value, datetime):
return value
return None
def safe_list(value: Any) -> list:
if value is None:
return []
if isinstance(value, list):
return value
return [value]
def safe_bool(value: Any, default: bool = False) -> bool:
if isinstance(value, bool):
return value
return default
def safe_str_list(raw: list | None) -> list[str]:
if not raw:
return []
return [str(v).strip() for v in raw if v is not None and str(v).strip()]
def strip_trailing_dot(value: str) -> str:
return value.rstrip(".")
def safe_uuid(value: uuid.UUID | str | None) -> uuid.UUID | None:
if value is None:
return None
if isinstance(value, uuid.UUID):
return value
return uuid.UUID(value)