This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author trott
Recipients trott
Date 2009-04-22.06:15:47
SpamBayes Score 2.57619e-05
Marked as misclassified No
Message-id <>
The documented behavior of io.BufferedReader.peek([n]) states:

Return 1 (or n if specified) bytes from a buffer without advancing the 

Thereas the parameter n is the _max_ length of returned bytes.

Implementation is:

    def _peek_unlocked(self, n=0):
        want = min(n, self.buffer_size)
        have = len(self._read_buf) - self._read_pos
        if have < want:
            to_read = self.buffer_size - have
            current =
            if current:
                self._read_buf = self._read_buf[self._read_pos:] + 
                self._read_pos = 0
        return self._read_buf[self._read_pos:]

Where you may see that the parameter n is the _min_ length
of returned bytes. So peek(1) will return _not_ just 1 Byte, but the
remaining bytes in the buffer.
Date User Action Args
2009-04-22 06:15:55trottsetrecipients: + trott
2009-04-22 06:15:53trottsetmessageid: <>
2009-04-22 06:15:51trottlinkissue5811 messages
2009-04-22 06:15:48trottcreate