Skip to content
Myr

six.advance_iterator -> next

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 5cf3168 · Browse files · 11 files+113 added−103 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+113 added−103 removed

  • other:+113 added−103 removed

11 files+113 added−103 removed

modified:jinja2/testsuite/api.py+13 added-13 removed
12 unmodified lines
13import tempfile14import shutil1516from jinja2.testsuite import JinjaTestCase17from jinja2._compat import next1819from jinja2 import Environment, Undefined, DebugUndefined, \20 StrictUndefined, UndefinedError, meta, \21 is_undefined, Template, DictLoader22from jinja2.utils import Cycler22import six2324env = Environment()2526
26 unmodified lines
53 items = 1, 2, 354 c = Cycler(*items)55 for item in items + items:56 assert c.current == item57 assert six.advance_iterator(c) == item58 six.advance_iterator(c)57 assert next(c) == item58 next(c)59 assert c.current == 260 c.reset()61 assert c.current == 162
47 unmodified lines
110111 def test_find_refererenced_templates(self):112 ast = env.parse('{% extends "layout.html" %}{% include helper %}')113 i = meta.find_referenced_templates(ast)114 assert six.advance_iterator(i) == 'layout.html'115 assert six.advance_iterator(i) is None114 assert next(i) == 'layout.html'115 assert next(i) is None116 assert list(i) == []117118 ast = env.parse('{% extends "layout.html" %}'119 '{% from "test.html" import a, b as c %}'
25 unmodified lines
145 def test_basic_streaming(self):146 tmpl = env.from_string("<ul>{% for item in seq %}<li>{{ loop.index "147 "}} - {{ item }}</li>{%- endfor %}</ul>")148 stream = tmpl.stream(seq=list(range(4)))149 self.assert_equal(six.advance_iterator(stream), '<ul>')150 self.assert_equal(six.advance_iterator(stream), '<li>1 - 0</li>')151 self.assert_equal(six.advance_iterator(stream), '<li>2 - 1</li>')152 self.assert_equal(six.advance_iterator(stream), '<li>3 - 2</li>')153 self.assert_equal(six.advance_iterator(stream), '<li>4 - 3</li>')154 self.assert_equal(six.advance_iterator(stream), '</ul>')149 self.assert_equal(next(stream), '<ul>')150 self.assert_equal(next(stream), '<li>1 - 0</li>')151 self.assert_equal(next(stream), '<li>2 - 1</li>')152 self.assert_equal(next(stream), '<li>3 - 2</li>')153 self.assert_equal(next(stream), '<li>4 - 3</li>')154 self.assert_equal(next(stream), '</ul>')155156 def test_buffered_streaming(self):157 tmpl = env.from_string("<ul>{% for item in seq %}<li>{{ loop.index "158 "}} - {{ item }}</li>{%- endfor %}</ul>")159 stream = tmpl.stream(seq=list(range(4)))160 stream.enable_buffering(size=3)161 self.assert_equal(six.advance_iterator(stream), u'<ul><li>1 - 0</li><li>2 - 1</li>')162 self.assert_equal(six.advance_iterator(stream), u'<li>3 - 2</li><li>4 - 3</li></ul>')161 self.assert_equal(next(stream), u'<ul><li>1 - 0</li><li>2 - 1</li>')162 self.assert_equal(next(stream), u'<li>3 - 2</li><li>4 - 3</li></ul>')163164 def test_streaming_behavior(self):165 tmpl = env.from_string("")166 stream = tmpl.stream()
95 unmodified lines
modified:jinja2/testsuite/ext.py+3 added-2 removed
7 unmodified lines
8 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""11import re12import six13import unittest1415from jinja2.testsuite import JinjaTestCase1617from jinja2 import Environment, DictLoader, contextfunction, nodes18from jinja2.exceptions import TemplateAssertionError19from jinja2.ext import Extension20from jinja2.lexer import Token, count_newlines20import six21from jinja2._compat import next22from six import BytesIO2324importable_object = 2325
85 unmodified lines
111 nodes.EnvironmentAttribute('sandboxed'),112 self.attr('ext_attr'),113 nodes.ImportedName(__name__ + '.importable_object'),114 nodes.ContextReference()114 ])]).set_lineno(six.advance_iterator(parser.stream).lineno)115 ])]).set_lineno(next(parser.stream).lineno)116117 def _dump(self, sandboxed, ext_attr, imported_object, context):118 return '%s|%s|%s|%s' % (119 sandboxed,
342 unmodified lines
modified:jinja2/testsuite/lexnparse.py+5 added-4 removed
7 unmodified lines
8 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""11import sys12import six13import unittest1415from jinja2.testsuite import JinjaTestCase1617from jinja2 import Environment, Template, TemplateSyntaxError, \18 UndefinedError, nodes19from jinja2._compat import next20from jinja2.lexer import Token, TokenStream, TOKEN_EOF, TOKEN_BLOCK_BEGIN, TOKEN_BLOCK_END19import six2122env = Environment()2324
14 unmodified lines
39 ts = TokenStream(self.test_tokens, "foo", "bar")40 assert ts.current.type is TOKEN_BLOCK_BEGIN41 assert bool(ts)42 assert not bool(ts.eos)42 six.advance_iterator(ts)43 next(ts)44 assert ts.current.type is TOKEN_BLOCK_END45 assert bool(ts)46 assert not bool(ts.eos)46 six.advance_iterator(ts)47 next(ts)48 assert ts.current.type is TOKEN_EOF49 assert not bool(ts)50 assert bool(ts.eos)51
46 unmodified lines
98 for test, expect in six.iteritems(operators):99 if test in '([{}])':100 continue101 stream = env.lexer.tokenize('{{ %s }}' % test)101 six.advance_iterator(stream)102 next(stream)103 assert stream.current.type == expect104105 def test_normalizing(self):106 for seq in '\r', '\r\n', '\n':
488 unmodified lines
modified:jinja2/_compat.py+4 added-4 removed
9 unmodified lines
1011 :copyright: Copyright 2013 by the Jinja team, see AUTHORS.12 :license: BSD, see LICENSE for details.13"""14import six1516# https://bitbucket.org/gutworth/six/issue/25/add-unichr17try:18 unichr = unichr # py219except NameError:20 unichr = chr # py32121try:22 range_type = xrange23except NameError:24 range_type = range22range_type = six.moves.xrange23next = six.advance_iterator24imap = six.moves.map
modified:jinja2/compiler.py+4 added-3 removed
6 unmodified lines
78 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10"""11import six1213from itertools import chain14from copy import deepcopy15from jinja2 import nodes16from jinja2.nodes import EvalContext17from jinja2.visitor import NodeVisitor18from jinja2.exceptions import TemplateAssertionError19from jinja2.utils import Markup, concat, escape, is_python_keyword18from jinja2._compat import range_type19import six20from jinja2._compat import range_type, next21from six.moves import cStringIO as StringIO, map222324operators = {
1334 unmodified lines
1359 if frame.toplevel:1360 public_names = [x for x in assignment_frame.toplevel_assignments1361 if not x.startswith('_')]1362 if len(assignment_frame.toplevel_assignments) == 1:1362 name = six.advance_iterator(iter(assignment_frame.toplevel_assignments))1363 name = next(iter(assignment_frame.toplevel_assignments))1364 self.writeline('context.vars[%r] = l_%s' % (name, name))1365 else:1366 self.writeline('context.vars.update({')1367 for idx, name in enumerate(assignment_frame.toplevel_assignments):
281 unmodified lines
modified:jinja2/ext.py+13 added-12 removed
18 unmodified lines
19from jinja2.environment import Environment20from jinja2.runtime import concat21from jinja2.exceptions import TemplateAssertionError, TemplateSyntaxError22from jinja2.utils import contextfunction, import_string, Markup23from jinja2._compat import next24import six252627# the only real useful gettext functions for a Jinja template. Note
187 unmodified lines
215 return extract_from_ast(source, gettext_functions)216217 def parse(self, parser):218 """Parse a translatable tag."""218 lineno = six.advance_iterator(parser.stream).lineno219 lineno = next(parser.stream).lineno220 num_called_num = False221222 # find all the variables referenced. Additionally a variable can be223 # defined in the body of the trans block too, but this is checked at
16 unmodified lines
240 exc=TemplateAssertionError)241242 # expressions243 if parser.stream.current.type == 'assign':243 six.advance_iterator(parser.stream)244 next(parser.stream)245 variables[name.value] = var = parser.parse_expression()246 else:247 variables[name.value] = var = nodes.Name(name.value, 'load')248
23 unmodified lines
272273 # if we have a pluralize block, we parse that too274 if parser.stream.current.test('name:pluralize'):275 have_plural = True275 six.advance_iterator(parser.stream)276 next(parser.stream)277 if parser.stream.current.type != 'block_end':278 name = parser.stream.expect('name')279 if name.value not in variables:280 parser.fail('unknown variable %r for pluralization' %
2 unmodified lines
283 plural_expr = variables[name.value]284 num_called_num = name.value == 'num'285 parser.stream.expect('block_end')286 plural_names, plural = self._parse_block(parser, False)286 six.advance_iterator(parser.stream)287 next(parser.stream)288 referenced.update(plural_names)289 else:289 six.advance_iterator(parser.stream)290 next(parser.stream)291292 # register free names as simple name expressions293 for var in referenced:294 if var not in variables:
19 unmodified lines
314 buf = []315 while 1:316 if parser.stream.current.type == 'data':317 buf.append(parser.stream.current.value.replace('%', '%%'))317 six.advance_iterator(parser.stream)318 next(parser.stream)319 elif parser.stream.current.type == 'variable_begin':319 six.advance_iterator(parser.stream)320 next(parser.stream)321 name = parser.stream.expect('name').value322 referenced.append(name)323 buf.append('%%(%s)s' % name)324 parser.stream.expect('variable_end')325 elif parser.stream.current.type == 'block_begin':325 six.advance_iterator(parser.stream)326 next(parser.stream)327 if parser.stream.current.test('name:endtrans'):328 break329 elif parser.stream.current.test('name:pluralize'):330 if allow_pluralize:
64 unmodified lines
395 """396 tags = set(['do'])397398 def parse(self, parser):398 node = nodes.ExprStmt(lineno=six.advance_iterator(parser.stream).lineno)399 node = nodes.ExprStmt(lineno=next(parser.stream).lineno)400 node.node = parser.parse_tuple()401 return node402403
1 unmodified line
405 """Adds break and continue to the template engine."""406 tags = set(['break', 'continue'])407408 def parse(self, parser):408 token = six.advance_iterator(parser.stream)409 token = next(parser.stream)410 if token.value == 'break':411 return nodes.Break(lineno=token.lineno)412 return nodes.Continue(lineno=token.lineno)413
2 unmodified lines
416 """Adds support for a django-like with block."""417 tags = set(['with'])418419 def parse(self, parser):419 node = nodes.Scope(lineno=six.advance_iterator(parser.stream).lineno)420 node = nodes.Scope(lineno=next(parser.stream).lineno)421 assignments = []422 while parser.stream.current.type != 'block_end':423 lineno = parser.stream.current.lineno424 if assignments:
12 unmodified lines
437 """Changes auto escape rules for a scope."""438 tags = set(['autoescape'])439440 def parse(self, parser):440 node = nodes.ScopedEvalContextModifier(lineno=six.advance_iterator(parser.stream).lineno)441 node = nodes.ScopedEvalContextModifier(lineno=next(parser.stream).lineno)442 node.options = [443 nodes.Keyword('autoescape', parser.parse_expression())444 ]445 node.body = parser.parse_statements(('name:endautoescape',),
193 unmodified lines
modified:jinja2/filters.py+6 added-4 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""11import re12import math13import six1415from random import choice16from operator import itemgetter17from itertools import groupby18from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode, \19 unicode_urlencode20from jinja2.runtime import Undefined21from jinja2.exceptions import FilterArgumentError20import six22from jinja2._compat import next23from six.moves import map242526_word_re = re.compile(r'\w+(?u)')
316 unmodified lines
343@environmentfilter344def do_first(environment, seq):345 """Return the first item of a sequence."""346 try:345 return six.advance_iterator(iter(seq))347 return next(iter(seq))348 except StopIteration:349 return environment.undefined('No first item, sequence was empty.')350351352@environmentfilter353def do_last(environment, seq):354 """Return the last item of a sequence."""355 try:354 return six.advance_iterator(iter(reversed(seq)))356 return next(iter(reversed(seq)))357 except StopIteration:358 return environment.undefined('No last item, sequence was empty.')359360
460 unmodified lines
821 if len(args) == 2 and 'attribute' in kwargs:822 attribute = kwargs.pop('attribute')823 if kwargs:824 raise FilterArgumentError('Unexpected keyword argument %r' %823 six.advance_iterator(iter(kwargs)))825 next(iter(kwargs)))826 func = make_attrgetter(context.environment, attribute)827 else:828 try:829 name = args[2]
156 unmodified lines
modified:jinja2/lexer.py+10 added-8 removed
13 unmodified lines
14 :copyright: (c) 2010 by the Jinja Team.15 :license: BSD, see LICENSE for more details.16"""17import re18import six1920from operator import itemgetter21from collections import deque22from jinja2.exceptions import TemplateSyntaxError23from jinja2.utils import LRUCache22import six24from jinja2._compat import next252627# cache for the lexers. Exists in order to be able to have multiple28# environments with the same lexer
257 unmodified lines
286 token = self.stream.current287 if token.type is TOKEN_EOF:288 self.stream.close()289 raise StopIteration()288 six.advance_iterator(self.stream)290 next(self.stream)291 return token292293294class TokenStream(six.Iterator):
8 unmodified lines
303 self.name = name304 self.filename = filename305 self.closed = False306 self.current = Token(1, TOKEN_INITIAL, '')305 six.advance_iterator(self)307 next(self)308309 def __iter__(self):310 return TokenStreamIterator(self)311
8 unmodified lines
320 self._pushed.append(token)321322 def look(self):323 """Look at the next token."""322 old_token = six.advance_iterator(self)324 old_token = next(self)325 result = self.current326 self.push(result)327 self.current = old_token328 return result329330 def skip(self, n=1):331 """Got n tokens ahead."""332 for x in range(n):331 six.advance_iterator(self)333 next(self)334335 def next_if(self, expr):336 """Perform the token test and return the token if it matched.337 Otherwise the return value is `None`.338 """339 if self.current.test(expr):338 return six.advance_iterator(self)340 return next(self)341342 def skip_if(self, expr):343 """Like :meth:`next_if` but only returns `True` or `False`."""344 return self.next_if(expr) is not None
4 unmodified lines
349 if self._pushed:350 self.current = self._pushed.popleft()351 elif self.current.type is not TOKEN_EOF:352 try:351 self.current = six.advance_iterator(self._iter)353 self.current = next(self._iter)354 except StopIteration:355 self.close()356 return rv357
20 unmodified lines
378 self.name, self.filename)379 try:380 return self.current381 finally:380 six.advance_iterator(self)382 next(self)383384385def get_lexer(environment):386 """Return a lexer which is probably cached."""
351 unmodified lines
modified:jinja2/nodes.py+4 added-2 removed
10 unmodified lines
1112 :copyright: (c) 2010 by the Jinja Team.13 :license: BSD, see LICENSE for more details.14"""15import six16import operator1718from collections import deque19from jinja2.utils import Markup, MethodType, FunctionType18import six20from jinja2._compat import next21from six.moves import zip222324#: the types we support for context functions
119 unmodified lines
144 for attr in self.attributes:145 setattr(self, attr, attributes.pop(attr, None))146 if attributes:147 raise TypeError('unknown attribute %r' %146 six.advance_iterator(iter(attributes)))148 next(iter(attributes)))149150 def iter_fields(self, exclude=None, only=None):151 """This method iterates over all fields that are defined and yields152 ``(key, value)`` tuples. Per default all fields are returned, but
761 unmodified lines
modified:jinja2/parser.py+49 added-50 removed
9 unmodified lines
10"""11from jinja2 import nodes12from jinja2.exceptions import TemplateSyntaxError, TemplateAssertionError13from jinja2.lexer import describe_token, describe_token_expr14import six15from six.moves import map14from jinja2._compat import next, imap151617#: statements that callinto 18_statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',
33 unmodified lines
5253 def _fail_ut_eof(self, name, end_token_stack, lineno):54 expected = []55 for exprs in end_token_stack:57 expected.extend(map(describe_token_expr, exprs))56 expected.extend(imap(describe_token_expr, exprs))57 if end_token_stack:58 currently_looking = ' or '.join(59 "'%s'" % describe_token_expr(expr)60 for expr in end_token_stack[-1])
100 unmodified lines
161 if self.stream.current.type == 'eof':162 self.fail_eof(end_tokens)163164 if drop_needle:166 six.advance_iterator(self.stream)165 next(self.stream)166 return result167168 def parse_set(self):169 """Parse an assign statement."""171 lineno = six.advance_iterator(self.stream).lineno170 lineno = next(self.stream).lineno171 target = self.parse_assign_target()172 self.stream.expect('assign')173 expr = self.parse_tuple()174 return nodes.Assign(target, expr, lineno=lineno)
9 unmodified lines
184 if self.stream.skip_if('name:if'):185 test = self.parse_expression()186 recursive = self.stream.skip_if('name:recursive')187 body = self.parse_statements(('name:endfor', 'name:else'))189 if six.advance_iterator(self.stream).value == 'endfor':188 if next(self.stream).value == 'endfor':189 else_ = []190 else:191 else_ = self.parse_statements(('name:endfor',), drop_needle=True)192 return nodes.For(target, iter, body, else_, test,
5 unmodified lines
198 while 1:199 node.test = self.parse_tuple(with_condexpr=False)200 node.body = self.parse_statements(('name:elif', 'name:else',201 'name:endif'))203 token = six.advance_iterator(self.stream)202 token = next(self.stream)203 if token.test('name:elif'):204 new_node = nodes.If(lineno=self.stream.current.lineno)205 node.else_ = [new_node]206 node = new_node
6 unmodified lines
213 break214 return result215216 def parse_block(self):218 node = nodes.Block(lineno=six.advance_iterator(self.stream).lineno)217 node = nodes.Block(lineno=next(self.stream).lineno)218 node.name = self.stream.expect('name').value219 node.scoped = self.stream.skip_if('name:scoped')220221 # common problem people encounter when switching from django
8 unmodified lines
230 self.stream.skip_if('name:' + node.name)231 return node232233 def parse_extends(self):235 node = nodes.Extends(lineno=six.advance_iterator(self.stream).lineno)234 node = nodes.Extends(lineno=next(self.stream).lineno)235 node.template = self.parse_expression()236 return node237238 def parse_import_context(self, node, default):239 if self.stream.current.test_any('name:with', 'name:without') and \240 self.stream.look().test('name:context'):242 node.with_context = six.advance_iterator(self.stream).value == 'with'241 node.with_context = next(self.stream).value == 'with'242 self.stream.skip()243 else:244 node.with_context = default245 return node246247 def parse_include(self):249 node = nodes.Include(lineno=six.advance_iterator(self.stream).lineno)248 node = nodes.Include(lineno=next(self.stream).lineno)249 node.template = self.parse_expression()250 if self.stream.current.test('name:ignore') and \251 self.stream.look().test('name:missing'):252 node.ignore_missing = True
2 unmodified lines
255 node.ignore_missing = False256 return self.parse_import_context(node, True)257258 def parse_import(self):260 node = nodes.Import(lineno=six.advance_iterator(self.stream).lineno)259 node = nodes.Import(lineno=next(self.stream).lineno)260 node.template = self.parse_expression()261 self.stream.expect('name:as')262 node.target = self.parse_assign_target(name_only=True).name263 return self.parse_import_context(node, False)264265 def parse_from(self):267 node = nodes.FromImport(lineno=six.advance_iterator(self.stream).lineno)266 node = nodes.FromImport(lineno=next(self.stream).lineno)267 node.template = self.parse_expression()268 self.stream.expect('name:import')269 node.names = []270271 def parse_context():272 if self.stream.current.value in ('with', 'without') and \273 self.stream.look().test('name:context'):275 node.with_context = six.advance_iterator(self.stream).value == 'with'274 node.with_context = next(self.stream).value == 'with'275 self.stream.skip()276 return True277 return False278
36 unmodified lines
315 args.append(arg)316 self.stream.expect('rparen')317318 def parse_call_block(self):320 node = nodes.CallBlock(lineno=six.advance_iterator(self.stream).lineno)319 node = nodes.CallBlock(lineno=next(self.stream).lineno)320 if self.stream.current.type == 'lparen':321 self.parse_signature(node)322 else:323 node.args = []
5 unmodified lines
329 node.body = self.parse_statements(('name:endcall',), drop_needle=True)330 return node331332 def parse_filter_block(self):334 node = nodes.FilterBlock(lineno=six.advance_iterator(self.stream).lineno)333 node = nodes.FilterBlock(lineno=next(self.stream).lineno)334 node.filter = self.parse_filter(None, start_inline=True)335 node.body = self.parse_statements(('name:endfilter',),336 drop_needle=True)337 return node338339 def parse_macro(self):341 node = nodes.Macro(lineno=six.advance_iterator(self.stream).lineno)340 node = nodes.Macro(lineno=next(self.stream).lineno)341 node.name = self.parse_assign_target(name_only=True).name342 self.parse_signature(node)343 node.body = self.parse_statements(('name:endmacro',),344 drop_needle=True)345 return node346347 def parse_print(self):349 node = nodes.Output(lineno=six.advance_iterator(self.stream).lineno)348 node = nodes.Output(lineno=next(self.stream).lineno)349 node.nodes = []350 while self.stream.current.type != 'block_end':351 if node.nodes:352 self.stream.expect('comma')
65 unmodified lines
418 return left419420 def parse_not(self):421 if self.stream.current.test('name:not'):423 lineno = six.advance_iterator(self.stream).lineno422 lineno = next(self.stream).lineno423 return nodes.Not(self.parse_not(), lineno=lineno)424 return self.parse_compare()425426 def parse_compare(self):
2 unmodified lines
429 ops = []430 while 1:431 token_type = self.stream.current.type432 if token_type in _compare_operators:434 six.advance_iterator(self.stream)433 next(self.stream)434 ops.append(nodes.Operand(token_type, self.parse_add()))435 elif self.stream.skip_if('name:in'):436 ops.append(nodes.Operand('in', self.parse_add()))437 elif self.stream.current.test('name:not') and \
10 unmodified lines
448 def parse_add(self):449 lineno = self.stream.current.lineno450 left = self.parse_sub()451 while self.stream.current.type == 'add':453 six.advance_iterator(self.stream)452 next(self.stream)453 right = self.parse_sub()454 left = nodes.Add(left, right, lineno=lineno)455 lineno = self.stream.current.lineno456 return left
1 unmodified line
458 def parse_sub(self):459 lineno = self.stream.current.lineno460 left = self.parse_concat()461 while self.stream.current.type == 'sub':463 six.advance_iterator(self.stream)462 next(self.stream)463 right = self.parse_concat()464 left = nodes.Sub(left, right, lineno=lineno)465 lineno = self.stream.current.lineno466 return left
1 unmodified line
468 def parse_concat(self):469 lineno = self.stream.current.lineno470 args = [self.parse_mul()]471 while self.stream.current.type == 'tilde':473 six.advance_iterator(self.stream)472 next(self.stream)473 args.append(self.parse_mul())474 if len(args) == 1:475 return args[0]476 return nodes.Concat(args, lineno=lineno)
1 unmodified line
478 def parse_mul(self):479 lineno = self.stream.current.lineno480 left = self.parse_div()481 while self.stream.current.type == 'mul':483 six.advance_iterator(self.stream)482 next(self.stream)483 right = self.parse_div()484 left = nodes.Mul(left, right, lineno=lineno)485 lineno = self.stream.current.lineno486 return left
1 unmodified line
488 def parse_div(self):489 lineno = self.stream.current.lineno490 left = self.parse_floordiv()491 while self.stream.current.type == 'div':493 six.advance_iterator(self.stream)492 next(self.stream)493 right = self.parse_floordiv()494 left = nodes.Div(left, right, lineno=lineno)495 lineno = self.stream.current.lineno496 return left
1 unmodified line
498 def parse_floordiv(self):499 lineno = self.stream.current.lineno500 left = self.parse_mod()501 while self.stream.current.type == 'floordiv':503 six.advance_iterator(self.stream)502 next(self.stream)503 right = self.parse_mod()504 left = nodes.FloorDiv(left, right, lineno=lineno)505 lineno = self.stream.current.lineno506 return left
1 unmodified line
508 def parse_mod(self):509 lineno = self.stream.current.lineno510 left = self.parse_pow()511 while self.stream.current.type == 'mod':513 six.advance_iterator(self.stream)512 next(self.stream)513 right = self.parse_pow()514 left = nodes.Mod(left, right, lineno=lineno)515 lineno = self.stream.current.lineno516 return left
1 unmodified line
518 def parse_pow(self):519 lineno = self.stream.current.lineno520 left = self.parse_unary()521 while self.stream.current.type == 'pow':523 six.advance_iterator(self.stream)522 next(self.stream)523 right = self.parse_unary()524 left = nodes.Pow(left, right, lineno=lineno)525 lineno = self.stream.current.lineno526 return left
1 unmodified line
528 def parse_unary(self, with_filter=True):529 token_type = self.stream.current.type530 lineno = self.stream.current.lineno531 if token_type == 'sub':533 six.advance_iterator(self.stream)532 next(self.stream)533 node = nodes.Neg(self.parse_unary(False), lineno=lineno)534 elif token_type == 'add':536 six.advance_iterator(self.stream)535 next(self.stream)536 node = nodes.Pos(self.parse_unary(False), lineno=lineno)537 else:538 node = self.parse_primary()539 node = self.parse_postfix(node)
10 unmodified lines
550 elif token.value in ('none', 'None'):551 node = nodes.Const(None, lineno=token.lineno)552 else:553 node = nodes.Name(token.value, 'load', lineno=token.lineno)555 six.advance_iterator(self.stream)554 next(self.stream)555 elif token.type == 'string':557 six.advance_iterator(self.stream)556 next(self.stream)557 buf = [token.value]558 lineno = token.lineno559 while self.stream.current.type == 'string':560 buf.append(self.stream.current.value)562 six.advance_iterator(self.stream)561 next(self.stream)562 node = nodes.Const(''.join(buf), lineno=lineno)563 elif token.type in ('integer', 'float'):565 six.advance_iterator(self.stream)564 next(self.stream)565 node = nodes.Const(token.value, lineno=token.lineno)566 elif token.type == 'lparen':568 six.advance_iterator(self.stream)567 next(self.stream)568 node = self.parse_tuple(explicit_parentheses=True)569 self.stream.expect('rparen')570 elif token.type == 'lbracket':571 node = self.parse_list()
113 unmodified lines
685 break686 return node687688 def parse_subscript(self, node):690 token = six.advance_iterator(self.stream)689 token = next(self.stream)690 if token.type == 'dot':691 attr_token = self.stream.current693 six.advance_iterator(self.stream)692 next(self.stream)693 if attr_token.type == 'name':694 return nodes.Getattr(node, attr_token.value, 'load',695 lineno=token.lineno)696 elif attr_token.type != 'integer':
17 unmodified lines
714 def parse_subscribed(self):715 lineno = self.stream.current.lineno716717 if self.stream.current.type == 'colon':719 six.advance_iterator(self.stream)718 next(self.stream)719 args = [None]720 else:721 node = self.parse_expression()722 if self.stream.current.type != 'colon':723 return node725 six.advance_iterator(self.stream)724 next(self.stream)725 args = [node]726727 if self.stream.current.type == 'colon':728 args.append(None)
2 unmodified lines
731 else:732 args.append(None)733734 if self.stream.current.type == 'colon':736 six.advance_iterator(self.stream)735 next(self.stream)736 if self.stream.current.type not in ('rbracket', 'comma'):737 args.append(self.parse_expression())738 else:739 args.append(None)
21 unmodified lines
761 if self.stream.current.type == 'rparen':762 break763 if self.stream.current.type == 'mul':764 ensure(dyn_args is None and dyn_kwargs is None)766 six.advance_iterator(self.stream)765 next(self.stream)766 dyn_args = self.parse_expression()767 elif self.stream.current.type == 'pow':768 ensure(dyn_kwargs is None)770 six.advance_iterator(self.stream)769 next(self.stream)770 dyn_kwargs = self.parse_expression()771 else:772 ensure(dyn_args is None and dyn_kwargs is None)773 if self.stream.current.type == 'name' and \
17 unmodified lines
791792 def parse_filter(self, node, start_inline=False):793 while self.stream.current.type == 'pipe' or start_inline:794 if not start_inline:796 six.advance_iterator(self.stream)795 next(self.stream)796 token = self.stream.expect('name')797 name = token.value798 while self.stream.current.type == 'dot':800 six.advance_iterator(self.stream)799 next(self.stream)800 name += '.' + self.stream.expect('name').value801 if self.stream.current.type == 'lparen':802 args, kwargs, dyn_args, dyn_kwargs = self.parse_call(None)803 else:
5 unmodified lines
809 start_inline = False810 return node811812 def parse_test(self, node):814 token = six.advance_iterator(self.stream)813 token = next(self.stream)814 if self.stream.current.test('name:not'):816 six.advance_iterator(self.stream)815 next(self.stream)816 negated = True817 else:818 negated = False819 name = self.stream.expect('name').value820 while self.stream.current.type == 'dot':822 six.advance_iterator(self.stream)821 next(self.stream)822 name += '.' + self.stream.expect('name').value823 dyn_args = dyn_kwargs = None824 kwargs = []825 if self.stream.current.type == 'lparen':
34 unmodified lines
860 if token.type == 'data':861 if token.value:862 add_data(nodes.TemplateData(token.value,863 lineno=token.lineno))865 six.advance_iterator(self.stream)864 next(self.stream)865 elif token.type == 'variable_begin':867 six.advance_iterator(self.stream)866 next(self.stream)867 add_data(self.parse_tuple(with_condexpr=True))868 self.stream.expect('variable_end')869 elif token.type == 'block_begin':870 flush_data()872 six.advance_iterator(self.stream)871 next(self.stream)872 if end_tokens is not None and \873 self.stream.current.test_any(*end_tokens):874 return body875 rv = self.parse_statement()
20 unmodified lines
modified:jinja2/runtime.py+2 added-1 removed
12 unmodified lines
13from jinja2.utils import Markup, soft_unicode, escape, missing, concat, \14 internalcode, object_type_repr15from jinja2.exceptions import UndefinedError, TemplateRuntimeError, \16 TemplateNotFound17from jinja2._compat import next18import six19from six.moves import map2021
298 unmodified lines
320 return LoopContextIterator(self)321322 def _safe_next(self):323 try:323 return six.advance_iterator(self._iterator)324 return next(self._iterator)325 except StopIteration:326 return _last_iteration327328 @internalcode
251 unmodified lines