Glenn Linderman <v+pyt...@g.nevcal.com> added the comment:

Pierre said:
Option 1 is impossible, because the CGI script sometimes has no control on the 
stream : for instance on a shared web host, it will receive sys.stdin as a text 
stream

I say:
It is the user code of the CGI script that calls CGI.FieldStorage.  So the user 
could be required (option 1) to first tweak the stdin to be bytes, one way or 
another.  I don't understand any circumstance where a Python CGI script doesn't 
have control over the settings of the Python IO Stack that it is using to 
obtain the data... and the CGI spec is defined as a bytestream, so it must be 
able to read the bytes.

Victor said:
It is possible to test the type of the stream.

I say:
Yes, why just assume (as I have been) that the initial precondition is the 
defaults that Python imposes.  Other code could have interposed something else. 
 The user should be allowed to pass in anything that is a TextIOWrapper, or a 
BytesIO, and CGI should be able to deal with it.  If the user passes some other 
type, it should be assumed to produce bytes from its read() API, and if it 
doesn't the user gets what he deserves (an error).  Since the default Python 
sys.stdin is a TextIOWrapper, having CGI detect that, and extract its .buffer 
to use for obtaining bytes, should work fine.  If the user already tweaked 
sys.stdin to be a BytesIO (.buffer or detach()), CGI should detect and use 
that.  If the user substitutes a different class, it should be bytes, and that 
should be documented, the three cases that could work.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue4953>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to