from __future__ import annotations

import ssl
import urllib.error


def is_transient_network_error(exc: BaseException) -> bool:
    if isinstance(exc, (TimeoutError, urllib.error.URLError, ssl.SSLError)):
        return True
    if isinstance(exc, OSError):
        return True
    msg = str(exc).lower()
    return any(
        token in msg
        for token in (
            "timeout",
            "timed out",
            "ssl",
            "connection reset",
            "network is unreachable",
            "temporary failure",
            "name or service not known",
        )
    )
