diff Python/pythonrun.c @ 50678:9c2bd647b646 3.0

Merged revisions 68463 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r68463 | antoine.pitrou | 2009-01-09 23:12:30 +0100 (ven., 09 janv. 2009) | 4 lines Fix bug introduced in r68451: stdio must always be opened in line-buffered mode if isatty() is true. ........
author Antoine Pitrou <solipsis@pitrou.net>
date Fri, 09 Jan 2009 22:26:34 +0000
parents b98fe8dc8acd
children 14c3ab9bd706
line wrap: on
line diff
--- a/Python/pythonrun.c	Fri Jan 09 20:08:07 2009 +0000
+++ b/Python/pythonrun.c	Fri Jan 09 22:26:34 2009 +0000
@@ -734,10 +734,10 @@
 	int fd, int write_mode, char* name,
 	char* encoding, char* errors)
 {
-	PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL;
+	PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res;
 	const char* mode;
-	const PyObject *line_buffering;
-	int buffering;
+	PyObject *line_buffering;
+	int buffering, isatty;
 
 	if (Py_UnbufferedStdioFlag)
 		buffering = 0;
@@ -766,13 +766,21 @@
 	text = PyUnicode_FromString(name);
 	if (text == NULL || PyObject_SetAttrString(raw, "_name", text) < 0)
 		goto error;
+	res = PyObject_CallMethod(raw, "isatty", "");
+	if (res == NULL)
+		goto error;
+	isatty = PyObject_IsTrue(res);
+	Py_DECREF(res);
+	if (isatty == -1)
+		goto error;
+	if (isatty || Py_UnbufferedStdioFlag)
+		line_buffering = Py_True;
+	else
+		line_buffering = Py_False;
+
 	Py_CLEAR(raw);
 	Py_CLEAR(text);
 
-	if (Py_UnbufferedStdioFlag)
-		line_buffering = Py_True;
-	else
-		line_buffering = Py_False;
 	stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO",
 				     buf, encoding, errors,
 				     "\n", line_buffering);