21 lines
415 B
Python
21 lines
415 B
Python
import re
|
|
|
|
_PATTERN = re.compile(r"\{\{(\w+)\}\}")
|
|
|
|
def render(value, context: dict):
|
|
if not isinstance(value, str):
|
|
return value
|
|
|
|
def replace(match):
|
|
key = match.group(1)
|
|
return str(context.get(key, ""))
|
|
|
|
return _PATTERN.sub(replace, value)
|
|
|
|
|
|
def render_headers(headers: dict, context: dict):
|
|
return {
|
|
k: render(v, context)
|
|
for k, v in headers.items()
|
|
}
|