本文整理匯總了Python中jinja2.nodes.Output方法的典型用法代碼示例。如果您正苦於以下問題:Python nodes.Output方法的具體用法?Python nodes.Output怎麽用?Python nodes.Output使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jinja2.nodes
的用法示例。
在下文中一共展示了nodes.Output方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def parse(self, parser):
stream = parser.stream
tag = stream.next()
# get arguments
args = []
kwargs = []
while not stream.current.test_any('block_end'):
if args or kwargs:
stream.expect('comma')
if stream.current.test('name') and stream.look().test('assign'):
key = nodes.Const(stream.next().value)
stream.skip()
value = parser.parse_expression()
kwargs.append(nodes.Pair(key, value, lineno=key.lineno))
else:
args.append(parser.parse_expression())
def make_call_node(*kw):
return self.call_method('_call', args=[
nodes.List(args),
nodes.Dict(kwargs),
], kwargs=kw)
return nodes.Output([make_call_node()]).set_lineno(tag.lineno)
示例2: parse
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def parse(self, parser):
def parse_arguments():
args = [parser.parse_expression()]
# append task filters if any
if parser.stream.skip_if('comma'):
args.append(parser.parse_expression())
return args
lineno = next(parser.stream).lineno
tag_args = parse_arguments()
call = self.call_method(self._include_tasks.__name__, tag_args)
return Output([call], lineno=lineno)
# By default, `yaml` package does not preserve field order, and
# playbook tasks do not look the same as in playbooks and in docs.
# These functions create custom Loader and Dumper to preserve field order.
# Source: https://stackoverflow.com/a/21912744
示例3: parse
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def parse(self, parser):
lineno = next(parser.stream).lineno
# get the first parameter: the view name
args = [parser.parse_expression()]
# if there's a comma, we've also got an instance variable here
if parser.stream.skip_if('comma'):
args.append(parser.parse_expression())
else:
# no instance supplied for URL tag
args.append(nodes.Const(None))
return nodes.Output(
[self.call_method('_url', args)],
lineno=lineno
)
示例4: parse_print
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def parse_print(self):
node = nodes.Output(lineno=next(self.stream).lineno)
node.nodes = []
while self.stream.current.type != 'block_end':
if node.nodes:
self.stream.expect('comma')
node.nodes.append(self.parse_expression())
return node
示例5: parse
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def parse(self, parser):
lineno = parser.stream.expect('name:csrf_token').lineno
call = self.call_method(
'_csrf_token',
[nodes.Name('csrf_token', 'load', lineno=lineno)],
lineno=lineno
)
return nodes.Output([nodes.MarkSafe(call)])
示例6: _parse_trans
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def _parse_trans(self, parser, lineno):
string = parser.stream.expect(lexer.TOKEN_STRING)
string = nodes.Const(string.value, lineno=string.lineno)
is_noop = False
context = None
as_var = None
for token in iter(lambda: parser.stream.next_if(lexer.TOKEN_NAME), None):
if token.value == 'noop' and not is_noop:
if context is not None:
parser.fail("noop translation can't have context", lineno=token.lineno)
is_noop = True
elif token.value == 'context' and context is None:
if is_noop:
parser.fail("noop translation can't have context", lineno=token.lineno)
context = parser.stream.expect(lexer.TOKEN_STRING)
context = nodes.Const(context.value, lineno=context.lineno)
elif token.value == 'as' and as_var is None:
as_var = parser.stream.expect(lexer.TOKEN_NAME)
as_var = nodes.Name(as_var.value, 'store', lineno=as_var.lineno)
else:
parser.fail("expected 'noop', 'context' or 'as'", lineno=token.lineno)
if is_noop:
output = string
elif context is not None:
func = nodes.Name('pgettext', 'load', lineno=lineno)
output = nodes.Call(func, [context, string], [], None, None, lineno=lineno)
else:
func = nodes.Name('gettext', 'load')
output = nodes.Call(func, [string], [], None, None, lineno=lineno)
if as_var is None:
return nodes.Output([output], lineno=lineno)
else:
return nodes.Assign(as_var, output, lineno=lineno)
示例7: parse
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def parse(self, parser):
list_of_paths = getattr(settings, 'LATEX_GRAPHICSPATH', [settings.BASE_DIR])
value = '\graphicspath{ ' + ' '.join(map(format_path_for_latex, list_of_paths)) + ' }'
node = nodes.Output(lineno=next(parser.stream).lineno)
node.nodes = [nodes.MarkSafe(nodes.Const(value))]
return node
示例8: parse
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def parse(self, parser):
lineno = next(parser.stream).lineno
node = parser.parse_expression()
if parser.stream.skip_if('comma'):
datetime_format = parser.parse_expression()
else:
datetime_format = nodes.Const(None)
if isinstance(node, nodes.Add):
call_method = self.call_method(
'_datetime',
[node.left, nodes.Const('+'), node.right, datetime_format],
lineno=lineno,
)
elif isinstance(node, nodes.Sub):
call_method = self.call_method(
'_datetime',
[node.left, nodes.Const('-'), node.right, datetime_format],
lineno=lineno,
)
else:
call_method = self.call_method(
'_now',
[node, datetime_format],
lineno=lineno,
)
return nodes.Output([call_method], lineno=lineno)
示例9: parse
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Output [as 別名]
def parse(self, parser):
return nodes.Output([self.call_method('_dump', [
nodes.EnvironmentAttribute('sandboxed'),
self.attr('ext_attr'),
nodes.ImportedName(__name__ + '.importable_object'),
nodes.ContextReference()
])]).set_lineno(next(parser.stream).lineno)