##// END OF EJS Templates
templater: resolve type of dict key in getmember()...
Yuya Nishihara -
r38262:688fbb75 @31 default
parent child Browse files
Show More
@@ -714,6 +714,7 b' class sessionvars(templateutil.wrapped):'
714 return sessionvars(copy.copy(self._vars), self._start)
714 return sessionvars(copy.copy(self._vars), self._start)
715
715
716 def getmember(self, context, mapping, key):
716 def getmember(self, context, mapping, key):
717 key = templateutil.unwrapvalue(context, mapping, key)
717 return self._vars.get(key)
718 return self._vars.get(key)
718
719
719 def itermaps(self, context):
720 def itermaps(self, context):
@@ -262,7 +262,7 b' def get(context, mapping, args):'
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 key = evalfuncarg(context, mapping, args[1])
265 key = evalrawexp(context, mapping, args[1])
266 try:
266 try:
267 return dictarg.getmember(context, mapping, key)
267 return dictarg.getmember(context, mapping, key)
268 except error.ParseError as err:
268 except error.ParseError as err:
@@ -41,6 +41,7 b' class wrapped(object):'
41 def getmember(self, context, mapping, key):
41 def getmember(self, context, mapping, key):
42 """Return a member item for the specified key
42 """Return a member item for the specified key
43
43
44 The key argument may be a wrapped object.
44 A returned object may be either a wrapped object or a pure value
45 A returned object may be either a wrapped object or a pure value
45 depending on the self type.
46 depending on the self type.
46 """
47 """
@@ -147,6 +148,7 b' class hybrid(wrapped):'
147 # TODO: maybe split hybrid list/dict types?
148 # TODO: maybe split hybrid list/dict types?
148 if not util.safehasattr(self._values, 'get'):
149 if not util.safehasattr(self._values, 'get'):
149 raise error.ParseError(_('not a dictionary'))
150 raise error.ParseError(_('not a dictionary'))
151 key = unwrapastype(context, mapping, key, self.keytype)
150 return self._wrapvalue(key, self._values.get(key))
152 return self._wrapvalue(key, self._values.get(key))
151
153
152 def _wrapvalue(self, key, val):
154 def _wrapvalue(self, key, val):
General Comments 0
You need to be logged in to leave comments. Login now