Message162905
| Author |
serhiy.storchaka |
| Recipients |
Arfrever, docs@python, jaraco, jgeralnik, pitrou, r.david.murray, serhiy.storchaka, zach.ware |
| Date |
2012年06月15日.14:41:18 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1339771282.6648.143.camel@raxxla> |
| In-reply-to |
<1339770034.92.0.432946035346.issue15068@psf.upfronthosting.co.za> |
| Content |
> The patch I've attached checks if the number of bytes read from the file is less than the size of the buffer (which means that the file has ended).
>From io.RawIOBase.read docs:
"""
Read up to n bytes from the object and return them. As a convenience, if
n is unspecified or -1, readall() is called. Otherwise, only one system
call is ever made. Fewer than n bytes may be returned if the operating
system call returns fewer than n bytes.
If 0 bytes are returned, and n was not 0, this indicates end of file.
"""
This is not an arbitrary assumption. In particular, when reading from a
terminal with line buffering (you can edit the line until you press
Enter) on C level you read only a whole line (if line length is not
greater than buffer length) and 0 bytes you will receive only by
pressing ^D or ^Z at the beginning of the line. Same for pipes and
sockets. On Python level there are many third-party implementations of
file-like objects which rely on this behavior, you cannot rewrite all of
them. |
|