Permalink
Browse files

Sample front end suitable for use with mod_python.

Contributed by Andrew Grumet.


git-svn-id: http://feedvalidator.googlecode.com/svn/trunk@122 34a10a33-d82d-0410-ba40-81c901463ecc
  • Loading branch information...
1 parent 4d7201b commit dacb283063ddab8a0b2cfa300e5b5201b1054de1 @rubys committed Jun 23, 2004
Showing with 54 additions and 0 deletions.
  1. +54 −0 src/index.py
View
@@ -0,0 +1,54 @@
+import feedvalidator
+import sys
+
+def index(req,url="",out="xml"):
+
+ if not url:
+ s = """<html><head><title>RSS 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
+
+ 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 " + 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
+
+if __name__=="__main__":
+ import sys
+ for url in sys.argv[1:]:
+ print index(0,url=url,out="html")

0 comments on commit dacb283

Please sign in to comment.