# HG changeset patch # User cmlenz # Date 1154519791 0 # Node ID c9f0a26e28a2ccedbb5ad4cdea80728d92131266 # Parent cc2aee07f53b5984c0517633ee261ef89a4beb00 * Allow `py:with` directives to define `lambda`s * Fix directive order so that a `py:for` loop can be used inside a `py:when` or `py:otherwise` branch. diff --git a/markup/eval.py b/markup/eval.py --- a/markup/eval.py +++ b/markup/eval.py @@ -76,17 +76,19 @@ def __repr__(self): return '' % self.source - def evaluate(self, data): + def evaluate(self, data, nocall=False): """Evaluate the expression against the given data dictionary. @param data: a mapping containing the data to evaluate against + @param nocall: if true, the result of the evaluation is not called if + if it is a callable @return: the result of the evaluation """ retval = eval(self.code, {'data': data, '_lookup_name': _lookup_name, '_lookup_attr': _lookup_attr, '_lookup_item': _lookup_item}) - if callable(retval): + if not nocall and callable(retval): retval = retval() return retval diff --git a/markup/template.py b/markup/template.py --- a/markup/template.py +++ b/markup/template.py @@ -648,7 +648,7 @@ offset + (err.offset or 0)) def __call__(self, stream, ctxt, directives): - ctxt.push(dict([(name, expr.evaluate(ctxt)) + ctxt.push(dict([(name, expr.evaluate(ctxt, nocall=True)) for name, expr in self.vars])) for event in _apply_directives(stream, ctxt, directives): yield event @@ -671,10 +671,10 @@ directives = [('def', DefDirective), ('match', MatchDirective), + ('when', WhenDirective), + ('otherwise', OtherwiseDirective), ('for', ForDirective), ('if', IfDirective), - ('when', WhenDirective), - ('otherwise', OtherwiseDirective), ('choose', ChooseDirective), ('with', WithDirective), ('replace', ReplaceDirective),