3 # Apache mod_wsgi python interface
5 # Copyright (C) 2004-2006 The Trustees of Princeton University
9 sys.path.append('/usr/share/plc_api')
10 sys.stdout = sys.stderr
12 from PLC.Debug import log
13 from PLC.API import PLCAPI
17 # recipe from this page
18 # http://code.google.com/p/modwsgi/wiki/DebuggingTechniques
19 # let ErrorMiddleware deal with exceptions
20 def application(environ, start_response):
22 if environ.get('REQUEST_METHOD') != 'POST':
23 content_type = 'text/html'
26 <title>PLCAPI WSGI XML-RPC/SOAP Interface</title>
28 <h1>PLCAPI WSGI XML-RPC/SOAP Interface</h1>
29 <p>Please use XML-RPC or SOAP to access the PLCAPI.</p>
34 content_type = 'text/xml'
35 ip = environ.get('REMOTE_ADDR')
36 port = environ.get('REMOTE_PORT')
37 output = api.handle((ip,port),environ.get('wsgi.input').read())
38 # Shut down database connection, otherwise up to MaxClients DB
39 # connections will remain open.
43 response_headers = [('Content-type', '%s' % content_type),
44 ('Content-Length', str(len(output)))]
45 start_response(status, response_headers)
48 from paste.exceptions.errormiddleware import ErrorMiddleware
49 application = ErrorMiddleware(application, debug=True)