本文整理匯總了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)