[Checkins] SVN: five.pt/trunk/ Fixed issue with persistent templates; we now use the provided ``_text`` string as the template source body and this is guaranteed by Zope's template class to be error free (errors are commented out using XML comments).

Malthe Borch mborch at gmail.com
Wed Aug 10 08:08:26 EDT 2011


Log message for revision 122523:
  Fixed issue with persistent templates; we now use the provided ``_text`` string as the template source body and this is guaranteed by Zope's template class to be error free (errors are commented out using XML comments).

Changed:
  U   five.pt/trunk/CHANGES.txt
  U   five.pt/trunk/src/five/pt/patches.py
  U   five.pt/trunk/src/five/pt/tests/secure.pt
  U   five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py

-=-
Modified: five.pt/trunk/CHANGES.txt
===================================================================
--- five.pt/trunk/CHANGES.txt	2011-08-10 11:14:52 UTC (rev 122522)
+++ five.pt/trunk/CHANGES.txt	2011-08-10 12:08:25 UTC (rev 122523)
@@ -3,8 +3,16 @@
 
 In next release ...
 
+- Reuse template instance on cook.
+  [malthe]
+
+- Use the template source string available in the ``_text`` attribute
+  instead of reading the file (again).
+  [leorochael, malthe]
+
 - Use secure moduler importer for both Zope 2 and 3 templates. This
   fixes issue #34.
+  [malthe]
 
 2.1.4 (2011-07-28)
 ~~~~~~~~~~~~~~~~~~

Modified: five.pt/trunk/src/five/pt/patches.py
===================================================================
--- five.pt/trunk/src/five/pt/patches.py	2011-08-10 11:14:52 UTC (rev 122522)
+++ five.pt/trunk/src/five/pt/patches.py	2011-08-10 12:08:25 UTC (rev 122523)
@@ -63,37 +63,31 @@
 
 
 def cook(self):
-    engine = self.pt_getEngine()
+    program = self._v_program
+    if program is None:
+        engine = self.pt_getEngine()
+        source_file = self.pt_source_file()
 
-    filename = getattr(self, 'filename', None) or \
-               getattr(self, '_filename', None)
+        if engine is getEngine():
+            expression_types = _secure_expression_types
+        else:
+            expression_types = _expression_types
 
-    if engine is getEngine():
-        expression_types = _secure_expression_types
-    else:
-        expression_types = _expression_types
+        extra_builtins = {
+            'modules': ZRPythonExpr._SecureModuleImporter()
+            }
 
-    extra_builtins = {
-        'modules': ZRPythonExpr._SecureModuleImporter()
-        }
-
-    if filename is None:
         program = ChameleonPageTemplate(
-            self._text, keep_body=True,
+            "", filename=source_file, keep_body=True,
             expression_types=expression_types,
-            encoding='utf-8', extra_builtins=extra_builtins)
-    else:
-        program = ChameleonPageTemplateFile(
-            filename, keep_body=True,
-            expression_types=expression_types,
-            encoding='utf-8', extra_builtins=extra_builtins)
+            encoding='utf-8', extra_builtins=extra_builtins,
+            )
 
-    self._v_program = program
-    self._v_macros = program.macros
-    self._v_cooked = 1
+        self._v_program = program
+        self._v_macros = program.macros
 
     try:
-        program.cook_check()
+        program.cook(self._text)
     except:
         etype, e = sys.exc_info()[:2]
         self._v_errors = [
@@ -103,7 +97,9 @@
     else:
         self._v_errors = ()
 
+    self._v_cooked = 1
 
+
 @staticmethod
 def create_interpreter(cls, *args, **kwargs):
     return ChameleonTALInterpreter(*args, **kwargs)

Modified: five.pt/trunk/src/five/pt/tests/secure.pt
===================================================================
--- five.pt/trunk/src/five/pt/tests/secure.pt	2011-08-10 11:14:52 UTC (rev 122522)
+++ five.pt/trunk/src/five/pt/tests/secure.pt	2011-08-10 12:08:25 UTC (rev 122523)
@@ -1,5 +1,5 @@
 <div xmlns="http://www.w3.org/1999/xhtml"
      xmlns:tal="http://xml.zope.org/namespaces/tal">
   <span tal:define="soup view/tagsoup | options/soup"
-        tal:replace="python: modules['cgi'].escape(soup)" />
+        tal:replace="structure python: modules['cgi'].escape(soup)" />
 </div>

Modified: five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py
===================================================================
--- five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py	2011-08-10 11:14:52 UTC (rev 122522)
+++ five.pt/trunk/src/five/pt/tests/test_persistenttemplate.py	2011-08-10 12:08:25 UTC (rev 122523)
@@ -41,8 +41,8 @@
 """.strip()
 
 simple_error = """
-<tal:block define="foo python: 0 < 1">
-  putting a "less-than" inside an attribute value is not valid
+<tal:block content__typo="nothing">
+  it's an error to use an unknown attribute in the tal namespace
 </tal:block>
 """.strip()
 



More information about the checkins mailing list