def pingback(src, dest, dryrun=False): """Makes a pingback request to dest on behalf of src, i.e. effectively saying to dest that "the page at src is linking to you".""" def search_link(content): match = re.search(b'<link rel="pingback" href="([^"]+)" ?/?>', content) return match and match.group(1) try: r = head(dest) except (URLError, HTTPError) as e: return try: server_url = r.info().get('X-Pingback', '') or search_link( r.read(512 * 1024)) if server_url: print("Pingback", blue(urlparse(server_url).netloc), end='') print("from", green(''.join(urlparse(src)[1:3])) + ".") if not dryrun: server = xmlrpc.client.ServerProxy(server_url) server.pingback.ping(src, dest) except xmlrpc.client.ProtocolError as e: raise AcrylamidException(e.args[0])
def pingback(src, dest, dryrun=False): """Makes a pingback request to dest on behalf of src, i.e. effectively saying to dest that "the page at src is linking to you".""" def search_link(content): match = re.search(b'<link rel="pingback" href="([^"]+)" ?/?>', content) return match and match.group(1) try: r = head(dest) except (URLError, HTTPError) as e: return try: server_url = r.info().get('X-Pingback', '') or search_link(r.read(512 * 1024)) if server_url: print("Pingback", blue(urlparse(server_url).netloc), end='') print("from", green(''.join(urlparse(src)[1:3])) + ".") if not dryrun: server = xmlrpc.client.ServerProxy(server_url) server.pingback.ping(src, dest) except xmlrpclib.Fault as e: log.warn("XML-RPC fault: %d (%s)", e.faultCode, e.faultString) except xmlrpc.client.ProtocolError as e: raise AcrylamidException(e.args[0])
def pingback(src, dest): """Makes a pingback request to dest on behalf of src, i.e. effectively saying to dest that "the page at src is linking to you".""" def search_link(content): match = re.search(r'<link rel="pingback" href="([^"]+)" ?/?>', content) return match and match.group(1) request_url = 'http:%s' % dest if dest.startswith('//') else dest try: info = head(request_url).info() except (URLError, HTTPError) as e: raise AcrylamidException(e.args[0]) try: server_url = info.get('X-Pingback', '') or search_link(f.read(512 * 1024)) if server_url: server = xmlrpclib.ServerProxy(server_url) server.pingback.ping(src, dest) except xmlrpclib.ProtocolError as e: raise AcrylamidException(e.args[0])
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'), end=' ') 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)