mercurial/templatefuncs.py
changeset 38243 06d11cd90516
parent 38242 12b6ee9e88f3
child 38244 688fbb758ba9
equal deleted inserted replaced
38242:12b6ee9e88f3 38243:06d11cd90516
   260     if len(args) != 2:
   260     if len(args) != 2:
   261         # i18n: "get" is a keyword
   261         # i18n: "get" is a keyword
   262         raise error.ParseError(_("get() expects two arguments"))
   262         raise error.ParseError(_("get() expects two arguments"))
   263 
   263 
   264     dictarg = evalwrapped(context, mapping, args[0])
   264     dictarg = evalwrapped(context, mapping, args[0])
   265     if not util.safehasattr(dictarg, 'getmember'):
   265     key = evalfuncarg(context, mapping, args[1])
       
   266     try:
       
   267         return dictarg.getmember(context, mapping, key)
       
   268     except error.ParseError as err:
   266         # i18n: "get" is a keyword
   269         # i18n: "get" is a keyword
   267         raise error.ParseError(_("get() expects a dict as first argument"))
   270         hint = _("get() expects a dict as first argument")
   268 
   271         raise error.ParseError(bytes(err), hint=hint)
   269     key = evalfuncarg(context, mapping, args[1])
       
   270     return dictarg.getmember(context, mapping, key)
       
   271 
   272 
   272 @templatefunc('if(expr, then[, else])')
   273 @templatefunc('if(expr, then[, else])')
   273 def if_(context, mapping, args):
   274 def if_(context, mapping, args):
   274     """Conditionally execute based on the result of
   275     """Conditionally execute based on the result of
   275     an expression."""
   276     an expression."""