utils
utils
¶
Shared utility functions for BigBrotr services.
Provides lightweight helpers used across multiple services. Domain-specific
logic belongs in per-service utils.py modules; only truly shared
primitives live here.
See Also
configs: Shared Pydantic network configuration models. queries: Centralized SQL query functions. mixins: Reusable service mixin classes.
Classes¶
Functions¶
parse_relay
¶
parse_relay(
url: str, discovered_at: int | None = None
) -> Relay | None
Parse a relay URL string into a Relay object.
Strips whitespace, rejects empty/non-string input, and delegates to the Relay constructor for RFC 3986 validation and network detection.
Parameters:
-
url(str) –Potential relay URL string.
-
discovered_at(int | None, default:None) –Optional Unix timestamp of first discovery. When
None(default),Relayuses the current time.
Returns:
Source code in src/bigbrotr/services/common/utils.py
parse_relay_row
¶
parse_relay_row(row: Any) -> Relay | None
Construct a Relay from a database row with network cross-check.
Builds a Relay from row["url"] and
row["discovered_at"], then verifies that the network detected from
the URL matches row["network"]. A mismatch is logged as a warning
(possible data integrity issue) but the relay is still returned with
the detected network. Returns None if the URL fails validation.
Parameters:
-
row(Any) –Database row with
url,network, anddiscovered_at.
Returns: