import os, sys
import BaseHTTPServer, cgi
servAddr = ('',8080)
#Define the HTTP handler that overrides do_GET
class httpServHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
if self.path.find('?') != -1:
self.path, self.query_string = self.path.split('?', 1)
else:
self.query_string = ''
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
#Setup Global Environment
self.globals = dict(cgi.parse_qsl(self.query_string))
#Redirect output to browser
sys.stdout = self.wfile
#Execute the script remotely
self.wfile.write("<h2>Handle Get</h2><P>")
self.wfile.write("<LI>Executing <b>%s</b>" % (self.path))
self.wfile.write( "<li>With Globals<B>%s</b><hr>" % (self.globals))
execfile(self.path, self.globals)
os.chdir('/myTest')
serv = BaseHTTPServer.HTTPServer(servAddr, httpServHandler)
serv.serve_forever()