changeset 344:bb881d1b4b5c experimental-inline

inline branch: Merged [419:421/trunk].
author cmlenz
date Fri, 10 Nov 2006 10:13:12 +0000
parents aebbf9ae3915
children ffa7dea6e8fd
files ChangeLog UPGRADE.txt genshi/template/directives.py genshi/template/eval.py genshi/template/tests/eval.py
diffstat 5 files changed, 19 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,8 @@
    immediate children.
  * Split up the `genshi.template` module into multiple modules inside the new
    `genshi.template` package.
+ * Results of expression evaluation are no longer implicitly called if they
+   are callable.
 
 Version 0.3.4
 http://svn.edgewall.org/repos/genshi/tags/0.3.4/
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -10,6 +10,10 @@
 leftover traces of the `template.py` file on the installation path.
 This is not necessary when Genshi was installed as a Python egg.
 
+Results of evaluating template expressions are no longer implicitly
+called if they are callable. If you have been using that feature, you
+will need to add the parenthesis to actually call the function.
+
 
 Upgrading from Markup
 ---------------------
--- a/genshi/template/directives.py
+++ b/genshi/template/directives.py
@@ -155,13 +155,13 @@
     </div>
     
     If a function does not require parameters, the parenthesis can be omitted
-    both when defining and when calling it:
+    in the definition:
     
     >>> tmpl = MarkupTemplate('''<div xmlns:py="http://genshi.edgewall.org/">
     ...   <p py:def="helloworld" class="message">
     ...     Hello, world!
     ...   </p>
-    ...   ${helloworld}
+    ...   ${helloworld()}
     ... </div>''')
     >>> print tmpl.generate(bar='Bye')
     <div>
@@ -590,7 +590,7 @@
         frame = {}
         ctxt.push(frame)
         for targets, expr in self.vars:
-            value = expr.evaluate(ctxt, nocall=True)
+            value = expr.evaluate(ctxt)
             for _, assign in targets:
                 assign(frame, value)
         for event in _apply_directives(stream, ctxt, directives):
--- a/genshi/template/eval.py
+++ b/genshi/template/eval.py
@@ -95,22 +95,17 @@
     def __repr__(self):
         return 'Expression(%r)' % self.source
 
-    def evaluate(self, data, nocall=False):
+    def evaluate(self, data):
         """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},
-                                 {'data': data})
-        if not nocall and type(retval) is not Undefined and callable(retval):
-            retval = retval()
-        return retval
+        return eval(self.code, {'data': data,
+                                '_lookup_name': _lookup_name,
+                                '_lookup_attr': _lookup_attr,
+                                '_lookup_item': _lookup_item},
+                               {'data': data})
 
 
 class Undefined(object):
--- a/genshi/template/tests/eval.py
+++ b/genshi/template/tests/eval.py
@@ -32,10 +32,9 @@
 
     def test_name_lookup(self):
         self.assertEqual('bar', Expression('foo').evaluate({'foo': 'bar'}))
-        self.assertEqual(id, Expression('id').evaluate({}, nocall=True))
+        self.assertEqual(id, Expression('id').evaluate({}))
         self.assertEqual('bar', Expression('id').evaluate({'id': 'bar'}))
-        self.assertEqual(None, Expression('id').evaluate({'id': None},
-                                                         nocall=True))
+        self.assertEqual(None, Expression('id').evaluate({'id': None}))
 
     def test_str_literal(self):
         self.assertEqual('foo', Expression('"foo"').evaluate({}))
@@ -217,14 +216,8 @@
     def test_call_dstar_args(self):
         def foo(x):
             return x
-        self.assertEqual(42, Expression("foo(**bar)").evaluate({'foo': foo,
-                                                                'bar': {"x": 42}}))
-
-    def test_call_function_without_params(self):
-        self.assertEqual(42, Expression("foo").evaluate({'foo': lambda: 42}))
-        data = {'foo': 'bar'}
-        self.assertEqual('BAR', Expression("foo.upper").evaluate(data))
-        data = {'foo': {'bar': range(42)}}
+        expr = Expression("foo(**bar)")
+        self.assertEqual(42, expr.evaluate({'foo': foo, 'bar': {"x": 42}}))
 
     def test_lambda(self):
         # Define a custom `sorted` function cause the builtin isn't available
Copyright (C) 2012-2017 Edgewall Software