Hi,
I found the StreamReader.readexactly(n) function which has a strange
behaviour. It reads exactly n bytes... but it returns less if the end
of stream is reached.
Why not raising an exception? When I use such function, I expected to
get... exactly... n bytes, not "almost" n bytes :-)
It would be annoying to write:
data = reader.readexactly(n)
if len(data) != n: ...
For each call to readexactly(). I prefer to write optimistic code and
maybe catch an exception if needed.
We may raise an exception with the incomplete data. For example,
subprocess.check_call() raises an exception which contains the return
code, the command and the output. The io module uses a BlockingIOError
which contains the number of written bytes.
The code even contains this comment:
# TODO: Raise EOFError if we break before n == 0? (That would
# be a change in specification, but I've always had to add an
# explicit size check to the caller.)
I opened an issue with a patch to raise an IncompleteReadError which
inherits from EOFError and contains the partial data:
http://code.google.com/p/tulip/issues/detail?id=111
Victor