File size: 938 Bytes
d1ceb73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
"""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
|