Update of /cvsroot/webware/Webware/WebKit
In directory usw-pr-cvs1:/tmp/cvs-serv4453/WebKit
Modified Files:
ASStreamOut.py HTTPResponse.py Page.py
Log Message:
Added the HTML validation hook, per Jason Hildebrand's instructions
http://webware.colorstudy.net/twiki/bin/view/Webware/AutomaticHTMLValidation
Still configured by overriding writeBodyParts -- need to improve that
sometime.
Index: ASStreamOut.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/ASStreamOut.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ASStreamOut.py 30 Aug 2002 15:55:55 -0000 1.4
--- ASStreamOut.py 27 Sep 2002 01:57:51 -0000 1.5
***************
*** 74,77 ****
--- 74,91 ----
return 1
+ def buffer(self):
+ """
+ Return accumulated data which has not yet been
+ flushed. We want to be able to get at this data
+ without having to call flush first, so that we can
+ (for example) integrate automatic HTML validation.
+ """
+ # if flush has been called, return what was flushed
+ if self._buffer:
+ return self._buffer
+ # otherwise return the buffered chunks
+ else:
+ return string.join(self._chunks,'')
+
def clear(self):
"""
Index: HTTPResponse.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/HTTPResponse.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** HTTPResponse.py 20 Jun 2002 17:48:08 -0000 1.20
--- HTTPResponse.py 27 Sep 2002 01:57:51 -0000 1.21
***************
*** 255,259 ****
return {
'headers': headers,
! 'contents': self._strmOut._buffer
}
--- 255,259 ----
return {
'headers': headers,
! 'contents': self._strmOut.buffer()
}
Index: Page.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/Page.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** Page.py 4 Sep 2002 13:28:39 -0000 1.24
--- Page.py 27 Sep 2002 01:57:51 -0000 1.25
***************
*** 375,378 ****
--- 375,417 ----
+ ## Validate HTML output (developer debugging) ##
+
+ def validateHTML(self, closingTags='</body></html>'):
+ """
+ Validate the current response data using Web Design
+ Group's HTML validator available at
+ http://www.htmlhelp.com/tools/validator/
+
+ Make sure you install the offline validator (called
+ "validate") which can be called from the command-line.
+ The "validate" script must be in your path.
+
+ Add this method to your SitePage (the servlet from
+ which all your servlets inherit), override
+ Page.writeBodyParts() in your SitePage like so:
+ def writeBodyParts(self):
+ Page.writeBodyParts()
+ self.validateHTML()
+
+ The "closingtags" param is a string which is appended
+ to the page before validation. Typically, it would be
+ the string "</body></html>". At the point this method
+ is called (e.g. from writeBodyParts() the page is not
+ yet 100% complete, so we have to fake it.
+ """
+
+ # don't bother validating if the servlet has redirected
+ status = self.response().header('status', None)
+ if status and status.find('Redirect') != -1:
+ return
+
+ response = self.response().rawResponse()
+ contents = response['contents'] + closingTags
+ from WebUtils import WDGValidator
+ errorText = WDGValidator.validateHTML(contents)
+ if not errorText:
+ return
+ self.write(errorText)
+
## Exception reports ##
|