本文整理汇总了Python中jinja2.exceptions.TemplateSyntaxError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.TemplateSyntaxError方法的具体用法?Python exceptions.TemplateSyntaxError怎么用?Python exceptions.TemplateSyntaxError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.exceptions
的用法示例。
在下文中一共展示了exceptions.TemplateSyntaxError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: expect
# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateSyntaxError [as 别名]
def expect(self, expr):
"""Expect a given token type and return it. This accepts the same
argument as :meth:`jinja2.lexer.Token.test`.
"""
if not self.current.test(expr):
expr = describe_token_expr(expr)
if self.current.type is TOKEN_EOF:
raise TemplateSyntaxError('unexpected end of template, '
'expected %r.' % expr,
self.current.lineno,
self.name, self.filename)
raise TemplateSyntaxError("expected token %r, got %r" %
(expr, describe_token(self.current)),
self.current.lineno,
self.name, self.filename)
try:
return self.current
finally:
next(self)
示例2: generate_by_context
# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateSyntaxError [as 别名]
def generate_by_context(self, context):
if context is None:
raise RuntimeError('Can\'t generate templates from None context')
templates = self._preprocess_templates(context.get('templates', []))
if len(templates) == 0:
templates = context.get('kubectl', [])
if len(templates) == 0:
return
output = []
for template in self._iterate_entries(templates):
try:
path = self._generate_file(template, settings.TEMP_DIR, context)
log.info('File "{}" successfully generated'.format(path))
output.append(path)
except TemplateNotFound as e:
raise TemplateRenderingError(
"Processing {}: template {} hasn't been found".format(template['template'], e.name))
except (UndefinedError, TemplateSyntaxError) as e:
raise TemplateRenderingError('Unable to render {}, due to: {}'.format(template, e))
return output
示例3: __init__
# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateSyntaxError [as 别名]
def __init__(self, message, cls=TemplateSyntaxError):
self.message = message
self.error_class = cls
示例4: wrap
# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateSyntaxError [as 别名]
def wrap(self, stream, name=None, filename=None):
"""This is called with the stream as returned by `tokenize` and wraps
every token in a :class:`Token` and converts the value.
"""
for lineno, token, value in stream:
if token in ignored_tokens:
continue
elif token == 'linestatement_begin':
token = 'block_begin'
elif token == 'linestatement_end':
token = 'block_end'
# we are not interested in those tokens in the parser
elif token in ('raw_begin', 'raw_end'):
continue
elif token == 'data':
value = self._normalize_newlines(value)
elif token == 'keyword':
token = value
elif token == 'name':
value = str(value)
if check_ident and not value.isidentifier():
raise TemplateSyntaxError(
'Invalid character in identifier',
lineno, name, filename)
elif token == 'string':
# try to unescape string
try:
value = self._normalize_newlines(value[1:-1]) \
.encode('ascii', 'backslashreplace') \
.decode('unicode-escape')
except Exception as e:
msg = str(e).split(':')[-1].strip()
raise TemplateSyntaxError(msg, lineno, name, filename)
elif token == 'integer':
value = int(value)
elif token == 'float':
value = float(value)
elif token == 'operator':
token = operators[value]
yield Token(lineno, token, value)
示例5: is_template_syntax_error
# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateSyntaxError [as 别名]
def is_template_syntax_error(self):
"""`True` if this is a template syntax error."""
return isinstance(self.exc_value, TemplateSyntaxError)
示例6: make_traceback
# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateSyntaxError [as 别名]
def make_traceback(exc_info, source_hint=None):
"""Creates a processed traceback object from the exc_info."""
exc_type, exc_value, tb = exc_info
if isinstance(exc_value, TemplateSyntaxError):
exc_info = translate_syntax_error(exc_value, source_hint)
initial_skip = 0
else:
initial_skip = 1
return translate_exception(exc_info, initial_skip)