[Checkins] SVN: z3c.pt/trunk/ Added XML validation.

Malthe Borch mborch at gmail.com
Tue Aug 12 09:22:05 EDT 2008


Log message for revision 89725:
  Added XML validation.

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/clauses.py
  U   z3c.pt/trunk/src/z3c/pt/config.py

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-08-12 13:17:52 UTC (rev 89724)
+++ z3c.pt/trunk/CHANGES.txt	2008-08-12 13:22:04 UTC (rev 89725)
@@ -4,6 +4,9 @@
 Version 1.0dev
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- Expression results are now validated for XML correctness when the
+  compiler is running in debug-mode. [malthe]
+
 - Preserve CDATA sections. [malthe]
 
 - The Genshi interpolation operator ${} should not have its result

Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py	2008-08-12 13:17:52 UTC (rev 89724)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py	2008-08-12 13:22:04 UTC (rev 89725)
@@ -1,6 +1,7 @@
 from cgi import escape
 
 from z3c.pt import types
+from z3c.pt import config
 from z3c.pt.utils import unicode_required_flag
 
 class Assign(object):
@@ -749,6 +750,17 @@
             stream.write("_write(_urf)")
         stream.outdent()
 
+        # validate XML if enabled
+        if config.VALIDATION:
+            try:
+                import xml.etree
+            except ImportError:
+                raise ImportError(
+                    "xml.etree (required when XML validation is enabled).")
+            
+            stream.write("from xml.etree import ElementTree as ET")
+            stream.write("ET.fromstring('<div>%s</div>' % _urf)")
+
     def end(self, stream):
         if self.assign:
             self.assign.end(stream)

Modified: z3c.pt/trunk/src/z3c/pt/config.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/config.py	2008-08-12 13:17:52 UTC (rev 89724)
+++ z3c.pt/trunk/src/z3c/pt/config.py	2008-08-12 13:22:04 UTC (rev 89725)
@@ -8,6 +8,8 @@
 
 PROD_MODE = not DEBUG_MODE
 
+VALIDATION = DEBUG_MODE
+
 DISABLE_I18N_KEY = 'Z3C_PT_DISABLE_I18N'
 DISABLE_I18N = os.environ.get(DISABLE_I18N_KEY, 'false')
 DISABLE_I18N = DISABLE_I18N.lower() in truevals



More information about the Checkins mailing list