Pierre Quentel <pierre.quen...@gmail.com> added the comment:

@Glenn
"Also, the use of FeedParser could be replaced by BytesFeedParser, thus 
eliminating the need to decode header lines in that loop."

BytesFeedParser only uses the ascii codec ; if the header has non ASCII 
characters (filename in a multipart/form-data), they are replaced by ? : the 
original file name is lost. So for the moment I leave the text version of 
FeedParser

@Victor :
"you should use qs.encode(locale.getpreferredencoding(), 'surrogateescape')"
Ok, I changed the code to that

"Maybe a DeprecationWarning if we would like to drop support of TextIOWrapper 
later :-)"
Maybe I'm missing something here, but sys.stdin is always a TextIOWrapper 
instance, even if set to binary mode

"For the else case: you should maybe add a strict test on the type, eg. check 
for RawIOBase or BufferedIOBase subclass, isinstance(fp, (io.RawIOBase, 
io.BufferedIOBase)). It would avoid to check that fp.read() returns a bytes 
object (or get an ugly error later)."

Rejecting non-instances of RawIOBase or BufferedIOBase is too much, I think. 
Any class whose instances have a read() method that return bytes should be 
accepted, like the TestReadLine class in test_cgi.py

"Set sys.stdin.buffer.encoding attribute is not a good idea. Why do you modify 
fp, instead of using a separated attribute on FieldStorage (eg. 
self.fp_encoding)?"

I set an attribute encoding to self.fp because, for each part of a 
multipart/form-data, a new instance of FieldStorage is created, and this 
instance needs to know how to decode bytes. So, either an attribute must be set 
to one of the arguments of the FieldStorage constructor, and fp comes to mind, 
or an extra argument has to be passed to this constructor, i.e. the encoding of 
the original stream

----------

_______________________________________
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