mercurial/templater.py
changeset 18582 ef78450c8df6
parent 18289 9bfb53106328
child 18747 f5db3092790f
--- a/mercurial/templater.py	Fri Feb 08 21:55:46 2013 +0100
+++ b/mercurial/templater.py	Fri Feb 08 23:49:14 2013 +0100
@@ -207,6 +207,19 @@
         f = context._filters[n]
         return (runfilter, (args[0][0], args[0][1], f))
 
+def get(context, mapping, args):
+    if len(args) != 2:
+        # i18n: "get" is a keyword
+        raise error.ParseError(_("get() expects two arguments"))
+
+    dictarg = args[0][0](context, mapping, args[0][1])
+    if not util.safehasattr(dictarg, 'get'):
+        # i18n: "get" is a keyword
+        raise error.ParseError(_("get() expects a dict as first argument"))
+
+    key = args[1][0](context, mapping, args[1][1])
+    yield dictarg.get(key)
+
 def join(context, mapping, args):
     if not (1 <= len(args) <= 2):
         # i18n: "join" is a keyword
@@ -285,11 +298,12 @@
     }
 
 funcs = {
+    "get": get,
     "if": if_,
     "ifeq": ifeq,
     "join": join,
+    "label": label,
     "sub": sub,
-    "label": label,
 }
 
 # template engine