2 # Apache mod_wsgi python interface
4 # Copyright (C) 2004-2006 The Trustees of Princeton University
5 # $Id: ModWSGI.py 14587 2009-07-19 13:18:50Z tmack $
6 # $URL: svn+ssh://svn.planet-lab.org/svn/PLCAPI/trunk/ModWSGI.py $
10 sys.path.append('/usr/share/plc_api')
11 sys.stdout = sys.stderr
13 from PLC.Debug import log
14 from PLC.API import PLCAPI
18 def application(environ, start_response):
21 if environ.get('REQUEST_METHOD') != 'POST':
22 content_type = 'text/html'
25 <title>PLCAPI WSGI XML-RPC/SOAP Interface</title>
27 <h1>PLCAPI WSGI XML-RPC/SOAP Interface</h1>
28 <p>Please use XML-RPC or SOAP to access the PLCAPI.</p>
33 content_type = 'text/xml'
34 ip = environ.get('REMOTE_ADDR')
35 port = environ.get('REMOTE_PORT')
36 output = api.handle((ip,port), environ.get('wsgi.input').read())
37 # Shut down database connection, otherwise up to MaxClients DB
38 # connections will remain open.
40 except Exception, err:
41 status = '500 Internal Server Error'
42 content_type = 'text/html'
43 output = 'Internal Server Error'
44 print >> log, err, traceback.format_exc()
47 response_headers = [('Content-type', '%s' % content_type),
48 ('Content-Length', str(len(output)))]
49 start_response(status, response_headers)