[IronPython] Creating Python file from .NET stream with Python file mode

Sanghyeon Seo sanxiyn at gmail.com
Thu Mar 23 03:20:48 CET 2006


I now installed Windows, and tried to run SimpleHTTPServer as I did
with Mono. While doing that I found a problem.

Currently there is no way to specify Python file mode, especially
binary mode, when creating Python file object from .NET stream.

I solved this by adding following method, below "public static
PythonFile Make(object cls, Stream stream) {" in PythonFile.cs:

[PythonName("__new__")]
public static PythonFile Make(object cls, Stream stream, string mode) {
    return new PythonFile(stream, mode);
}

That way, socket.makefile("rb") works as expected, not translating
\r\n\r\n with \r\r\n\r\r\n or any such things.

Seo Sanghyeon



More information about the Ironpython-users mailing list