[Checkins] SVN: z3c.pt/trunk/ Expressions that return a callable are now evaluated.

Malthe Borch mborch at gmail.com
Fri Feb 22 19:49:22 EST 2008


Log message for revision 84158:
  Expressions that return a callable are now evaluated.

Changed:
  U   z3c.pt/trunk/README.txt
  U   z3c.pt/trunk/setup.py
  U   z3c.pt/trunk/z3c/pt/BENCHMARKS.txt
  U   z3c.pt/trunk/z3c/pt/clauses.py
  U   z3c.pt/trunk/z3c/pt/translation.py
  U   z3c.pt/trunk/z3c/pt/translation.txt

-=-
Modified: z3c.pt/trunk/README.txt
===================================================================
--- z3c.pt/trunk/README.txt	2008-02-23 00:28:10 UTC (rev 84157)
+++ z3c.pt/trunk/README.txt	2008-02-23 00:49:21 UTC (rev 84158)
@@ -38,4 +38,15 @@
 
    can be used instead of ``dictionary['key']``.
 
-*) http://wiki.zope.org/ZPT/TALSpecification14
\ No newline at end of file
+5. Expressions that return a callable are called.
+
+
+*) http://wiki.zope.org/ZPT/TALSpecification14
+
+Development
+-----------
+
+If you want to use the code directly from trunk, provide
+``z3c.pt==dev`` as your dependency.
+
+http://svn.zope.org/z3c.pt/trunk#egg=z3c.pt-dev

Modified: z3c.pt/trunk/setup.py
===================================================================
--- z3c.pt/trunk/setup.py	2008-02-23 00:28:10 UTC (rev 84157)
+++ z3c.pt/trunk/setup.py	2008-02-23 00:49:21 UTC (rev 84158)
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = '0.4.1'
+version = '0.4.2'
 
 setup(name='z3c.pt',
       version=version,

Modified: z3c.pt/trunk/z3c/pt/BENCHMARKS.txt
===================================================================
--- z3c.pt/trunk/z3c/pt/BENCHMARKS.txt	2008-02-23 00:28:10 UTC (rev 84157)
+++ z3c.pt/trunk/z3c/pt/BENCHMARKS.txt	2008-02-23 00:49:21 UTC (rev 84158)
@@ -10,7 +10,7 @@
 
                   zope.pagetemplate     z3c.pt    pure python
 Hello World        3.6                  1         0.02        
-1000 x 10 table   14.0                  1         0.63
+1000 x 10 table   13.5                  1         0.58
 
 There's a setup cost in using a template language which explains the
 50x factor in the 'Hello World' benchmark versus a pure python

Modified: z3c.pt/trunk/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/z3c/pt/clauses.py	2008-02-23 00:28:10 UTC (rev 84157)
+++ z3c.pt/trunk/z3c/pt/clauses.py	2008-02-23 00:49:21 UTC (rev 84158)
@@ -325,7 +325,8 @@
     """
       >>> from z3c.pt.io import CodeIO
       >>> from StringIO import StringIO
-
+      >>> from cgi import escape as _escape
+      
       >>> _out = StringIO(); stream = CodeIO()
       >>> tag = Tag('div', dict(alt=value(repr('Hello World!'))))
       >>> tag.begin(stream)
@@ -364,7 +365,7 @@
 
             if isinstance(expression, (tuple, list)):
                 write = Write(expression)
-                write.begin(stream)
+                write.begin(stream, escape='"')
                 write.end(stream)
             else:
                 stream.out(expression.replace("'", "\\'"))
@@ -462,7 +463,7 @@
         self.expressions = expressions
         self.count = len(expressions)
         
-    def begin(self, stream):
+    def begin(self, stream, escape=False):
         temp = stream.save()
                 
         if self.count == 1:
@@ -471,9 +472,15 @@
             self.assign.begin(stream, temp)
             expr = temp
 
+        stream.write("_urf = %s" % expr)
+        stream.write("if callable(_urf): _urf = _urf()")
+        stream.write("if _urf is None: _urf = ''")
+
+        if escape:
+            escape_char = escape.replace("'", "\'")
+            stream.write("_urf = _escape(_urf, '%s')" % escape_char)
+            
         if unicode_required_flag:
-            stream.write("_urf = %s" % expr)
-            stream.write("if _urf is None: _urf = ''")
             stream.write("try:")
             stream.indent()
             stream.write("_out.write(str(_urf))")
@@ -483,7 +490,7 @@
             stream.write("_out.write(unicode(_urf, 'utf-8'))")
             stream.outdent()
         else:
-            stream.write("_out.write(str(%s))" % expr)
+            stream.write("_out.write(str(_urf))")
             
     def end(self, stream):
         if self.count != 1:

Modified: z3c.pt/trunk/z3c/pt/translation.py
===================================================================
--- z3c.pt/trunk/z3c/pt/translation.py	2008-02-23 00:28:10 UTC (rev 84157)
+++ z3c.pt/trunk/z3c/pt/translation.py	2008-02-23 00:49:21 UTC (rev 84158)
@@ -204,7 +204,7 @@
                     raise ValueError, "Tuple definitions in assignment clause is not supported."
 
                 variable = variables[0]
-                attributes[variable] = _escape(expression, '"')
+                attributes[variable] = expression
         else:
             attrs = []
 
@@ -317,8 +317,5 @@
              "target_language=_target_language, default=%s)") %
             (exp, mapping, default) for exp in expressions]
 
-def _escape(expressions, delim):
-    return ["_escape(%s, '\\%s')" % (exp, delim) for exp in expressions]
-
 def _not(expressions):
     return ["not (%s)" % exp for exp in expressions]

Modified: z3c.pt/trunk/z3c/pt/translation.txt
===================================================================
--- z3c.pt/trunk/z3c/pt/translation.txt	2008-02-23 00:28:10 UTC (rev 84157)
+++ z3c.pt/trunk/z3c/pt/translation.txt	2008-02-23 00:49:21 UTC (rev 84158)
@@ -37,6 +37,8 @@
   ...   <span tal:replace="'Hello World!'">Hello Universe!</span>
   ...   <span tal:content="'%s'" />
   ...   <span tal:content="None" />
+  ...   <span tal:attributes="class lambda: 'Hello'"
+  ...         tal:content="lambda: 'World'" />
   ... </div>
   ... """ % (u'La Pe\xf1a').encode('utf-8')
 
@@ -73,6 +75,7 @@
     Hello World!
     <span>La Peña</span>
     <span></span>
+    <span class="Hello">World</span>
   </div>
     
 Error handling



More information about the Checkins mailing list