clean validate, pep8, remove CRs
This commit is contained in:
parent
09f4abea84
commit
627b83039c
|
@ -26,5 +26,3 @@ def mem(inp):
|
||||||
return 'memory usage: %d kB' % total
|
return 'memory usage: %d kB' % total
|
||||||
|
|
||||||
return mem.__doc__
|
return mem.__doc__
|
||||||
|
|
||||||
print mem('')
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ def normalize(url):
|
||||||
fragment=quote(clean(fragment), "~")
|
fragment=quote(clean(fragment), "~")
|
||||||
|
|
||||||
# note care must be taken to only encode & and = characters as values
|
# note care must be taken to only encode & and = characters as values
|
||||||
query="&".join(["=".join([quote(clean(t) , "~:/?#[]@!$'()*+,;=")
|
query="&".join(["=".join([quote(clean(t), "~:/?#[]@!$'()*+,;=")
|
||||||
for t in q.split("=", 1)]) for q in query.split("&")])
|
for t in q.split("=", 1)]) for q in query.split("&")])
|
||||||
|
|
||||||
# Prevent dot-segments appearing in non-relative URI paths.
|
# Prevent dot-segments appearing in non-relative URI paths.
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
'''
|
'''
|
||||||
Runs a given url through the w3c validator and queries
|
Runs a given url through the w3c validator
|
||||||
the result header for information
|
|
||||||
|
|
||||||
by Vladi
|
by Vladi
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
|
import urllib2
|
||||||
|
|
||||||
from util import hook
|
from util import hook
|
||||||
|
|
||||||
path = 'http://validator.w3.org/check?uri=%s'
|
|
||||||
|
|
||||||
@hook.command('val')
|
@hook.command('val')
|
||||||
@hook.command
|
@hook.command
|
||||||
|
@ -22,14 +21,15 @@ def validate(inp):
|
||||||
if not inp.startswith('http://'):
|
if not inp.startswith('http://'):
|
||||||
inp = 'http://' + inp
|
inp = 'http://' + inp
|
||||||
|
|
||||||
url = path % (urllib.quote(inp))
|
url = 'http://validator.w3.org/check?uri=%s' % urllib.quote(inp, '')
|
||||||
temp = urllib.urlopen(url).info()
|
info = dict(urllib2.urlopen(url).info())
|
||||||
|
|
||||||
status = temp.getheader('X-W3C-Validator-Status')
|
print info
|
||||||
if (status == "Valid" or status == "Invalid"):
|
status = info['x-w3c-validator-status'].lower()
|
||||||
errorcount = temp.getheader('X-W3C-Validator-Errors')
|
if status in ("valid", "invalid"):
|
||||||
warningcount = temp.getheader('X-W3C-Validator-Warnings')
|
errorcount = info['x-w3c-validator-errors']
|
||||||
return "%s was validated as %s with %s errors and %s warnings. See: %s" \
|
warningcount = info['x-w3c-validator-warnings']
|
||||||
% (inp, status.lower(), errorcount, warningcount, url)
|
return "%s was found to be %s with %s errors and %s warnings." \
|
||||||
|
" see: %s" % (inp, status, errorcount, warningcount, url)
|
||||||
else:
|
else:
|
||||||
return "Something went wrong while validating %s" % (inp)
|
return "Something went wrong while validating %s" % inp
|
||||||
|
|
Loading…
Reference in New Issue