diff mercurial/templater.py @ 35474:a33be093ec62

templater: look up symbols/resources as if they were separated (issue5699) It wouldn't be easy to split the mapping dict into (symbols, resources). This patch instead rejects invalid lookup taking resources.keys() as source of truth. The doctest is updated since mapping['repo'] is now reserved for a repo object.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 21 Dec 2017 22:17:39 +0900
parents 32c278eb876f
children 964510dcdc2a
line wrap: on
line diff
--- a/mercurial/templater.py	Thu Dec 21 22:05:30 2017 +0900
+++ b/mercurial/templater.py	Thu Dec 21 22:17:39 2017 +0900
@@ -1320,7 +1320,9 @@
 
     def symbol(self, mapping, key):
         """Resolve symbol to value or function; None if nothing found"""
-        v = mapping.get(key)
+        v = None
+        if key not in self._resources:
+            v = mapping.get(key)
         if v is None:
             v = self._defaults.get(key)
         return v
@@ -1328,11 +1330,13 @@
     def resource(self, mapping, key):
         """Return internal data (e.g. cache) used for keyword/function
         evaluation"""
-        v = mapping.get(key)
+        v = None
+        if key in self._resources:
+            v = mapping.get(key)
         if v is None:
             v = self._resources.get(key)
         if v is None:
-            raise KeyError
+            raise error.Abort(_('template resource not available: %s') % key)
         return v
 
     def _load(self, t):