comparison mercurial/templateutil.py @ 37162:9ab3491f84c2

templater: extract unwrapinteger() function from evalinteger()
author Yuya Nishihara <yuya@tcha.org>
date Fri, 23 Mar 2018 20:34:12 +0900
parents 0023da2910c9
children 0fb28899e81a
comparison
equal deleted inserted replaced
37161:0023da2910c9 37162:9ab3491f84c2
316 # other objects are evaluated as strings, which means 0 is True, but 316 # other objects are evaluated as strings, which means 0 is True, but
317 # empty dict/list should be False as they are expected to be '' 317 # empty dict/list should be False as they are expected to be ''
318 return bool(stringify(thing)) 318 return bool(stringify(thing))
319 319
320 def evalinteger(context, mapping, arg, err=None): 320 def evalinteger(context, mapping, arg, err=None):
321 v = evalfuncarg(context, mapping, arg) 321 return unwrapinteger(evalrawexp(context, mapping, arg), err)
322
323 def unwrapinteger(thing, err=None):
324 thing = _unwrapvalue(thing)
322 try: 325 try:
323 return int(v) 326 return int(thing)
324 except (TypeError, ValueError): 327 except (TypeError, ValueError):
325 raise error.ParseError(err or _('not an integer')) 328 raise error.ParseError(err or _('not an integer'))
326 329
327 def evalstring(context, mapping, arg): 330 def evalstring(context, mapping, arg):
328 return stringify(evalrawexp(context, mapping, arg)) 331 return stringify(evalrawexp(context, mapping, arg))