Using BaseHTTPServer

Lars von Wedel lvw at lfpt.rwth-aachen.de
Fri Apr 28 06:25:15 EDT 2000


Hello,

 > > Within any of the do_GET methods, how do I access data that has been
 > > sent by the client (...&data1=val1?data2=val2?...)?
 >
 > Use the CGI module <wink>. Just copy the code from CGIHTTPServer to create
 > the dictionary, (not as os.environ), and use the cgi module to parse
 > that dictionary.

I have been looking into CGIHTTPServer.py a little. I think, it should
be possible to modify run_cgi() (in a subclass) in the following way:

 - Decode self.cgi_info as shown additionally use cgi.parse_qs
   to write results (directory with CGI arguments) into
   e.g. self.cgi_args

 - fork the process (same as original run_cgi())

 - Associate stdin with self.rfile and stdout with self.wfile

 - Instead of running a script with name 'scriptname'
   call a method on 'self' called 'scriptname'.

 - The method called can access self.cgi_args to access
   the data passed and it can simply write to stdout
   using print.


Lars






More information about the Python-list mailing list