Mercurial > genshi > mirror
comparison markup/eval.py @ 120:c9f0a26e28a2 trunk
* 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.
author | cmlenz |
---|---|
date | Wed, 02 Aug 2006 11:56:31 +0000 |
parents | c392d38694d9 |
children | 2ad83f1d337c 9d7ca94133be |
comparison
equal
deleted
inserted
replaced
119:cc2aee07f53b | 120:c9f0a26e28a2 |
---|---|
74 self.code = _compile(source, filename, lineno) | 74 self.code = _compile(source, filename, lineno) |
75 | 75 |
76 def __repr__(self): | 76 def __repr__(self): |
77 return '<Expression "%s">' % self.source | 77 return '<Expression "%s">' % self.source |
78 | 78 |
79 def evaluate(self, data): | 79 def evaluate(self, data, nocall=False): |
80 """Evaluate the expression against the given data dictionary. | 80 """Evaluate the expression against the given data dictionary. |
81 | 81 |
82 @param data: a mapping containing the data to evaluate against | 82 @param data: a mapping containing the data to evaluate against |
83 @param nocall: if true, the result of the evaluation is not called if | |
84 if it is a callable | |
83 @return: the result of the evaluation | 85 @return: the result of the evaluation |
84 """ | 86 """ |
85 retval = eval(self.code, {'data': data, | 87 retval = eval(self.code, {'data': data, |
86 '_lookup_name': _lookup_name, | 88 '_lookup_name': _lookup_name, |
87 '_lookup_attr': _lookup_attr, | 89 '_lookup_attr': _lookup_attr, |
88 '_lookup_item': _lookup_item}) | 90 '_lookup_item': _lookup_item}) |
89 if callable(retval): | 91 if not nocall and callable(retval): |
90 retval = retval() | 92 retval = retval() |
91 return retval | 93 return retval |
92 | 94 |
93 | 95 |
94 def _compile(source, filename=None, lineno=-1): | 96 def _compile(source, filename=None, lineno=-1): |