bpo-34070: open() only checks for isatty if buffering < 0 (GH-8187)

This commit is contained in:
David Herberth 2018-10-20 00:32:04 +02:00 committed by Victor Stinner
parent acef69068f
commit 8deab96725
2 changed files with 5 additions and 3 deletions

View File

@ -0,0 +1,2 @@
Make sure to only check if the handle is a tty, when opening
a file with ``buffering=-1``.

View File

@ -241,7 +241,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
char rawmode[6], *m;
int line_buffering, is_number;
long isatty;
long isatty = 0;
PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL, *path_or_fd = NULL;
@ -388,7 +388,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
goto error;
/* buffering */
{
if (buffering < 0) {
PyObject *res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL);
if (res == NULL)
goto error;
@ -398,7 +398,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
goto error;
}
if (buffering == 1 || (buffering < 0 && isatty)) {
if (buffering == 1 || isatty) {
buffering = -1;
line_buffering = 1;
}