/proj/grddl/demo.cgi
#!/usr/bin/env python
"""
GRDDL Demonstration
License: GPL 2; share and enjoy!
Author: Sean B. Palmer, inamidst.com
Service: http://inamidst.com/proj/grddl/demo
Source: http://inamidst.com/inside/proj/grddl/demo
Requirements:
http://inamidst.com/misc/cgiutil.py
http://inamidst.com/grddl/garner.py
http://infomesh.net/pyrple/
---
<title>GRDDL Demonstration (using Pyrple and garner.py)</title>
<link rel="stylesheet" type="text/css" href="/trove/pwyky.css" />
<h1>GRDDL Demo</h1>
<p>This demonstration uses <a href="http://inamidst.com/\
grddl/garner.py">garner.py</a> and <a href="http://infomesh\
.net/pyrple/">Pyrple</a> to <a href="http://www.w3.org/2003/\
g/data-view">GRDDL</a> itself up some RDF.</p>
<form action="./demo" method="GET">
URI: <input type="text" name="uri" size="35" value="http://\
www.w3.org/2003/12/rdf-in-xhtml-xslts/complete-example" />
<input type="submit" />
</form>
<p>Also: the <a href="/inside/proj/grddl/demo">source of
this demo</a>. The W3C also maintains a <a
href="http://www.w3.org/2003/11/rdf-in-xhtml-demo"
>similar service</a>.</p>
<address>
<a href="http://inamidst.com/sbp/">Sean B. Palmer</a>
</address>
"""
import cgitb; cgitb.enable()
import sys; sys.path.extend(('/home/sbp/tools', '../../misc'))
import garner, pyrple
from cgiutil import serve, form, method
def demo():
if not form.has_key('format'):
format = 'rdfxml'
else: format = form('format')
if format not in ('rdfxml', 'ntriples'):
serve(500, '<p>Format %s is not supported.</p>\n' % format)
result = garner.garner(form('uri'), format=format)
mime = {'ntriples': 'text/plain',
'rdfxml': 'application/rdf+xml'}[format]
serve(200, result, mime=mime)
def homepage():
i = __doc__.find('---')
serve(200, __doc__[i+3:])
def main():
if form.has_key('uri'): demo()
elif method == 'GET': homepage()
else: serve(501, "<p>Only GET is supported.</p>\n")
if __name__=="__main__":
main()