SetOutputFileHandle only works with legit file objects with file descriptors. It ought to work with subclasses of IOBase as well.
This patch adds support for passing an arbitrary python stream (anything inheriting from IOBase) to SetOutputFileHandle or SetErrorFileHandle.
It also fixes some crashes associated with PythonFile.
Supposedly it also works for SetInputFileHandle, but as far as I can tell nothing actually uses the input file handle so I coluldn’t figure out how to test that part at all.