blob: 0820f82e2a0b41112c369492abe5232527461723 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001from __future__ import print_function
2import sys
3
4import httplib2
5import config
6import urllist
7
8
9config.logger.info("Testing %s with %s", config.TOASTER_BASEURL, config.W3C_VALIDATOR)
10
11def validate_html5(url):
12 http_client = httplib2.Http(None)
13 status = "Failed"
14 errors = -1
15 warnings = -1
16
17 urlrequest = config.W3C_VALIDATOR+url
18
19 # pylint: disable=broad-except
20 # we disable the broad-except because we want to actually catch all possible exceptions
21 try:
22 resp, _ = http_client.request(urlrequest, "HEAD")
23 if resp['x-w3c-validator-status'] != "Abort":
24 status = resp['x-w3c-validator-status']
25 errors = int(resp['x-w3c-validator-errors'])
26 warnings = int(resp['x-w3c-validator-warnings'])
27
28 if status == 'Invalid':
29 config.logger.warn("Failed %s is %s\terrors %s warnings %s (check at %s)", url, status, errors, warnings, urlrequest)
30 else:
31 config.logger.debug("OK! %s", url)
32
33 except Exception as exc:
34 config.logger.warn("Failed validation call: %s", exc)
35 return (status, errors, warnings)
36
37
38def print_validation(url):
39 status, errors, warnings = validate_html5(url)
40 config.logger.error("url %s is %s\terrors %s warnings %s (check at %s)", url, status, errors, warnings, config.W3C_VALIDATOR+url)
41
42
43def main():
44 print("Testing %s with %s" % (config.TOASTER_BASEURL, config.W3C_VALIDATOR))
45
46 if len(sys.argv) > 1:
47 print_validation(sys.argv[1])
48 else:
49 for url in urllist.URLS:
50 print_validation(config.TOASTER_BASEURL+url)
51
52if __name__ == "__main__":
53 main()