Python jinja2.nodes.CallBlock() Examples
The following are 30
code examples of jinja2.nodes.CallBlock().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
jinja2.nodes
, or try the search function
.
Example #1
Source File: jinja2ext.py From canvas with BSD 3-Clause "New" or "Revised" License | 6 votes |
def parse(self, parser): lineno = parser.stream.next().lineno kindarg = parser.parse_expression() # Allow kind to be defined as jinja2 name node if isinstance(kindarg, nodes.Name): kindarg = nodes.Const(kindarg.name) args = [kindarg] if args[0].value not in self.compressors: raise TemplateSyntaxError('compress kind may be one of: %s' % (', '.join(self.compressors.keys())), lineno) if parser.stream.skip_if('comma'): modearg = parser.parse_expression() # Allow mode to be defined as jinja2 name node if isinstance(modearg, nodes.Name): modearg = nodes.Const(modearg.name) args.append(modearg) else: args.append(nodes.Const('file')) body = parser.parse_statements(['name:endcompress'], drop_needle=True) args.append(nodes.Const(unicode(body))) return nodes.CallBlock(self.call_method('_compress', args), [], [], body).set_lineno(lineno)
Example #2
Source File: parser.py From data with GNU General Public License v3.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #3
Source File: parser.py From luci-py with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #4
Source File: parser.py From luci-py with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #5
Source File: parser.py From luci-py with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #6
Source File: factory.py From snaql with MIT License | 5 votes |
def parse(self, parser): lineno = next(parser.stream).lineno expr = parser.parse_expression() args = [expr] kwargs = [nodes.Keyword('func', expr)] if parser.stream.skip_if('comma'): # Optional 'note' for function docstring if ( parser.stream.current.type == 'name' and parser.stream.current.value in ( 'note', 'cond_for', 'depends_on' ) ): stream_type = parser.stream.current.value next(parser.stream) parser.stream.expect('assign') # Depends meta is always a list if stream_type == 'depends_on': c_expr = parser.parse_list() else: c_expr = parser.parse_expression() args.append(c_expr) kwargs.append(nodes.Keyword(stream_type, c_expr)) body = parser.parse_statements( ['name:endsql', 'name:endquery'], drop_needle=True ) raw_template = self.environment.sql_params['raws'][parser.name] # Lines range of original raw template raw_lines = slice(lineno, parser.stream.current.lineno-1) self.environment.sql_params.setdefault('funcs', {}).update({ expr.value: {'raw_sql': '\n '.join(raw_template[raw_lines])} }) call_node = nodes.Call( self.attr('_sql_process', lineno=lineno), args, kwargs, None, None ) return nodes.CallBlock(call_node, [], [], body)
Example #7
Source File: parser.py From PhonePi_SampleServer with MIT License | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #8
Source File: parser.py From syntheticmass with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #9
Source File: jinja2ext.py From syntheticmass with Apache License 2.0 | 5 votes |
def parse(self, parser): lineno = next(parser.stream).lineno #: Parse timeout args = [parser.parse_expression()] #: Parse fragment name #: Grab the fragment name if it exists #: otherwise, default to the old method of using the templates #: lineno to maintain backwards compatibility. if parser.stream.skip_if('comma'): args.append(parser.parse_expression()) else: args.append(nodes.Const("%s%s" % (parser.filename, lineno))) #: Parse vary_on parameters vary_on = [] while parser.stream.skip_if('comma'): vary_on.append(parser.parse_expression()) if vary_on: args.append(nodes.List(vary_on)) else: args.append(nodes.Const([])) body = parser.parse_statements(['name:endcache'], drop_needle=True) return nodes.CallBlock(self.call_method('_cache', args), [], [], body).set_lineno(lineno)
Example #10
Source File: parser.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #11
Source File: parser.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #12
Source File: parser.py From EDCOP with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #13
Source File: parser.py From data with GNU General Public License v3.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #14
Source File: parser.py From luci-py with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #15
Source File: parser.py From data with GNU General Public License v3.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #16
Source File: parser.py From data with GNU General Public License v3.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #17
Source File: parser.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #18
Source File: adapter.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _parse_djextends(self, parser, lineno): args = [parser.parse_expression()] body = parser.parse_statements(['name:enddjextends'], drop_needle=True) return [nodes.Assign( nodes.Name(EXTENDS_DJANGO, 'store'), nodes.Const(True), ).set_lineno(lineno), nodes.CallBlock(self.call_method('_extend_django', args), [], [], body).set_lineno(lineno)]
Example #19
Source File: adapter.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _parse_djblock(self, parser, lineno): node = nodes.Block(lineno=lineno) node.name = parser.stream.expect('name').value node.scoped = parser.stream.skip_if('name:scoped') # common problem people encounter when switching from django # to jinja. we do not support hyphens in block names, so let's # raise a nicer error message in that case. if parser.stream.current.type == 'sub': parser.fail('Block names in Jinja have to be valid Python ' 'identifiers and may not contain hyphens, use an ' 'underscore instead.') node.body = parser.parse_statements(('name:enddjblock',), drop_needle=True) parser.stream.skip_if('name:' + node.name) block_name = node.name def output(text): return nodes.CallBlock(self.call_method('_block', args=[ nodes.Name(EXTENDS_DJANGO, 'load'), nodes.Const(text), ]), [], [], []).set_lineno(lineno) prefix = output('{{% block {0} %}}'.format(block_name)) postfix = output('{% endblock %}') return [prefix, node, postfix]
Example #20
Source File: parser.py From android_universal with MIT License | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #21
Source File: parser.py From Flask with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #22
Source File: parser.py From Flask with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #23
Source File: parser.py From odoo12-x64 with GNU General Public License v3.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #24
Source File: parser.py From pySINDy with MIT License | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #25
Source File: parser.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #26
Source File: parser.py From recruit with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #27
Source File: parser.py From recruit with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #28
Source File: parser.py From jbox with MIT License | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node
Example #29
Source File: jinja2ext.py From django-cachalot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def parse(self, parser): tag = parser.stream.current.value lineno = next(parser.stream).lineno args, kwargs = self.parse_args(parser) default_cache_key = (None if parser.filename is None else '%s:%d' % (parser.filename, lineno)) kwargs.append(Keyword('default_cache_key', Const(default_cache_key), lineno=lineno)) body = parser.parse_statements(['name:end' + tag], drop_needle=True) return CallBlock(self.call_method('cache', args, kwargs), [], [], body).set_lineno(lineno)
Example #30
Source File: parser.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def parse_call_block(self): node = nodes.CallBlock(lineno=next(self.stream).lineno) if self.stream.current.type == 'lparen': self.parse_signature(node) else: node.args = [] node.defaults = [] node.call = self.parse_expression() if not isinstance(node.call, nodes.Call): self.fail('expected call', node.lineno) node.body = self.parse_statements(('name:endcall',), drop_needle=True) return node