[Python-Dev] io.BufferedReader.peek() Behaviour in python3.1

Antoine Pitrou solipsis at pitrou.net
Sat Jun 13 14:16:14 CEST 2009


Nick Coghlan <ncoghlan <at> gmail.com> writes:
> 
> Since the latter method will perform as many reads of the underlying
> stream as necessary to reach the requested number of bytes (or EOF),
> then so should the former.

How do you propose to implement this while staying compatible with
1) unseekable raw streams
2) the expectation that peek() doesn't advance the logical file pointer?

> Note that the current behaviour I get from Python 3.1 is for it to
> return the *entire* buffer, no matter what number I pass to it:
> 
[...]
> 
> That's an outright bug - I've promoted an existing issue about this [1]
> to a release blocker and sent it to Benjamin to have another look at.

The original docstring for peek() says:

        """Returns buffered bytes without advancing the position.

        The argument indicates a desired minimal number of bytes; we
        do at most one raw read to satisfy it.  We never return more
        than self.buffer_size.
        """

In that light, I'm not sure it's a bug -- although it can certainly look
unexpected at first sight.

Regards

Antoine.




More information about the Python-Dev mailing list