Issue 853963: Implement lazy read for sockets (original) (raw)
When a socket is transformed into a file object using the makefile() method, the resulting object read() behaviour requires that read(N) returns N characters or that the end of stream be reached.
This causes problems with XML parsers which call read(BufferSize) to get "something", not necessarily a full buffer.
The following patch adds a "lazy" attribute to each socket._fileobject instance, the default being set to False in order to be backward compatible. If this attribute is set to True, read(N) will return at least one character unless the end of stream is reached, and no more than N characters.