Comment 2 for bug 1515231

Revision history for this message
Ben Nemec (bnemec) wrote :

Looking at this a little closer, it seems to me that there is a fundamental problem with this function on Python 3. It allows the user to specify an encoding, but because the file object passed in may or may not have been opened in binary mode, we can't necessarily decode it. If it was opened in normal 'r' mode, the value we get back from read() is already going to be decoded to utf-8.

I think we would need to detect whether the object passed in is giving us bytes or a str and treat it appropriately. If they give us something that results in a utf-8 str and they passed something other than utf-8 as the encoding that would be an error.