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
Provenance
- Commit
c002261- Tree
6e9a3ec- Author
Sebastian Noack <sebastian.noack@gmail.com>- Committer
Sebastian Noack <sebastian.noack@gmail.com>- Parent
6bf78bc
2 files changed+23 added−26 removed
modified:jinja2/_compat.py-3 removed
43 unmodified lines44 45 implements_iterator = _identity46 implements_to_string = _identity47 encode_filename = _identity48- get_next = lambda x: x.__next__48 49 else:50 unichr = unichr51 text_type = unicode23 unmodified lines75 cls.__unicode__ = cls.__str__76 cls.__str__ = lambda x: x.__unicode__().encode('utf-8')77 return cls78 80- get_next = lambda x: x.next81-79 def encode_filename(filename):80 if isinstance(filename, unicode):81 return filename.encode('utf-8')82 return filename26 unmodified linesmodified:jinja2/environment.py+23 added-23 removed
8 unmodified lines9 :license: BSD, see LICENSE for more details.10 """11 import os12 import sys13+from functools import reduce, partial14 from jinja2 import nodes15 from 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 lines29 from jinja2.utils import import_string, LRUCache, Markup, missing, \30 concat, consume, internalcode31 from jinja2._compat import imap, ifilter, string_types, iteritems, \32 text_type, reraise, implements_iterator, implements_to_string, \32- get_next, encode_filename, PY2, PYPY33-from functools import reduce33+ encode_filename, PY2, PYPY34 35 36 # for direct template usage we have up to ten living environments37 _spontaneous_environments = LRUCache(10)1132 unmodified lines1170 fp.close()1171 1172 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 = False1176 1177+ def _buffered_generator(self, size):1178+ buf = []1179+ c_size = 01180+ push = buf.append1181+1182+ 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 = 01195+1196 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')1200 1182- def generator(next):1183- buf = []1184- c_size = 01185- push = buf.append1186-1187- 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 = 01200-1201 self.buffered = True1202- self._next = get_next(generator(get_next(self._gen)))1202+ self._next = partial(next, self._buffered_generator(size))1203 1204 def __iter__(self):1205 return self1206 7 unmodified lines