HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Python311/Lib/site-packages/uri_template/__init__.py
"""Module for URI Template expansion."""

from __future__ import annotations

from .expansions import ExpansionFailedError
from .uritemplate import ExpansionInvalidError, ExpansionReservedError, URITemplate
from .variable import Variable, VariableInvalidError


__all__ = (
    'URITemplate',
    'Variable',
    'ExpansionInvalidError',
    'ExpansionReservedError',
    'VariableInvalidError',
    'ExpansionFailedError',
)


def expand(template: str, **kwargs) -> (str | None):
    try:
        templ = URITemplate(template)
        return templ.expand(**kwargs)
    except Exception:
        return None


def partial(template: str, **kwargs) -> (str | None):
    try:
        templ = URITemplate(template)
        return str(templ.partial(**kwargs))
    except Exception:
        return None


def validate(template: str) -> bool:
    try:
        URITemplate(template)
        return True
    except Exception:
        return False