[docs] Something to be added to cgi module doc

Serguei G. Poltorak poltorak at alsenet.com
Wed Aug 25 18:50:59 CEST 2010

Dear python documentation maintainer, 

I would like to submit a small text to the cgi module documentation to help other users use this module with BaseHTTPServer.HTTPServer. The current documentation (http://docs.python.org/library/cgi.html) shortly describes the usage of this module as a CGI under Apache. It does not covers at all the usage of cgi with BaseHTTPServer module. I've passed about an hour reading cgi.py sources to make it work, so I would like to share my knowledge with others. 

Be so kind to include (mangled by you) the following text: 
Running with no parameters FieldStorage will read sys.stdin and use os.environ as environment variable. To use this module with BaseHTTPServer you must initialize FieldStorage with the rfile coming from WebHandler, pass headers as is and construct your ow environ to inform FieldStorage about the method used and the query string. Example for do_POST() function: 
form = cgi.FieldStorage(fp=self.rfile, headers=self.headers.dict, environ={"REQUEST_METHOD": "POST", "QUERY_STRING": self.path}) 
See "print cgi.FieldStorage.__doc__" for more information on FieldStorage() parameters. 

To upload files use enctype="multipart/form-data" . For example: 
<form method="post" action="/my/url/to/python/script" enctype="multipart/form-data"> 
<input type="file" name="filename"/> 
<input type="hidden" name="additional params" value="123"/> 
<input type="submit"/> 

Thank you for your great work! 

Sincerely yours, 
Poltorak Sergeui 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20100825/18d00710/attachment.html>

More information about the docs mailing list