本文整理汇总了Python中jinja2.nodes.Impossible方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.Impossible方法的具体用法?Python nodes.Impossible怎么用?Python nodes.Impossible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.nodes
的用法示例。
在下文中一共展示了nodes.Impossible方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_If
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Impossible [as 别名]
def visit_If(self, node):
"""Eliminate dead code."""
# do not optimize ifs that have a block inside so that it doesn't
# break super().
if node.find(nodes.Block) is not None:
return self.generic_visit(node)
try:
val = self.visit(node.test).as_const()
except nodes.Impossible:
return self.generic_visit(node)
if val:
body = node.body
else:
body = node.else_
result = []
for node in body:
result.extend(self.visit_list(node))
return result
示例2: fold
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Impossible [as 别名]
def fold(self, node, eval_ctx=None):
"""Do constant folding."""
node = self.generic_visit(node)
try:
return nodes.Const.from_untrusted(node.as_const(eval_ctx),
lineno=node.lineno,
environment=self.environment)
except nodes.Impossible:
return node
示例3: visit_TemplateData
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Impossible [as 别名]
def visit_TemplateData(self, node, frame):
try:
self.write(repr(node.as_const(frame.eval_ctx)))
except nodes.Impossible:
self.write('(Markup if context.eval_ctx.autoescape else identity)(%r)'
% node.data)
示例4: visit_EvalContextModifier
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Impossible [as 别名]
def visit_EvalContextModifier(self, node, frame):
for keyword in node.options:
self.writeline('context.eval_ctx.%s = ' % keyword.key)
self.visit(keyword.value, frame)
try:
val = keyword.value.as_const(frame.eval_ctx)
except nodes.Impossible:
frame.eval_ctx.volatile = True
else:
setattr(frame.eval_ctx, keyword.key, val)
示例5: fold
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Impossible [as 别名]
def fold(self, node):
"""Do constant folding."""
node = self.generic_visit(node)
try:
return nodes.Const.from_untrusted(node.as_const(),
lineno=node.lineno,
environment=self.environment)
except nodes.Impossible:
return node
示例6: visit_TemplateData
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Impossible [as 别名]
def visit_TemplateData(self, node, frame):
try:
self.write(repr(node.as_const(frame.eval_ctx)))
except nodes.Impossible:
self.write('(context.eval_ctx.autoescape and Markup or identity)(%r)'
% node.data)