#!/usr/bin/env python """ This is a simple-minded CGI-based driver for the web API. $Header: /cvsroot/dbagg3/htdocs/api.cgi,v 1.1 2004/09/13 14:44:50 deusx Exp $ """ import os, sys, cgi from cStringIO import StringIO # TODO: Need XML-based traceback/error reporting import cgitb; cgitb.enable() import cgiconfig import dbagg3.web.api # Capture & clone incoming data, rewind after letting cgi have a crack at it. data_in = sys.stdin.read() stdin = StringIO(data_in) form = cgi.FieldStorage(fp=stdin) stdin.seek(0) # Transmogrify form parameters into a dict params = {} try: params.update(dict(map(lambda x: (x,form.getvalue(x)), form.keys()))) except: pass env = os.environ method = env.get('REQUEST_METHOD', 'GET') base_href = 'http://%s%s' % (env['HTTP_HOST'], env['SCRIPT_NAME']) content_type = params.get('content-type', 'application/xml') path = env.get('PATH_INFO','/') dbagg3.web.api.dispatch(method, path, params, base_href, stdout=sys.stdout, stdin=stdin)