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
Provenance
- Commit
c87d4cf- Tree
a7f074a- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
5cf3168
11 files changed+113 added−103 removed
modified:jinja2/testsuite/api.py+13 added-13 removed
12 unmodified lines13 import tempfile14 import shutil15 16 from jinja2.testsuite import JinjaTestCase17+from jinja2._compat import next18 19 from jinja2 import Environment, Undefined, DebugUndefined, \20 StrictUndefined, UndefinedError, meta, \21 is_undefined, Template, DictLoader22 from jinja2.utils import Cycler22-import six23 24 env = Environment()25 26 26 unmodified lines53 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 lines110 111 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) == []117 118 ast = env.parse('{% extends "layout.html" %}'119 '{% from "test.html" import a, b as c %}'25 unmodified lines145 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>')155 156 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>')163 164 def test_streaming_behavior(self):165 tmpl = env.from_string("")166 stream = tmpl.stream()95 unmodified linesmodified:jinja2/testsuite/ext.py+3 added-2 removed
7 unmodified lines8 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10 """11 import re12+import six13 import unittest14 15 from jinja2.testsuite import JinjaTestCase16 17 from jinja2 import Environment, DictLoader, contextfunction, nodes18 from jinja2.exceptions import TemplateAssertionError19 from jinja2.ext import Extension20 from jinja2.lexer import Token, count_newlines20-import six21+from jinja2._compat import next22 from six import BytesIO23 24 importable_object = 2325 85 unmodified lines111 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)116 117 def _dump(self, sandboxed, ext_attr, imported_object, context):118 return '%s|%s|%s|%s' % (119 sandboxed,342 unmodified linesmodified:jinja2/testsuite/lexnparse.py+5 added-4 removed
7 unmodified lines8 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10 """11 import sys12+import six13 import unittest14 15 from jinja2.testsuite import JinjaTestCase16 17 from jinja2 import Environment, Template, TemplateSyntaxError, \18 UndefinedError, nodes19+from jinja2._compat import next20 from jinja2.lexer import Token, TokenStream, TOKEN_EOF, TOKEN_BLOCK_BEGIN, TOKEN_BLOCK_END19-import six21 22 env = Environment()23 24 14 unmodified lines39 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 lines98 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 == expect104 105 def test_normalizing(self):106 for seq in '\r', '\r\n', '\n':488 unmodified linesmodified:jinja2/_compat.py+4 added-4 removed
9 unmodified lines10 11 :copyright: Copyright 2013 by the Jinja team, see AUTHORS.12 :license: BSD, see LICENSE for details.13 """14+import six15 16 # https://bitbucket.org/gutworth/six/issue/25/add-unichr17 try:18 unichr = unichr # py219 except NameError:20 unichr = chr # py321 21-try:22- range_type = xrange23-except NameError:24- range_type = range22+range_type = six.moves.xrange23+next = six.advance_iterator24+imap = six.moves.mapmodified:jinja2/compiler.py+4 added-3 removed
6 unmodified lines7 8 :copyright: (c) 2010 by the Jinja Team.9 :license: BSD, see LICENSE for more details.10 """11+import six12+13 from itertools import chain14 from copy import deepcopy15 from jinja2 import nodes16 from jinja2.nodes import EvalContext17 from jinja2.visitor import NodeVisitor18 from jinja2.exceptions import TemplateAssertionError19 from jinja2.utils import Markup, concat, escape, is_python_keyword18-from jinja2._compat import range_type19-import six20+from jinja2._compat import range_type, next21 from six.moves import cStringIO as StringIO, map22 23 24 operators = {1334 unmodified lines1359 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 linesmodified:jinja2/ext.py+13 added-12 removed
18 unmodified lines19 from jinja2.environment import Environment20 from jinja2.runtime import concat21 from jinja2.exceptions import TemplateAssertionError, TemplateSyntaxError22 from jinja2.utils import contextfunction, import_string, Markup23+from jinja2._compat import next24 import six25 26 27 # the only real useful gettext functions for a Jinja template. Note187 unmodified lines215 return extract_from_ast(source, gettext_functions)216 217 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 = False221 222 # find all the variables referenced. Additionally a variable can be223 # defined in the body of the trans block too, but this is checked at16 unmodified lines240 exc=TemplateAssertionError)241 242 # 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 lines272 273 # 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 lines283 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)291 292 # register free names as simple name expressions293 for var in referenced:294 if var not in variables:19 unmodified lines314 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 lines395 """396 tags = set(['do'])397 398 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 node402 403 1 unmodified line405 """Adds break and continue to the template engine."""406 tags = set(['break', 'continue'])407 408 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 lines416 """Adds support for a django-like with block."""417 tags = set(['with'])418 419 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 lines437 """Changes auto escape rules for a scope."""438 tags = set(['autoescape'])439 440 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 linesmodified:jinja2/filters.py+6 added-4 removed
8 unmodified lines9 :license: BSD, see LICENSE for more details.10 """11 import re12 import math13+import six14+15 from random import choice16 from operator import itemgetter17 from itertools import groupby18 from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode, \19 unicode_urlencode20 from jinja2.runtime import Undefined21 from jinja2.exceptions import FilterArgumentError20-import six22+from jinja2._compat import next23 from six.moves import map24 25 26 _word_re = re.compile(r'\w+(?u)')316 unmodified lines343 @environmentfilter344 def 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.')350 351 352 @environmentfilter353 def 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.')359 360 460 unmodified lines821 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 linesmodified:jinja2/lexer.py+10 added-8 removed
13 unmodified lines14 :copyright: (c) 2010 by the Jinja Team.15 :license: BSD, see LICENSE for more details.16 """17 import re18+import six19+20 from operator import itemgetter21 from collections import deque22 from jinja2.exceptions import TemplateSyntaxError23 from jinja2.utils import LRUCache22-import six24+from jinja2._compat import next25 26 27 # cache for the lexers. Exists in order to be able to have multiple28 # environments with the same lexer257 unmodified lines286 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 token292 293 294 class TokenStream(six.Iterator):8 unmodified lines303 self.name = name304 self.filename = filename305 self.closed = False306 self.current = Token(1, TOKEN_INITIAL, '')305- six.advance_iterator(self)307+ next(self)308 309 def __iter__(self):310 return TokenStreamIterator(self)311 8 unmodified lines320 self._pushed.append(token)321 322 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 result329 330 def skip(self, n=1):331 """Got n tokens ahead."""332 for x in range(n):331- six.advance_iterator(self)333+ next(self)334 335 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)341 342 def skip_if(self, expr):343 """Like :meth:`next_if` but only returns `True` or `False`."""344 return self.next_if(expr) is not None4 unmodified lines349 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 lines378 self.name, self.filename)379 try:380 return self.current381 finally:380- six.advance_iterator(self)382+ next(self)383 384 385 def get_lexer(environment):386 """Return a lexer which is probably cached."""351 unmodified linesmodified:jinja2/nodes.py+4 added-2 removed
10 unmodified lines11 12 :copyright: (c) 2010 by the Jinja Team.13 :license: BSD, see LICENSE for more details.14 """15+import six16 import operator17+18 from collections import deque19 from jinja2.utils import Markup, MethodType, FunctionType18-import six20+from jinja2._compat import next21 from six.moves import zip22 23 24 #: the types we support for context functions119 unmodified lines144 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)))149 150 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, but761 unmodified linesmodified:jinja2/parser.py+49 added-50 removed
9 unmodified lines10 """11 from jinja2 import nodes12 from jinja2.exceptions import TemplateSyntaxError, TemplateAssertionError13 from jinja2.lexer import describe_token, describe_token_expr14-import six15-from six.moves import map14+from jinja2._compat import next, imap15 16 17 #: statements that callinto 18 _statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',33 unmodified lines52 53 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 lines161 if self.stream.current.type == 'eof':162 self.fail_eof(end_tokens)163 164 if drop_needle:166- six.advance_iterator(self.stream)165+ next(self.stream)166 return result167 168 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 lines184 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 lines198 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_node6 unmodified lines213 break214 return result215 216 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')220 221 # common problem people encounter when switching from django8 unmodified lines230 self.stream.skip_if('name:' + node.name)231 return node232 233 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 node237 238 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 node246 247 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 = True2 unmodified lines255 node.ignore_missing = False256 return self.parse_import_context(node, True)257 258 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)264 265 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 = []270 271 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 lines315 args.append(arg)316 self.stream.expect('rparen')317 318 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 lines329 node.body = self.parse_statements(('name:endcall',), drop_needle=True)330 return node331 332 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 node338 339 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 node346 347 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 lines418 return left419 420 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()425 426 def parse_compare(self):2 unmodified lines429 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 lines448 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 left1 unmodified line458 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 left1 unmodified line468 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 line478 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 left1 unmodified line488 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 left1 unmodified line498 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 left1 unmodified line508 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 left1 unmodified line518 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 left1 unmodified line528 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 lines550 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 lines685 break686 return node687 688 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 lines714 def parse_subscribed(self):715 lineno = self.stream.current.lineno716 717 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]726 727 if self.stream.current.type == 'colon':728 args.append(None)2 unmodified lines731 else:732 args.append(None)733 734 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 lines761 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 lines791 792 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 lines809 start_inline = False810 return node811 812 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 lines860 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 linesmodified:jinja2/runtime.py+2 added-1 removed
12 unmodified lines13 from jinja2.utils import Markup, soft_unicode, escape, missing, concat, \14 internalcode, object_type_repr15 from jinja2.exceptions import UndefinedError, TemplateRuntimeError, \16 TemplateNotFound17+from jinja2._compat import next18 import six19 from six.moves import map20 21 298 unmodified lines320 return LoopContextIterator(self)321 322 def _safe_next(self):323 try:323- return six.advance_iterator(self._iterator)324+ return next(self._iterator)325 except StopIteration:326 return _last_iteration327 328 @internalcode251 unmodified lines