#!/usr/bin/env python # -*- coding: utf-8 -*- """ Knowledge Closure.SPARUL adapter by kennyluck """ import sys import os #@@ change this to suitable folder if os.environ['HTTP_HOST'] == 'dig.csail.mit.edu': WRITABLE_DIRECTORY = "/afs/csail.mit.edu/group/dig/www/data/2008/webdav/Knowledge_Closure/" else: WRITABLE_DIRECTORY = "" import re from urlparse import urlparse import httplib NETLOC, PATH = 1, 2 log = open(WRITABLE_DIRECTORY + "inform_log.txt", 'w') def LOG(string): log.write(string + '\n') original_data = sys.stdin.read() LOG("get from client: ") LOG(original_data) #@@ just a fast prototyle, should be a complete SPARQL parser match = re.match(r"INSERT\s+INTO\s+<(?P\S+)>(?P.+)", original_data, re.DOTALL) if not match: #@@ 500 sys.exit(0) dict = match.groupdict() machine, location = urlparse(dict['graph_uri'])[NETLOC:(PATH+1)] sent_data = "INSERT" + dict["clause"] headers = {"Content-type" : 'application/sparql-query'} conn = httplib.HTTPConnection(machine) conn.request("POST", location, sent_data, headers) response = conn.getresponse() # print response.status, response.reason #a 500 happened because of this data = response.read() conn.close() LOG("Response:") LOG(data) print "Content-type: text/plain" print print "SUCCESS" LOG("End: nothing goes wrong") log.close()