Source code for restgdf.utils.utils
"""General-purpose string helpers for URL and query construction."""
import re
from collections.abc import Iterable
from typing import Union
ends_with_num_pat = re.compile(r"\d+$")
[docs]
def ends_with_num(url: str) -> bool:
"""Return True if the given URL ends with a number."""
return bool(ends_with_num_pat.search(url))
[docs]
def where_var_in_list(var: str, vals: Iterable[Union[str, int, float]]) -> str:
"""Return a where clause for a variable in a list of values."""
vals_str = ", ".join(
f"'{val}'" if isinstance(val, str) else str(val) for val in vals
)
return f"{var} In ({vals_str})"