New submission from Torsten Rottmann <[email protected]>:
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.
----------
components: Library (Lib)
messages: 86274
nosy: trott
severity: normal
status: open
title: io.BufferedReader.peek(): Documentation differs from Implementation
type: behavior
versions: Python 3.0
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue5811>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com