Show More
@@ -262,12 +262,12 b' def get(context, mapping, args):' | |||
|
262 | 262 | raise error.ParseError(_("get() expects two arguments")) |
|
263 | 263 | |
|
264 | 264 | dictarg = evalwrapped(context, mapping, args[0]) |
|
265 | if not util.safehasattr(dictarg, 'get'): | |
|
265 | if not util.safehasattr(dictarg, 'getmember'): | |
|
266 | 266 | # i18n: "get" is a keyword |
|
267 | 267 | raise error.ParseError(_("get() expects a dict as first argument")) |
|
268 | 268 | |
|
269 | 269 | key = evalfuncarg(context, mapping, args[1]) |
|
270 | return templateutil.getdictitem(dictarg, key) | |
|
270 | return dictarg.getmember(context, mapping, key) | |
|
271 | 271 | |
|
272 | 272 | @templatefunc('if(expr, then[, else])') |
|
273 | 273 | def if_(context, mapping, args): |
@@ -128,6 +128,17 b' class hybrid(wrapped):' | |||
|
128 | 128 | self._joinfmt = joinfmt |
|
129 | 129 | self.keytype = keytype # hint for 'x in y' where type(x) is unresolved |
|
130 | 130 | |
|
131 | def getmember(self, context, mapping, key): | |
|
132 | # TODO: maybe split hybrid list/dict types? | |
|
133 | if not util.safehasattr(self._values, 'get'): | |
|
134 | raise error.ParseError(_('not a dictionary')) | |
|
135 | return self._wrapvalue(key, self._values.get(key)) | |
|
136 | ||
|
137 | def _wrapvalue(self, key, val): | |
|
138 | if val is None: | |
|
139 | return | |
|
140 | return wraphybridvalue(self, key, val) | |
|
141 | ||
|
131 | 142 | def itermaps(self, context): |
|
132 | 143 | makemap = self._makemap |
|
133 | 144 | for x in self._values: |
@@ -667,8 +678,8 b' def runmember(context, mapping, data):' | |||
|
667 | 678 | lm = context.overlaymap(mapping, d.tomap()) |
|
668 | 679 | return runsymbol(context, lm, memb) |
|
669 | 680 | try: |
|
670 | if util.safehasattr(d, 'get'): | |
|
671 |
return |
|
|
681 | if util.safehasattr(d, 'getmember'): | |
|
682 | return d.getmember(context, mapping, memb) | |
|
672 | 683 | raise error.ParseError |
|
673 | 684 | except error.ParseError: |
|
674 | 685 | sym = findsymbolicname(darg) |
@@ -693,12 +704,6 b' def runarithmetic(context, mapping, data' | |||
|
693 | 704 | except ZeroDivisionError: |
|
694 | 705 | raise error.Abort(_('division by zero is not defined')) |
|
695 | 706 | |
|
696 | def getdictitem(dictarg, key): | |
|
697 | val = dictarg.get(key) | |
|
698 | if val is None: | |
|
699 | return | |
|
700 | return wraphybridvalue(dictarg, key, val) | |
|
701 | ||
|
702 | 707 | def joinitems(itemiter, sep): |
|
703 | 708 | """Join items with the separator; Returns generator of bytes""" |
|
704 | 709 | first = True |
General Comments 0
You need to be logged in to leave comments.
Login now