Source code for airbase.util

"""Utility functions for processing the raw Portal responses, url templating, etc."""

from __future__ import annotations

from datetime import datetime
from typing import Iterable, overload

from .resources import (
    ALL_SOURCES,
    CURRENT_YEAR,
    DATE_FMT,
    LINK_LIST_URL_TEMPLATE,
)


@overload
def string_safe_list(obj: None) -> list[None]:  # pragma: no cover
    ...


@overload
def string_safe_list(obj: str | Iterable[str]) -> list[str]:  # pragma: no cover
    ...


[docs]def string_safe_list(obj: str | Iterable[str] | None) -> list[str] | list[None]: """ Turn an (iterable) object into a list. If it is a string or not iterable, put the whole object into a list of length 1. :param obj: :return list: """ if isinstance(obj, str): return [obj] if obj is None: return [obj] return list(obj)