[Checkins] SVN: zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate. Make the validated HTML available in a response header for inspecting
Ross Patterson
me at rpatterson.net
Sat Feb 20 07:44:17 EST 2010
Log message for revision 109174:
Make the validated HTML available in a response header for inspecting
validation problems
Changed:
U zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate.py
U zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate.txt
-=-
Modified: zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate.py
===================================================================
--- zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate.py 2010-02-20 12:44:14 UTC (rev 109173)
+++ zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate.py 2010-02-20 12:44:17 UTC (rev 109174)
@@ -6,17 +6,19 @@
class ValidatingHandler(urllib2.BaseHandler):
def http_response(self, request, response):
+ source = response.read()
+ response.seek(0)
check = urllib2.urlopen(
os.environ.get('ZOPE_TESTBROWSER_VALIDATE',
'http://validator.w3.org/check'),
- urllib.urlencode(dict(fragment=response.read())))
- response.seek(0)
+ urllib.urlencode(dict(fragment=source)))
if check.info().get(
'X-W3C-Validator-Status').lower() != 'valid':
+ hdrs = check.info()
+ hdrs['X-W3C-Validator-Source'] = source
return self.parent.error(
- 'http', request, check, '500', 'Invalid HTML',
- check.info())
+ 'http', request, check, '500', 'Invalid HTML', hdrs)
return check
return response
Modified: zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate.txt
===================================================================
--- zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate.txt 2010-02-20 12:44:14 UTC (rev 109173)
+++ zope.testbrowser/branches/rossp-validator/src/zope/testbrowser/validate.txt 2010-02-20 12:44:17 UTC (rev 109174)
@@ -50,6 +50,18 @@
<h2 id="results" class="invalid">This page is <strong>not</strong> Valid (no Doctype found)!</h2>
...
+The original HTML is available in a header.
+
+ >>> print browser.headers['X-W3C-Validator-Source']
+ <html>
+ <head>
+ <title>Simple Page</title>
+ </head>
+ <body>
+ <h1>Simple Page</h1>
+ </body>
+ </html>
+
When the environment variable is not in place, the browser does
nothing with invalid HTML.
More information about the checkins
mailing list