Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/uri_template/__init__.py: 35%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Module for URI Template expansion."""
3from __future__ import annotations
5from .expansions import ExpansionFailedError
6from .uritemplate import ExpansionInvalidError, ExpansionReservedError, URITemplate
7from .variable import Variable, VariableInvalidError
10__all__ = (
11 'URITemplate',
12 'Variable',
13 'ExpansionInvalidError',
14 'ExpansionReservedError',
15 'VariableInvalidError',
16 'ExpansionFailedError',
17)
20def expand(template: str, **kwargs) -> (str | None):
21 try:
22 templ = URITemplate(template)
23 return templ.expand(**kwargs)
24 except Exception:
25 return None
28def partial(template: str, **kwargs) -> (str | None):
29 try:
30 templ = URITemplate(template)
31 return str(templ.partial(**kwargs))
32 except Exception:
33 return None
36def validate(template: str) -> bool:
37 try:
38 URITemplate(template)
39 return True
40 except Exception:
41 return False