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.
Created on 2009年01月19日 10:09 by kawai, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (10) | |||
|---|---|---|---|
| msg80152 - (view) | Author: HiroakiKawai (kawai) | Date: 2009年01月19日 10:09 | |
The documentation says io.TextIOWrapper wraps io.BufferedIOBase raw stream. In the code, io.TextIOWrapper.read(), io.TextIOWrapper._read_chunk() calls buffer.read1() which seems expecting buffer to be an instance of io.BufferedReader. I'm not sure which is correct right now. |
|||
| msg80167 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2009年01月19日 13:28 | |
Indeed, read1() is not documented as a standard method of either IOBase, RawIOBase or BufferedIOBase. I suggest that it becomes a standard method of IOBase, with a default implementation simply calling read(n). It also means unbuffered stdio as it was recently committed doesn't work for stdin: $ ./python -u Python 3.1a0 (py3k:68756, Jan 19 2009, 01:17:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.stdin.read(1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/antoine/py3k/__svn__/Lib/io.py", line 1739, in read eof = not self._read_chunk() File "/home/antoine/py3k/__svn__/Lib/io.py", line 1565, in _read_chunk input_chunk = self.buffer.read1(self._CHUNK_SIZE) AttributeError: 'FileIO' object has no attribute 'read1' >>> I had been misguided by the fact that the interpreter prompt did work, but it doesn't seem to use sys.stdin... |
|||
| msg80188 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2009年01月19日 16:14 | |
IOBase doesn't even define read(), though! I think we should make it part of BufferIOBase. |
|||
| msg80193 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2009年01月19日 16:57 | |
Usage of read1(): * _BytesIO.read1(n) (_bytesio.c): calls bytesio_read(n) * _BytesIO.read1(n) (io.py): return self.read(n) * BufferedReader._read_unlocked(n=None): - if n is None or n==-1, call self.raw.read() in a "while True: ..." until EOF - else, call self.raw.read() until we get enough bytes * BufferedReader.read1(n): calls self._read_unlocked(...) but make sure that we don't call self.raw.read() more than once * BufferedRWPair.read1(n): return self.reader.read1(n) * BufferedRandom.read1(n): self.flush(); return BufferedReader.read1 (self, n) * TextIOWrapper._read_chunk() calls self.buffer.read1 (self._CHUNK_SIZE) IOBase, RawIOBase, FileIO, BufferedIOBase, TextIOBase, TextIOWrapper, StringIO have no read1() method. |
|||
| msg80198 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2009年01月19日 17:59 | |
Short example to reproduce the problem:
---
import io, os
fd = os.open("/etc/issue", os.O_RDONLY)
raw = open(fd, "rb", buffering=0)
text = io.TextIOWrapper(raw, line_buffering=False)
print(text.read(1))
---
Traceback (most recent call last):
File "x.py", line 6, in <module>
print(text.read(1))
File "/home/SHARE/SVN/py3k/Lib/io.py", line 1739, in read
eof = not self._read_chunk()
File "/home/SHARE/SVN/py3k/Lib/io.py", line 1565, in _read_chunk
input_chunk = self.buffer.read1(self._CHUNK_SIZE)
AttributeError: 'FileIO' object has no attribute 'read1'
|
|||
| msg80199 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2009年01月19日 18:02 | |
On Mon, Jan 19, 2009 at 11:59 AM, STINNER Victor <report@bugs.python.org> wrote: > > STINNER Victor <victor.stinner@haypocalc.com> added the comment: > > Short example to reproduce the problem: > --- > import io, os > fd = os.open("/etc/issue", os.O_RDONLY) > raw = open(fd, "rb", buffering=0) > text = io.TextIOWrapper(raw, line_buffering=False) > print(text.read(1)) You can only use TextIOWrapper over a buffered stream, so this example is invalid anyway. |
|||
| msg80201 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2009年01月19日 18:17 | |
I don't understand the motivation of having two different methods for "raw" streams: read1() and read(). I would prefer to have only a method read() (because "read" is the most common name, whereas read1() is only used on Python3), but read() will have to follow the read1() rule: at most one syscall. If someone requires a read() method with the "one syscall" rule, he can use a raw stream. If you don't care, use high level classes (TextIOWrapper, BufferedReader, etc.). _fileio._FileIO.read() and _socket.socket.recv_into() already respect the syscall rule. Since BytesIO and StringIO don't use kernel object, the syscall rule is meaningles. Note: socket.SocketIO() implements RawIOBase but it has no read() nor write() methods ;-) That's maybe why IOBase has no read()/write() method. |
|||
| msg82921 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2009年02月28日 17:10 | |
In the io-c branch, read1() is now a member of BufferedIOBase. |
|||
| msg83138 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2009年03月04日 21:32 | |
This has been fixed in io-c branch merge. (r70152) |
|||
| msg83168 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2009年03月05日 00:25 | |
> This has been fixed in io-c branch merge. r70152 Amazing, io-c is faster but also fixes many bugs! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:44 | admin | set | github: 49246 |
| 2009年03月05日 00:25:49 | vstinner | set | messages: + msg83168 |
| 2009年03月04日 21:32:07 | benjamin.peterson | set | status: open -> closed resolution: fixed messages: + msg83138 |
| 2009年02月28日 17:12:32 | benjamin.peterson | link | issue4565 dependencies |
| 2009年02月28日 17:10:14 | benjamin.peterson | set | messages: + msg82921 |
| 2009年01月19日 18:17:58 | vstinner | set | messages: + msg80201 |
| 2009年01月19日 18:02:07 | benjamin.peterson | set | messages: + msg80199 |
| 2009年01月19日 17:59:41 | vstinner | set | messages: + msg80198 |
| 2009年01月19日 16:57:53 | vstinner | set | messages: + msg80193 |
| 2009年01月19日 16:20:56 | vstinner | set | nosy: + vstinner |
| 2009年01月19日 16:14:02 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg80188 |
| 2009年01月19日 13:29:18 | pitrou | set | messages: - msg80166 |
| 2009年01月19日 13:28:33 | pitrou | set | nosy:
+ gvanrossum messages: + msg80167 |
| 2009年01月19日 13:28:18 | pitrou | set | nosy:
+ pitrou messages: + msg80166 |
| 2009年01月19日 10:09:55 | kawai | create | |