Skip to content

route_rules.utils

Functions:

as_set

as_set(obj: str | Iterable[str]) -> set[str]
Source code in src/route_rules/utils/_as.py
4
5
6
7
def as_set(obj: str | Iterable[str]) -> set[str]:
    if isinstance(obj, str):
        return {obj}
    return set(obj)

download async

download(
    url: str,
    _fpath: StrPath | None = None,
    *,
    redo: bool = False,
    verbose: bool | None = True,
    expires: str | int | datetime | timedelta | None = None
) -> Path
Source code in src/route_rules/utils/_download.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
async def download(
    url: str,
    _fpath: StrPath | None = None,
    *,
    redo: bool = False,
    verbose: bool | None = True,
    expires: str | int | datetime.datetime | datetime.timedelta | None = None,
) -> Path:
    if _fpath is None:
        _fpath = os.path.basename(url)  # noqa: PTH119
    fpath: Path = Path(_fpath)
    fname: str = fpath.name
    fpath.parent.mkdir(parents=True, exist_ok=True)
    stamp = ub.CacheStamp(
        fname + ".stamp",
        dpath=fpath.parent,
        product=fpath,
        verbose=verbose,
        expires=expires,
        ext=".json",
    )
    if redo or stamp.expired():
        await _download(url, fpath)
        stamp.renew()
    return fpath

split_strip

split_strip(text: str, sep: str | None = ',') -> list[str]
Source code in src/route_rules/utils/_str.py
13
14
def split_strip(text: str, sep: str | None = ",") -> list[str]:
    return [s.strip() for s in text.split(sep)]

strip_comments

strip_comments(text: str) -> Generator[str, None, None]
Source code in src/route_rules/utils/_str.py
 4
 5
 6
 7
 8
 9
10
def strip_comments(text: str) -> Generator[str, None, None]:
    for line in text.splitlines():
        s: str
        s, _, _ = line.partition("#")
        s = s.strip()
        if s:
            yield s