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 nikratio
Recipients benjamin.peterson, hynek, nikratio, pitrou, r.david.murray, serhiy.storchaka, stutzbach
Date 2013-07-24.21:58:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <51F04E6F.1010904@rath.org>
In-reply-to <1374702683.2619.5.camel@fsol>
Content
On 07/24/2013 02:51 PM, Antoine Pitrou wrote:
> 
> Antoine Pitrou added the comment:
> 
> Le mercredi 24 juillet 2013 à 21:45 +0000, Nikolaus Rath a écrit :
>> The documentation is correct that read1(n) never returns more than n bytes.
>>
>> My complaint is that the actual bound is stricter than this, band
>> read1(n) will never return more than min(n, bufsize) bytes.
> 
> That's not really true. If the buffer is empty, read1(n) will try to
> read at most n bytes from the raw stream. So:
> - if the buffer is not empty, the whole buffer is returned and 0 raw I/O
> call is issued
> - if the buffer is empty, 1 raw I/O call is issued and at most 1 byte is
> returned
> 
> Therefore, if you call read1(n) in a loop, all calls but the first will
> really try to read *n* bytes from the raw stream (because the first call
> will have emptied the buffer).

I agree that this is how it *should* work. But that's not what's
happening in practice:

> $ python3
Python 3.2.3 (default, Feb 20 2013, 14:44:27)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
>>> raw = io.BytesIO(bytes(200))
>>> buffered = io.BufferedReader(raw, 10)
>>> while True:
...     buf = buffered.read1(20)
...     print('Read %d bytes' % len(buf))
...     if not buf:
...        break
...
Read 10 bytes
Read 10 bytes
Read 10 bytes
Read 10 bytes
Read 10 bytes
Read 10 bytes
Read 10 bytes
Read 10 bytes
[...]
History
Date User Action Args
2013-07-24 21:58:51nikratiosetrecipients: + nikratio, pitrou, benjamin.peterson, stutzbach, r.david.murray, hynek, serhiy.storchaka
2013-07-24 21:58:51nikratiolinkissue18524 messages
2013-07-24 21:58:51nikratiocreate