comparison mercurial/templateutil.py @ 38224:61cecab0cc20

templater: inline unwrapvalue() The current unwrapvalue() will be superseded by _unwrapvalue(). Note that _unwrapvalue() can simply return thing.tovalue() if thing is a wrapped object. That's because tovalue() is guaranteed to not return a generator of strings.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 04 Apr 2018 21:01:21 +0900
parents 40c7347f6848
children d48b80d58848
comparison
equal deleted inserted replaced
38223:b865bba56db1 38224:61cecab0cc20
459 459
460 # TODO: unify this with unwrapvalue() once the bug of templatefunc.join() 460 # TODO: unify this with unwrapvalue() once the bug of templatefunc.join()
461 # is fixed. we can't do that right now because join() has to take a generator 461 # is fixed. we can't do that right now because join() has to take a generator
462 # of byte strings as it is, not a lazy byte string. 462 # of byte strings as it is, not a lazy byte string.
463 def _unwrapvalue(context, mapping, thing): 463 def _unwrapvalue(context, mapping, thing):
464 thing = unwrapvalue(context, mapping, thing) 464 if isinstance(thing, wrapped):
465 return thing.tovalue(context, mapping)
465 # evalrawexp() may return string, generator of strings or arbitrary object 466 # evalrawexp() may return string, generator of strings or arbitrary object
466 # such as date tuple, but filter does not want generator. 467 # such as date tuple, but filter does not want generator.
467 return _unthunk(context, mapping, thing) 468 return _unthunk(context, mapping, thing)
468 469
469 def evalboolean(context, mapping, arg): 470 def evalboolean(context, mapping, arg):
474 if thing is None: 475 if thing is None:
475 # not a template keyword, takes as a boolean literal 476 # not a template keyword, takes as a boolean literal
476 thing = stringutil.parsebool(data) 477 thing = stringutil.parsebool(data)
477 else: 478 else:
478 thing = func(context, mapping, data) 479 thing = func(context, mapping, data)
479 thing = unwrapvalue(context, mapping, thing) 480 if isinstance(thing, wrapped):
481 thing = thing.tovalue(context, mapping)
480 if isinstance(thing, bool): 482 if isinstance(thing, bool):
481 return thing 483 return thing
482 # other objects are evaluated as strings, which means 0 is True, but 484 # other objects are evaluated as strings, which means 0 is True, but
483 # empty dict/list should be False as they are expected to be '' 485 # empty dict/list should be False as they are expected to be ''
484 return bool(stringify(context, mapping, thing)) 486 return bool(stringify(context, mapping, thing))