#!/usr/bin/env python """ CGI Frontend for the RSS 1.1 Validator Author: Sean B. Palmer License: GPL 2; share and enjoy! Requires: http://inamidst.com/rss1.1/validator.py """ import cgitb; cgitb.enable() import sys, cgi, urllib import validator form = cgi.FieldStorage() form.__call__ = lambda s: form[s].value def validate(uri): if ':' not in uri: raise ValueError, "Sorry, only absolute URIs are allowed." report = validator.pyreport(uri) validity = report['Summary'] print 'Content-Type: text/html' print print """
{ For URI: <%s> }
' % (uri, uri) if validity == 'Valid': print '' if warnings: print 'Warnings: %s' % warnings if warnings and errors: print '; ' if errors: print 'Errors: %s' % errors print '
' else: print 'Congratulations: your feed produced no warnings, ' print 'and no error messages.
' warningMessages = report['WarningMessages'] errorMessages = report['ErrorMessages'] if errorMessages: print 'Note: only showing the first 50 errors.
' print 'Note: only showing the first 50 warnings.
' print 'Or return to the RSS 1.1 Validator homepage.
Contact: Sean B. Palmer """) def homepage(): print 'Content-Type: text/html' print print ("""This service validates your document against the RSS 1.1 Specification to let you know whether or not it is conformant. A conformant feed is more likely to be able to be parsed correctly by aggregators and other user agents. Examples from the RSS 1.1 test suite:
You may also like to browse the python source code for this validator; it requires the RSS 1.1 validator.py module. Related resources: RSS Feed Converter, A Rough Guide to RSS 1.1.
Sorry, the validator was unable to complete your request for the following reason: """ + cgi.escape('%r' % str(e)) + """. If you believe this message to be in error, please submit feedback using the following form:
{ Maintainer: Sean B. Palmer } """) def main(): if form.has_key('uri'): uri = form('uri') if not form.has_key('debug'): try: validate(uri) except Exception, e: barf(e) else: validate(uri) else: homepage() if __name__=="__main__": main()