def check(url, path): """A HEAD request to URL. If HEAD is not allowed, we try GET.""" try: get(url, timeout=10) except HTTPError as e: if e.code == 405: try: get(url, path, 'GET', True) except URLError as e: print(' ' + yellow(e.reason), url) print(white(' -- ' + path)) else: print(' ' + red(e.code), url) print(white(' -- ' + path)) except URLError as e: print(' ' + yellow(e.reason), url) print(white(' -- ' + path))
def check(url, path): """A HEAD request to URL. If HEAD is not allowed, we try GET.""" try: get(url, timeout=10) except HTTPError as e: if e.code == 405: try: get(url, path, 'GET', True) except URLError as e: print ' ' + yellow(e.reason), url print white(' -- ' + path) else: print ' ' + red(e.code), url print white(' -- ' + path) except URLError as e: print ' ' + yellow(e.reason), url print white(' -- ' + path)
def w3c(paths, conf, warn=False, sleep=0.2): """Validate HTML by using the validator.w3.org API. :param paths: a list of HTML files we map to our actual domain :param conf: configuration :param warn: don't handle warnings as success when set :param sleep: sleep between requests (be nice to their API)""" for path in paths: url = path[len(conf['output_dir']) - 1:] resp = head("http://validator.w3.org/check?uri=" + \ helpers.joinurl(conf['www_root'], quote(url))) print helpers.rchop(url, 'index.html'), if resp.code != 200: print red('not 200 Ok!') continue headers = resp.info() if headers['x-w3c-validator-status'] == "Abort": print red("Abort") elif headers['x-w3c-validator-status'] == 'Valid': if int(headers['x-w3c-validator-warnings']) == 0: print green('Ok') else: if warn: print yellow(headers['x-w3c-validator-warnings'] + ' warns') else: print green('Ok') else: res = headers['x-w3c-validator-errors'] + ' errors, ' + \ headers['x-w3c-validator-warnings'] + ' warns' print red(res) time.sleep(sleep)
def w3c(paths, conf, warn=False, sleep=0.2): """Validate HTML by using the validator.w3.org API. :param paths: a list of HTML files we map to our actual domain :param conf: configuration :param warn: don't handle warnings as success when set :param sleep: sleep between requests (be nice to their API)""" for path in paths: url = path[len(conf['output_dir'])-1:] resp = head("http://validator.w3.org/check?uri=" + \ helpers.joinurl(conf['www_root'], quote(url))) print helpers.rchop(url, 'index.html'), if resp.code != 200: print red('not 200 Ok!') continue headers = resp.info() if headers['x-w3c-validator-status'] == "Abort": print red("Abort") elif headers['x-w3c-validator-status'] == 'Valid': if int(headers['x-w3c-validator-warnings']) == 0: print green('Ok') else: if warn: print yellow(headers['x-w3c-validator-warnings'] + ' warns') else: print green('Ok') else: res = headers['x-w3c-validator-errors'] + ' errors, ' + \ headers['x-w3c-validator-warnings'] + ' warns' print red(res) time.sleep(sleep)