Skip to content
Myr

Use partial(next, ...) instead get_next()

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

authored by Sebastian Noack · committed by Sebastian Noack · parent 6bf78bc · Browse files · 2 files+23 added−26 removed
This commit

State

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

Diff stats

2 files+23 added−26 removed

  • other:+23 added−26 removed

2 files+23 added−26 removed

modified:jinja2/_compat.py-3 removed
43 unmodified lines
4445 implements_iterator = _identity46 implements_to_string = _identity47 encode_filename = _identity48 get_next = lambda x: x.__next__4849else:50 unichr = unichr51 text_type = unicode
23 unmodified lines
75 cls.__unicode__ = cls.__str__76 cls.__str__ = lambda x: x.__unicode__().encode('utf-8')77 return cls7880 get_next = lambda x: x.next8179 def encode_filename(filename):80 if isinstance(filename, unicode):81 return filename.encode('utf-8')82 return filename
26 unmodified lines
modified:jinja2/environment.py+23 added-23 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""11import os12import sys13from functools import reduce, partial14from jinja2 import nodes15from jinja2.defaults import BLOCK_START_STRING, \16 BLOCK_END_STRING, VARIABLE_START_STRING, VARIABLE_END_STRING, \17 COMMENT_START_STRING, COMMENT_END_STRING, LINE_STATEMENT_PREFIX, \
11 unmodified lines
29from jinja2.utils import import_string, LRUCache, Markup, missing, \30 concat, consume, internalcode31from jinja2._compat import imap, ifilter, string_types, iteritems, \32 text_type, reraise, implements_iterator, implements_to_string, \32 get_next, encode_filename, PY2, PYPY33from functools import reduce33 encode_filename, PY2, PYPY343536# for direct template usage we have up to ten living environments37_spontaneous_environments = LRUCache(10)
1132 unmodified lines
1170 fp.close()11711172 def disable_buffering(self):1173 """Disable the output buffering."""1174 self._next = get_next(self._gen)1174 self._next = partial(next, self._gen)1175 self.buffered = False11761177 def _buffered_generator(self, size):1178 buf = []1179 c_size = 01180 push = buf.append11811182 while 1:1183 try:1184 while c_size < size:1185 c = next(self._gen)1186 push(c)1187 if c:1188 c_size += 11189 except StopIteration:1190 if not c_size:1191 return1192 yield concat(buf)1193 del buf[:]1194 c_size = 011951196 def enable_buffering(self, size=5):1197 """Enable buffering. Buffer `size` items before yielding them."""1198 if size <= 1:1199 raise ValueError('buffer size too small')12001182 def generator(next):1183 buf = []1184 c_size = 01185 push = buf.append11861187 while 1:1188 try:1189 while c_size < size:1190 c = next()1191 push(c)1192 if c:1193 c_size += 11194 except StopIteration:1195 if not c_size:1196 return1197 yield concat(buf)1198 del buf[:]1199 c_size = 012001201 self.buffered = True1202 self._next = get_next(generator(get_next(self._gen)))1202 self._next = partial(next, self._buffered_generator(size))12031204 def __iter__(self):1205 return self1206
7 unmodified lines