Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templateutil.py @ 37280:671a01cd50b5
templater: extract private function to evaluate generator to byte string
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 23 Mar 2018 21:40:16 +0900 |
parents | 9e8128e84326 |
children | 26f6fc179e62 |
comparison
equal
deleted
inserted
replaced
37279:9e8128e84326 | 37280:671a01cd50b5 |
---|---|
311 elif func is runfilter: | 311 elif func is runfilter: |
312 arg = data[0] | 312 arg = data[0] |
313 else: | 313 else: |
314 return None | 314 return None |
315 | 315 |
316 def _unthunk(context, mapping, thing): | |
317 """Evaluate a lazy byte string into value""" | |
318 if not isinstance(thing, types.GeneratorType): | |
319 return thing | |
320 return stringify(context, mapping, thing) | |
321 | |
316 def evalrawexp(context, mapping, arg): | 322 def evalrawexp(context, mapping, arg): |
317 """Evaluate given argument as a bare template object which may require | 323 """Evaluate given argument as a bare template object which may require |
318 further processing (such as folding generator of strings)""" | 324 further processing (such as folding generator of strings)""" |
319 func, data = arg | 325 func, data = arg |
320 return func(context, mapping, data) | 326 return func(context, mapping, data) |
328 # of byte strings as it is, not a lazy byte string. | 334 # of byte strings as it is, not a lazy byte string. |
329 def _unwrapvalue(context, mapping, thing): | 335 def _unwrapvalue(context, mapping, thing): |
330 thing = unwrapvalue(context, mapping, thing) | 336 thing = unwrapvalue(context, mapping, thing) |
331 # evalrawexp() may return string, generator of strings or arbitrary object | 337 # evalrawexp() may return string, generator of strings or arbitrary object |
332 # such as date tuple, but filter does not want generator. | 338 # such as date tuple, but filter does not want generator. |
333 if isinstance(thing, types.GeneratorType): | 339 return _unthunk(context, mapping, thing) |
334 thing = stringify(context, mapping, thing) | |
335 return thing | |
336 | 340 |
337 def evalboolean(context, mapping, arg): | 341 def evalboolean(context, mapping, arg): |
338 """Evaluate given argument as boolean, but also takes boolean literals""" | 342 """Evaluate given argument as boolean, but also takes boolean literals""" |
339 func, data = arg | 343 func, data = arg |
340 if func is runsymbol: | 344 if func is runsymbol: |