Show More
@@ -289,6 +289,15 b' def evalfuncarg(context, mapping, arg):' | |||||
289 | thing = stringify(thing) |
|
289 | thing = stringify(thing) | |
290 | return thing |
|
290 | return thing | |
291 |
|
291 | |||
|
292 | def evalboolean(context, mapping, arg): | |||
|
293 | func, data = arg | |||
|
294 | thing = func(context, mapping, data) | |||
|
295 | if isinstance(thing, bool): | |||
|
296 | return thing | |||
|
297 | # other objects are evaluated as strings, which means 0 is True, but | |||
|
298 | # empty dict/list should be False as they are expected to be '' | |||
|
299 | return bool(stringify(thing)) | |||
|
300 | ||||
292 | def evalinteger(context, mapping, arg, err): |
|
301 | def evalinteger(context, mapping, arg, err): | |
293 | v = evalfuncarg(context, mapping, arg) |
|
302 | v = evalfuncarg(context, mapping, arg) | |
294 | try: |
|
303 | try: | |
@@ -560,7 +569,7 b' def if_(context, mapping, args):' | |||||
560 | # i18n: "if" is a keyword |
|
569 | # i18n: "if" is a keyword | |
561 | raise error.ParseError(_("if expects two or three arguments")) |
|
570 | raise error.ParseError(_("if expects two or three arguments")) | |
562 |
|
571 | |||
563 |
test = eval |
|
572 | test = evalboolean(context, mapping, args[0]) | |
564 | if test: |
|
573 | if test: | |
565 | yield args[1][0](context, mapping, args[1][1]) |
|
574 | yield args[1][0](context, mapping, args[1][1]) | |
566 | elif len(args) == 3: |
|
575 | elif len(args) == 3: |
General Comments 0
You need to be logged in to leave comments.
Login now