

def template(value):
    'Validate a jinja2 template.'
    if (value is None):
        raise vol.Invalid('template value is None')
    value = str(value)
    try:
        jinja2.Environment().parse(value)
        return value
    except jinja2.exceptions.TemplateSyntaxError as ex:
        raise vol.Invalid('invalid template ({})'.format(ex))

dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/helpers/config_validation.py template/original