#!/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 """ RSS 1.1 Validation Results
""" if validity == 'Valid': icon = ('tick', 'Valid') else: icon = ('cross', 'Invalid') print '' print """

RSS 1.1 Validation Results

""" print '

{ For URI: <%s> }

' % (uri, uri) if validity == 'Valid': print '

This feed is valid RSS 1.1!

' else: print '

This feed is NOT valid RSS 1.1!

' warnings = int(report['Warnings']) errors = int(report['Errors']) if warnings or errors: 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 '

Error Messages

' if len(errorMessages) > 50: print '

Note: only showing the first 50 errors.

' print '' if warningMessages: print '

Warning Messages

' if len(warningMessages) > 50: print '

Note: only showing the first 50 warnings.

' print '' print ("""

Where Now?

Validate by URI
Address:

Revalidate, or validate another document, but entering the URI above.

Or return to the RSS 1.1 Validator homepage.

Contact: Sean B. Palmer
""") def homepage(): print 'Content-Type: text/html' print print (""" RSS 1.1 Feed Validator

RSS 1.1 Validator

Validate by URI
Address:

Enter the URI of the document that you want to check.

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.

{ Maintainer: Sean B. Palmer }
""") def barf(e): print "Content-Type: text/html" print print (""" RSS 1.1 Validator Error

RSS 1.1 Validator Error

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:

Your email address:
{ 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()