[issue31775] Support unbuffered TextIOWrapper

2017-10-28 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31775] Support unbuffered TextIOWrapper

2017-10-12 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

What methods still require read1()?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31775] Support unbuffered TextIOWrapper

2017-10-12 Thread STINNER Victor

STINNER Victor  added the comment:

Context: I created this issue as a follow-up of the discussion on the -u 
command line option, bpo-28647, which still leaves sys.stdin *buffered* in the 
current master branch.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31775] Support unbuffered TextIOWrapper

2017-10-12 Thread STINNER Victor

STINNER Victor  added the comment:

> The falling back to read() was implemented in issue12591. What methods still 
> require read1()?

I read the Python implementation of TextIOWrapper in _pyio:

* seek() calls buffer.read() "if chars_to_skip:"... not sure that it can happen 
if buffer is a FileIO?
* read(None)  and read(-1) to read "everything" (until EOF): buffer.read()

It seems like read(None) also calls buffer.read() in the C implementation, 
_io_TextIOWrapper_read_impl():

/* Read everything */
PyObject *bytes = _PyObject_CallMethodId(self->buffer, _read, 
NULL);
PyObject *decoded;
if (bytes == NULL)
goto fail;

and in _io_TextIOWrapper_seek_impl():

/* Just like _read_chunk, feed the decoder and save a snapshot. */
PyObject *input_chunk = _PyObject_CallMethodId(
self->buffer, _read, "i", cookie.bytes_to_feed);

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31775] Support unbuffered TextIOWrapper

2017-10-12 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

The falling back to read() was implemented in issue12591. What methods still 
require read1()?

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31775] Support unbuffered TextIOWrapper

2017-10-12 Thread STINNER Victor

STINNER Victor  added the comment:

Oh, currently it's not possible to create an unbuffered read-only TextIOWrapper 
object:

haypo@selma$ python3
Python 3.6.2 (default, Oct  2 2017, 16:51:32) 
>>> open("/etc/issue", "r", 0)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: can't have unbuffered text I/O

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31775] Support unbuffered TextIOWrapper

2017-10-12 Thread STINNER Victor

STINNER Victor  added the comment:

I created this issue because of this comment in create_stdio() of 
Python/pylifecycle.c:
---
/* stdin is always opened in buffered mode, first because it shouldn't
   make a difference in common use cases, second because TextIOWrapper
   depends on the presence of a read1() method which only exists on
   buffered streams.
*/
if (Py_UnbufferedStdioFlag && write_mode)
buffering = 0;
else
buffering = -1;
---

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31775] Support unbuffered TextIOWrapper

2017-10-12 Thread STINNER Victor

New submission from STINNER Victor :

It seems like that some methods of the io.TextIOWrapper class requires that its 
buffer object has the read1() method, whereas the constructor checks if the 
buffer has a read1() method and the TextIOWrapper _read_chunk() method is able 
to call buffer.read() if buffer doesn't have read1().

This issue may help to get fully unbuffered sys.stdin, at least when replaced 
manually:

stdin = sys.stdin
sys.stdin = open(0, "r", buffering=0, encoding=stdin.encoding, 
errors=stdin.errors, newline=stdin.newline)

--
components: IO
messages: 304250
nosy: haypo
priority: normal
severity: normal
status: open
title: Support unbuffered TextIOWrapper
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com