equal
deleted
inserted
replaced
308 |
308 |
309 def filter(self, context, mapping, select): |
309 def filter(self, context, mapping, select): |
310 if util.safehasattr(self._values, b'get'): |
310 if util.safehasattr(self._values, b'get'): |
311 values = { |
311 values = { |
312 k: v |
312 k: v |
313 for k, v in pycompat.iteritems(self._values) |
313 for k, v in self._values.items() |
314 if select(self._wrapvalue(k, v)) |
314 if select(self._wrapvalue(k, v)) |
315 } |
315 } |
316 else: |
316 else: |
317 values = [v for v in self._values if select(self._wrapvalue(v, v))] |
317 values = [v for v in self._values if select(self._wrapvalue(v, v))] |
318 return hybrid(None, values, self._makemap, self._joinfmt, self._keytype) |
318 return hybrid(None, values, self._makemap, self._joinfmt, self._keytype) |
340 |
340 |
341 def tovalue(self, context, mapping): |
341 def tovalue(self, context, mapping): |
342 # TODO: make it non-recursive for trivial lists/dicts |
342 # TODO: make it non-recursive for trivial lists/dicts |
343 xs = self._values |
343 xs = self._values |
344 if util.safehasattr(xs, b'get'): |
344 if util.safehasattr(xs, b'get'): |
345 return { |
345 return {k: unwrapvalue(context, mapping, v) for k, v in xs.items()} |
346 k: unwrapvalue(context, mapping, v) |
|
347 for k, v in pycompat.iteritems(xs) |
|
348 } |
|
349 return [unwrapvalue(context, mapping, x) for x in xs] |
346 return [unwrapvalue(context, mapping, x) for x in xs] |
350 |
347 |
351 |
348 |
352 class hybriditem(mappable, wrapped): |
349 class hybriditem(mappable, wrapped): |
353 """Wrapper for non-list/dict object to support map operation |
350 """Wrapper for non-list/dict object to support map operation |
535 # drop internal resources (recursively) which shouldn't be displayed |
532 # drop internal resources (recursively) which shouldn't be displayed |
536 lm = context.overlaymap(mapping, nm) |
533 lm = context.overlaymap(mapping, nm) |
537 items.append( |
534 items.append( |
538 { |
535 { |
539 k: unwrapvalue(context, lm, v) |
536 k: unwrapvalue(context, lm, v) |
540 for k, v in pycompat.iteritems(nm) |
537 for k, v in nm.items() |
541 if k not in knownres |
538 if k not in knownres |
542 } |
539 } |
543 ) |
540 ) |
544 return items |
541 return items |
545 |
542 |
713 """Wrap data like hybriddict(), but also supports old-style list template |
710 """Wrap data like hybriddict(), but also supports old-style list template |
714 |
711 |
715 This exists for backward compatibility with the old-style template. Use |
712 This exists for backward compatibility with the old-style template. Use |
716 hybriddict() for new template keywords. |
713 hybriddict() for new template keywords. |
717 """ |
714 """ |
718 c = [{key: k, value: v} for k, v in pycompat.iteritems(data)] |
715 c = [{key: k, value: v} for k, v in data.items()] |
719 f = _showcompatlist(context, mapping, name, c, plural, separator) |
716 f = _showcompatlist(context, mapping, name, c, plural, separator) |
720 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f) |
717 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f) |
721 |
718 |
722 |
719 |
723 def compatlist( |
720 def compatlist( |