#!/usr/bin/env python # utf-8 must be used # comments in CDATA may or may not be parsed import cgitb cgitb.enable() import sys, os, re, urllib sys.path = ['..', '../trio'] + sys.path import trio def homepage(): print 'Content-Type: text/html' print f = open('about.html') for line in f: print line.rstrip('\r\n') f.close() sys.exit() requri = os.environ.get('REQUEST_URI') uri = requri.split('hturtle/', 1).pop() if not uri or uri.startswith('?'): try: uri = __import__('cgi').FieldStorage()['uri'].value # print 'Content-Type: text/plain' # print if uri.startswith('http://'): uri = uri[7:] # print 'URI:', uri print 'Status: 307' print 'Location: http://inamidst.com/sw/hturtle/' + uri print print 'Go!' % uri sys.exit() except KeyError: homepage() print 'Content-Type: text/xml' print if not uri.startswith('http://'): uri = 'http://' + uri r_comment = re.compile(r'') G = trio.Graph(baseURI=uri) u = urllib.urlopen(uri) bytes = u.read() u.close() bindings = """\ @prefix rdf: . @prefix rdfs: . @prefix owl: . @prefix dc: . @prefix foaf: . @prefix doap: . @prefix skos: . """ turtle = bindings + '\n'.join(r_comment.findall(bytes)) + '\n' turtle = turtle.decode('utf-8') G.parseText(turtle, 'turtle') print '' print '' for line in G.serialiseToLines('rdfxml'): print line print '' print '' # EOF