[New-bugs-announce] [issue11352] Buf in cgi module doc
report at bugs.python.org
Mon Feb 28 13:14:21 CET 2011
New submission from Pierre Quentel <pierre.quentel at gmail.com>:
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
assignee: docs at python
nosy: docs at python, quentel
title: Buf in cgi module doc
versions: Python 3.2
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce