[issue4953] cgi module cannot handle POST with multipart/form-data in 3.0

Pierre Quentel report at bugs.python.org
Sun Jan 9 13:26:24 CET 2011


Pierre Quentel <pierre.quentel at gmail.com> added the comment:

Here is the diff file for the revised version of cgi.py

FieldStorage tests if the stream is an instance of (a subclass of) io.TextIOBase. If true, data is read from its attribute buffer ; if it hasn't one (eg for StringIO instances), an AttributeException is raised. Should we have a more specific exception ?
If false, the stream's method read() is supposed to return bytes ; an exception will be raised if it's not the case

The encoding used to decode keys and values to strings is the attribute "encoding" of the stream, or "latin-1" if this attribute doesn't exist

Besides FieldStorage, I modified the  parse() function at module level, but not parse_multipart (should it be kept at all ?)

I leave the code to set sys.stdin to binary on Windows for the moment, but it can be removed in the final version thanks to Victor's fix of issue 10841

I modified cgi_test.py and test_cgi.py (sent in a next post), all the tests pass with the revised version of cgi.py on my PC

While testing the patch I found other related things that I suppose should be changed (but need to check again - perhaps there are already tracker issues about them) :
- in http.server.CGIHTPPRequestHandler, the -u option should be removed (line 1123)
- on Windows, http.server.SimpleHTTPRequestHandler.list_directory() fails with Arabic characters (mbcs encoding fails, utf-8 works)
- in urllib.parse.unquote(), default encoding should be latin-1, not utf-8 (submitting a simple form with French accented characters raises a UnicodeEncodeError when trying to print the submitted value)

----------
Added file: http://bugs.python.org/file20322/cgi_diff_20110109.txt

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4953>
_______________________________________


More information about the Python-bugs-list mailing list