2010-03-13 06:16:06 +00:00
|
|
|
'''
|
|
|
|
Runs a given url through the w3c validator
|
|
|
|
|
|
|
|
by Vladi
|
|
|
|
'''
|
|
|
|
|
2010-04-23 03:47:41 +00:00
|
|
|
from util import hook, http
|
2010-03-13 06:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
@hook.command
|
|
|
|
def validate(inp):
|
2010-05-07 23:16:44 +00:00
|
|
|
".validate <url> -- runs url through w3c markup validator"
|
2010-03-13 06:16:06 +00:00
|
|
|
|
|
|
|
if not inp.startswith('http://'):
|
|
|
|
inp = 'http://' + inp
|
|
|
|
|
2010-04-23 03:47:41 +00:00
|
|
|
url = 'http://validator.w3.org/check?uri=' + http.quote_plus(inp)
|
|
|
|
info = dict(http.open(url).info())
|
2010-03-15 08:31:19 +00:00
|
|
|
|
|
|
|
status = info['x-w3c-validator-status'].lower()
|
|
|
|
if status in ("valid", "invalid"):
|
|
|
|
errorcount = info['x-w3c-validator-errors']
|
|
|
|
warningcount = info['x-w3c-validator-warnings']
|
|
|
|
return "%s was found to be %s with %s errors and %s warnings." \
|
|
|
|
" see: %s" % (inp, status, errorcount, warningcount, url)
|