definition.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:ethereum 作者: Webhero9297 项目源码 文件源码
def interpolate_value(value: str, context: dict):
    """Expand Jinja templating in the definitions."""

    if type(value) == str and "{{" in value:
        t = jinja2.Template(value, undefined=jinja2.StrictUndefined)
        try:
            v = t.render(**context)
        except jinja2.exceptions.TemplateError as e:
            raise RuntimeError("Could not expand template value: {}".format(value)) from e

        # Jinja template rendering does not have explicit int support,
        # so we have this hack in place
        try:
            v = int(v)
        except ValueError:
            pass

        return v
    else:
        return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号