def validate_atom(self, url): try: import feedvalidator except ImportError: print >>sys.stderr, "No feedvalidator, skipping validation test" return try: events = feedvalidator.validateURL(url)["loggedEvents"] except feedvalidator.logging.ValidationFailure as e: events = [e.event] # Filter logged events from feedvalidator import logging events = [ e for e in events if isinstance(e, logging.Error) or ( isinstance(e, logging.Warning) and not isinstance(e, logging.DuplicateUpdated) and not isinstance(e, logging.SelfDoesntMatchLocation) ) ] # Show any remaining events from feedvalidator.formatter.text_plain import Formatter output = Formatter(events) if output: self.fail("\n".join(output))
def index(req, url="", out="xml"): if not url: s = """<html><head><title>Feed Validator</title></head><body> Enter the URL to validate: <p> <form method="GET"> URL: <input type="text" name="url"><br> <input type="submit"> <input type="hidden" name="out" value="html"> </form> </html>""" return s url = sanitizeURL(url) events = feedvalidator.validateURL(url, firstOccurrenceOnly=1)['loggedEvents'] # (optional) arg 2 is compatibility level # "A" is most basic level # "AA" mimics online validator # "AAA" is experimental; these rules WILL change or disappear in future versions from feedvalidator import compatibility filter = "AA" filterFunc = getattr(compatibility, filter) events = filterFunc(events) if out == "html": s = "<html><body><p>Validating " + escapeURL(url) + "...</p><pre>" from feedvalidator.formatter.text_plain import Formatter output = Formatter(events) if output: s += "\n".join(output) else: s += "No errors or warnings" s += "</pre></body></html>" return s else: from feedvalidator.formatter.text_xml import Formatter s = "\n".join(Formatter(events)) or "" s = '<?xml version="1.0"?>\n<validationErrors>\n' + s + "</validationErrors>" req.content_type = "application/xml" return s
def index(req,url="",out="xml"): if not url: s = """<html><head><title>Feed Validator</title></head><body> Enter the URL to validate: <p> <form method="GET"> URL: <input type="text" name="url"><br> <input type="submit"> <input type="hidden" name="out" value="html"> </form> </html>""" return s url = sanitizeURL(url) events = feedvalidator.validateURL(url, firstOccurrenceOnly=1)['loggedEvents'] # (optional) arg 2 is compatibility level # "A" is most basic level # "AA" mimics online validator # "AAA" is experimental; these rules WILL change or disappear in future versions from feedvalidator import compatibility filter = "AA" filterFunc = getattr(compatibility, filter) events = filterFunc(events) if out == "html": s = "<html><body><p>Validating " + escapeURL(url) + "...</p><pre>" from feedvalidator.formatter.text_plain import Formatter output = Formatter(events) if output: s += "\n".join(output) else: s += "No errors or warnings" s += "</pre></body></html>" return s else: from feedvalidator.formatter.text_xml import Formatter s = "\n".join(Formatter(events)) or "" s = '<?xml version="1.0"?>\n<validationErrors>\n' + s + "</validationErrors>" req.content_type = "application/xml" return s
link = sys.argv[1:] and sys.argv[1] or 'http://www.intertwingly.net/blog/index.atom' link = urlparse.urljoin('file:' + urllib.pathname2url(os.getcwd()) + '/', link) try: link = link.decode('utf-8').encode('idna') except: pass print 'Validating %s' % link curdir = os.path.abspath(os.path.dirname(sys.argv[0])) basedir = urlparse.urljoin('file:' + curdir, ".") try: if link.startswith(basedir): events = feedvalidator.validateStream(urllib.urlopen(link), firstOccurrenceOnly=1,base=link.replace(basedir,"http://www.feedvalidator.org/"))['loggedEvents'] else: events = feedvalidator.validateURL(link, firstOccurrenceOnly=1)['loggedEvents'] except feedvalidator.logging.ValidationFailure, vf: events = [vf.event] # (optional) arg 2 is compatibility level # "A" is most basic level # "AA" mimics online validator # "AAA" is experimental; these rules WILL change or disappear in future versions from feedvalidator import compatibility filter = sys.argv[2:] and sys.argv[2] or "AA" filterFunc = getattr(compatibility, filter) events = filterFunc(events) from feedvalidator.formatter.text_plain import Formatter output = Formatter(events) if output:
print "Cannot connect to site: %s" % str(e) siteFailed.append([title, entry]) if code >= 200 and code < 400: # Is a valid response print "Site successfully responded with code %s" % code elif code >= 0: print "Site responded with unexpected response code %s" % code siteFailed.append([title, entry]) print "Fetching feeds..." feed = entry.get('xmlUrl') events = None try: events = feedvalidator.validateURL( feed, firstOccurrenceOnly=1)['loggedEvents'] except feedvalidator.logging.ValidationFailure as vf: events = [vf.event] except Exception as e: print "Unable to fetch feed: %s" % str(e) feedCritical.append(e) if events is not None: from feedvalidator import compatibility from feedvalidator.formatter.text_plain import Formatter criticals = compatibility.A(events) if len(criticals) > 0: print "Feed failed validation with critical errors:" output = Formatter(criticals) print "\n".join(output)