##// END OF EJS Templates
templater: complain about invalid application of '%' operator (BC)...
Yuya Nishihara -
r37422:7c902a83 default
parent child Browse files
Show More
@@ -567,6 +567,20 b' def _formatfiltererror(arg, filt):'
567 567 return (_("template filter '%s' is not compatible with keyword '%s'")
568 568 % (fn, sym))
569 569
570 def _checkeditermaps(darg, d):
571 try:
572 for v in d:
573 if not isinstance(v, dict):
574 raise TypeError
575 yield v
576 except TypeError:
577 sym = findsymbolicname(darg)
578 if sym:
579 raise error.ParseError(_("keyword '%s' is not iterable of mappings")
580 % sym)
581 else:
582 raise error.ParseError(_("%r is not iterable of mappings") % d)
583
570 584 def _iteroverlaymaps(context, origmapping, newmappings):
571 585 """Generate combined mappings from the original mapping and an iterable
572 586 of partial mappings to override the original"""
@@ -578,28 +592,17 b' def _iteroverlaymaps(context, origmappin'
578 592 def runmap(context, mapping, data):
579 593 darg, targ = data
580 594 d = evalrawexp(context, mapping, darg)
595 # TODO: a generator should be rejected because it is a thunk of lazy
596 # string, but we can't because hgweb abuses generator as a keyword
597 # that returns a list of dicts.
581 598 if isinstance(d, wrapped):
582 599 diter = d.itermaps(context)
583 600 else:
584 try:
585 diter = iter(d)
586 except TypeError:
587 sym = findsymbolicname(darg)
588 if sym:
589 raise error.ParseError(_("keyword '%s' is not iterable") % sym)
590 else:
591 raise error.ParseError(_("%r is not iterable") % d)
592
601 diter = _checkeditermaps(darg, d)
593 602 for i, v in enumerate(diter):
594 if isinstance(v, dict):
595 lm = context.overlaymap(mapping, v)
596 lm['index'] = i
597 yield evalrawexp(context, lm, targ)
598 else:
599 # v is not an iterable of dicts, this happen when 'key'
600 # has been fully expanded already and format is useless.
601 # If so, return the expanded value.
602 yield v
603 lm = context.overlaymap(mapping, v)
604 lm['index'] = i
605 yield evalrawexp(context, lm, targ)
603 606
604 607 def runmember(context, mapping, data):
605 608 darg, memb = data
@@ -3210,10 +3210,13 b' Test new-style inline templating:'
3210 3210
3211 3211
3212 3212 $ hg log -R latesttag -r tip -T '{rev % "a"}\n'
3213 hg: parse error: keyword 'rev' is not iterable
3213 hg: parse error: keyword 'rev' is not iterable of mappings
3214 3214 [255]
3215 3215 $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "a"}\n'
3216 hg: parse error: None is not iterable
3216 hg: parse error: None is not iterable of mappings
3217 [255]
3218 $ hg log -R latesttag -r tip -T '{extras % "{key}\n" % "{key}\n"}'
3219 hg: parse error: <generator *> is not iterable of mappings (glob)
3217 3220 [255]
3218 3221
3219 3222 Test new-style inline templating of non-list/dict type:
@@ -3228,7 +3231,7 b' Test new-style inline templating of non-'
3228 3231 $ hg log -R latesttag -r tip -T '{get(extras, "branch") % "{key}: {value}\n"}'
3229 3232 branch: default
3230 3233 $ hg log -R latesttag -r tip -T '{get(extras, "unknown") % "{key}\n"}'
3231 hg: parse error: None is not iterable
3234 hg: parse error: None is not iterable of mappings
3232 3235 [255]
3233 3236 $ hg log -R latesttag -r tip -T '{min(extras) % "{key}: {value}\n"}'
3234 3237 branch: default
General Comments 0
You need to be logged in to leave comments. Login now