This patch causes the readline, readlines, read and
readinto methods of file objects (as well as
PyFile_ReadLine() called on actual fileobjects) to
raise an exception if (and only if) there is data in
the file-iteration buffer. Currently, if any of these
methods are called during file-iteration (with a
non-empty buffer), the read* methods return data
following the buffer, causing the data to seem out of
order. Or, if all of the file's remaining data is in
the buffer, truncated.
The patch is only supposed to raise an error when,
previously, the file's data would get corrupted. It
doesn't prevent mixing iteration and read*-methods in
harmless situations (methods followed by iteration,
iteration until EOF followed by methods, or iteration
until an exact buffer boundary, followed by methods.)
The exception currently raised is ValueError, because
it seems least inappropriate. Also, read* on closed
files raises ValueError (probably for the same reason.)
The test_file test has been ammended to include tests
for this behaviour.
|