[z3-checkins] r38590 - z3/deliverance/branches/cache_aware/deliverance

ltucker at codespeak.net ltucker at codespeak.net
Mon Feb 12 17:33:55 CET 2007


Author: ltucker
Date: Mon Feb 12 17:33:53 2007
New Revision: 38590

Modified:
   z3/deliverance/branches/cache_aware/deliverance/htmlserialize.py
   z3/deliverance/branches/cache_aware/deliverance/wsgimiddleware.py
Log:
support doctype in serialization, use transitional html 4 for middleware output

Modified: z3/deliverance/branches/cache_aware/deliverance/htmlserialize.py
==============================================================================
--- z3/deliverance/branches/cache_aware/deliverance/htmlserialize.py	(original)
+++ z3/deliverance/branches/cache_aware/deliverance/htmlserialize.py	Mon Feb 12 17:33:53 2007
@@ -3,29 +3,22 @@
 
 html_xsl = """
 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-  <xsl:output method="html" encoding="UTF-8" />
+  <xsl:output method="html" encoding="UTF-8" /> 
   <xsl:template match="/">
     <xsl:copy-of select="."/>
   </xsl:template>
 </xsl:transform>
 """
 
-# TODO: this should do real formatting 
-pretty_html_xsl = """
-<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-  <xsl:output method="html" indent="yes" />
-  <xsl:template match="/">
-    <xsl:copy-of select="."/>
-  </xsl:template>
-</xsl:transform>
-"""
+# TODO: this should be xsl for real formatting 
+pretty_html_xsl = html_xsl
 
 html_transform = etree.XSLT(etree.XML(html_xsl))
 pretty_html_transform = etree.XSLT(etree.XML(pretty_html_xsl))
 
 
 
-def tostring(doc,pretty = False):
+def tostring(doc, pretty = False, doctype_pair=None):
     """
     return HTML string representation of the document given 
  
@@ -34,9 +27,15 @@
     """
 
     if pretty:
-        return str(pretty_html_transform(doc))
+        doc = str(pretty_html_transform(doc))
     else:
-        return str(html_transform(doc))
+        doc = str(html_transform(doc))
+
+    if doctype_pair: 
+        doc = """<!DOCTYPE html PUBLIC "%s" "%s">\n%s""" % (doctype_pair[0], doctype_pair[1], doc) 
+
+    return doc
+
                   
 
 

Modified: z3/deliverance/branches/cache_aware/deliverance/wsgimiddleware.py
==============================================================================
--- z3/deliverance/branches/cache_aware/deliverance/wsgimiddleware.py	(original)
+++ z3/deliverance/branches/cache_aware/deliverance/wsgimiddleware.py	Mon Feb 12 17:33:53 2007
@@ -213,7 +213,9 @@
         in the context of environ. The result is a string containing HTML. 
         """
         content = self.get_renderer(environ).render(parseHTML(body))
-        return tostring(content)
+
+        return tostring(content, doctype_pair=("-//W3C//DTD HTML 4.01 Transitional//EN",
+                                               "http://www.w3.org/TR/html4/loose.dtd"))
 
 
     def rebuild_check(self, environ, start_response): 


More information about the z3-checkins mailing list