Author trott
Recipients trott
Date 2009-04-22.06:15:47
SpamBayes Score 2.57619e-05
Marked as misclassified No
Message-id <1240380953.7.0.732520909261.issue5811@psf.upfronthosting.co.za>
In-reply-to
Content
The documented behavior of io.BufferedReader.peek([n]) states:

peek([n])
Return 1 (or n if specified) bytes from a buffer without advancing the 
position.

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 = self.raw.read(to_read)
            if current:
                self._read_buf = self._read_buf[self._read_pos:] + 
current
                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.
History
Date User Action Args
2009-04-22 06:15:55trottsetrecipients: + trott
2009-04-22 06:15:53trottsetmessageid: <1240380953.7.0.732520909261.issue5811@psf.upfronthosting.co.za>
2009-04-22 06:15:51trottlinkissue5811 messages
2009-04-22 06:15:48trottcreate