[issue18524] BufferedReader.read1() documentation/implementation difference

Nikolaus Rath report at bugs.python.org
Wed Jul 24 20:24:52 CEST 2013


Nikolaus Rath added the comment:

On 07/24/2013 07:35 AM, Antoine Pitrou wrote:
> 
> Antoine Pitrou added the comment:
> 
>> This means that read1() will only return up to n bytes if n is smaller
>> than the buffer size, otherwise it will return at most <buffer-size>
>> bytes.
> 
> Did you actually observe such behaviour? If so, this is a bug.

Yes, that's what I see:

$ python3 bug.py
Read 20 bytes using read()
Read 10 bytes using read1()

$ cat bug.py
#!/usr/bin/env python3

import io

raw = io.BytesIO(bytes(200))
buffered = io.BufferedReader(raw, 10)

data = buffered.read(20)
print('Read %d bytes using read()' % len(data))

data = buffered.read1(20)
print('Read %d bytes using read1()' % len(data))

There should be no problem reading 20 bytes with a single call to
BytesIO.read(), yet the buffered reader returns only 10 bytes.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18524>
_______________________________________


More information about the Python-bugs-list mailing list