Mercurial > public > mercurial-scm > hg
comparison mercurial/templateutil.py @ 38229:7701c2d4a438
templater: always map over a wrapped object
_checkeditermaps() is no longer necessary as the hgweb issue was resolved.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 21 Apr 2018 17:21:31 +0900 |
parents | 8bded7eae26c |
children | c2456a7726c1 |
comparison
equal
deleted
inserted
replaced
38228:8bded7eae26c | 38229:7701c2d4a438 |
---|---|
641 if not sym: | 641 if not sym: |
642 return _("incompatible use of template filter '%s'") % fn | 642 return _("incompatible use of template filter '%s'") % fn |
643 return (_("template filter '%s' is not compatible with keyword '%s'") | 643 return (_("template filter '%s' is not compatible with keyword '%s'") |
644 % (fn, sym)) | 644 % (fn, sym)) |
645 | 645 |
646 def _checkeditermaps(darg, d): | |
647 try: | |
648 for v in d: | |
649 if not isinstance(v, dict): | |
650 raise TypeError | |
651 yield v | |
652 except TypeError: | |
653 sym = findsymbolicname(darg) | |
654 if sym: | |
655 raise error.ParseError(_("keyword '%s' is not iterable of mappings") | |
656 % sym) | |
657 else: | |
658 raise error.ParseError(_("%r is not iterable of mappings") % d) | |
659 | |
660 def _iteroverlaymaps(context, origmapping, newmappings): | 646 def _iteroverlaymaps(context, origmapping, newmappings): |
661 """Generate combined mappings from the original mapping and an iterable | 647 """Generate combined mappings from the original mapping and an iterable |
662 of partial mappings to override the original""" | 648 of partial mappings to override the original""" |
663 for i, nm in enumerate(newmappings): | 649 for i, nm in enumerate(newmappings): |
664 lm = context.overlaymap(origmapping, nm) | 650 lm = context.overlaymap(origmapping, nm) |
665 lm['index'] = i | 651 lm['index'] = i |
666 yield lm | 652 yield lm |
667 | 653 |
668 def _applymap(context, mapping, diter, targ): | 654 def _applymap(context, mapping, d, targ): |
669 for lm in _iteroverlaymaps(context, mapping, diter): | 655 for lm in _iteroverlaymaps(context, mapping, d.itermaps(context)): |
670 yield evalrawexp(context, lm, targ) | 656 yield evalrawexp(context, lm, targ) |
671 | 657 |
672 def runmap(context, mapping, data): | 658 def runmap(context, mapping, data): |
673 darg, targ = data | 659 darg, targ = data |
674 d = evalrawexp(context, mapping, darg) | 660 d = evalwrapped(context, mapping, darg) |
675 # TODO: a generator should be rejected because it is a thunk of lazy | 661 return mappedgenerator(_applymap, args=(mapping, d, targ)) |
676 # string, but we can't because hgweb abuses generator as a keyword | |
677 # that returns a list of dicts. | |
678 # TODO: drop _checkeditermaps() and pass 'd' to mappedgenerator so it | |
679 # can be restarted. | |
680 if isinstance(d, wrapped): | |
681 diter = d.itermaps(context) | |
682 else: | |
683 diter = _checkeditermaps(darg, d) | |
684 return mappedgenerator(_applymap, args=(mapping, diter, targ)) | |
685 | 662 |
686 def runmember(context, mapping, data): | 663 def runmember(context, mapping, data): |
687 darg, memb = data | 664 darg, memb = data |
688 d = evalrawexp(context, mapping, darg) | 665 d = evalrawexp(context, mapping, darg) |
689 if util.safehasattr(d, 'tomap'): | 666 if util.safehasattr(d, 'tomap'): |