--- HTTPResponse.py.orig Wed Apr 9 08:37:36 2003
+++ HTTPResponse.py Wed Apr 9 08:26:52 2003
@@ -176,6 +176,46 @@
self.stdout = stdout
self.stderr = stderr
+ def html_tidy(self):
+ """
+ Small hack to call html-tidy for every html
+ page which is serverd by zope.
+ Call it from lib/python/ZPublisher/HTTPResponse.setBody()
+ after self.body is set
+
+ if content_type == 'text/html':
+ self.html_tidy()
+ """
+ import tempfile
+ import popen2
+ ignore=[
+ 'Warning:
lacks "summary" attribute',
+ "Can't open",
+ "Warning: is not approved by W3C",
+ "Warning: inserting missing 'title' element"]
+ htmlfile=tempfile.mktemp()
+ fd=open(htmlfile, "wt")
+ fd.write(self.body)
+ fd.close()
+ stdout, stdin = popen2.popen4("tidy -q -errors %s" % htmlfile)
+ out=stdout.readlines()
+ os.unlink(htmlfile)
+ for line in out:
+ line=line.strip()
+ cont=0
+ for ign in ignore:
+ if line.find(ign)!=-1:
+ cont=1
+ continue
+ if cont:
+ continue
+ base="unknown base"
+ if hasattr(self, "base"):
+ base=self.base
+ print "HTML-Tidy: %s %s" % (
+ self.base, line)
+
+
def retry(self):
"""Return a response object to be used in a retry attempt
"""
@@ -329,6 +369,8 @@
body = '>'.join(body.split('\233'))
self.setHeader('content-length', len(self.body))
+ if content_type == 'text/html':
+ self.html_tidy()
self.insertBase()
if self.use_HTTP_content_compression and \
not self.headers.get('content-encoding',None):