Author quentel
Recipients docs@python, quentel
Date 2011-02-28.12:14:19
SpamBayes Score 1.11022e-16
Marked as misclassified No
Message-id <1298895261.86.0.965235067518.issue11352@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

I wrote a patch for the cgi module in version 3.2rc1 (#4953). Small changes should be done to the documentation of this module to reflect the changes in the module API :

- in section "20.2.2. Using the cgi module"

original text :
"If a field represents an uploaded file, accessing the value via the value attribute or the getvalue() method reads the entire file in memory as a string. This may not be what you want. You can test for an uploaded file by testing either the filename attribute or the file attribute. You can then read the data at leisure from the file attribute:"

proposed new text (for files, value is bytes, not string, and the read() method on file also returns bytes) :
"If a field represents an uploaded file, accessing the value via the value attribute or the getvalue() method reads the entire file in memory as bytes. This may not be what you want. You can test for an uploaded file by testing either the filename attribute or the file attribute. You can then read the data at leisure from the file attribute (the read() and readline() methods will return bytes) :"

- version 3.2 introduced a parameter "encoding" for the FieldStorage constructor, used to decode the bytes received on the HTTP connection for fields other than files. This encoding must the one defined in the HTML document holding the form submitted to the CGI script ; it is usually defined by a meta tag :
<meta http-equiv="Content-type" content="text/html;charset=latin-1">
or by the Content-Type header for this document

I'm not sure where this should be mentioned in the module documentation. Maybe in "20.2.9. Common problems and solutions" for the moment. But there are plans (#11066) to introduce another interface to change the encoding of sys.stdout in the CGI script itself, so another option would be to open a specific section about encodings

Hope it's clear enough
Pierre
History
Date User Action Args
2011-02-28 12:14:22quentelsetrecipients: + quentel, docs@python
2011-02-28 12:14:21quentelsetmessageid: <1298895261.86.0.965235067518.issue11352@psf.upfronthosting.co.za>
2011-02-28 12:14:19quentellinkissue11352 messages
2011-02-28 12:14:19quentelcreate