@@ -1289,12 +1289,25 @@ static PyObject *
12891289builtin_raw_input (PyObject * self , PyObject * args )
12901290{
12911291 PyObject * v = NULL ;
1292- PyObject * f ;
1292+ PyObject * fin = PySys_GetObject ("stdin" );
1293+ PyObject * fout = PySys_GetObject ("stdout" );
12931294
12941295 if (!PyArg_ParseTuple (args , "|O:[raw_]input" , & v ))
12951296 return NULL ;
1296- if (PyFile_AsFile (PySys_GetObject ("stdin" )) == stdin &&
1297- PyFile_AsFile (PySys_GetObject ("stdout" )) == stdout &&
1297+
1298+ if (fin == NULL ) {
1299+ PyErr_SetString (PyExc_RuntimeError , "lost sys.stdin" );
1300+ return NULL ;
1301+ }
1302+ if (fout == NULL ) {
1303+ PyErr_SetString (PyExc_RuntimeError , "lost sys.stdout" );
1304+ return NULL ;
1305+ }
1306+ if (PyFile_SoftSpace (fout , 0 )) {
1307+ if (PyFile_WriteString (" " , fout ) != 0 )
1308+ return NULL ;
1309+ }
1310+ if (PyFile_AsFile (fin ) == stdin && PyFile_AsFile (fout ) == stdout &&
12981311 isatty (fileno (stdin )) && isatty (fileno (stdout ))) {
12991312 PyObject * po ;
13001313 char * prompt ;
@@ -1325,32 +1338,23 @@ builtin_raw_input(PyObject *self, PyObject *args)
13251338 else { /* strip trailing '\n' */
13261339 size_t len = strlen (s );
13271340 if (len > INT_MAX ) {
1328- PyErr_SetString (PyExc_OverflowError , "input too long" );
1341+ PyErr_SetString (PyExc_OverflowError ,
1342+ "input too long" );
13291343 result = NULL ;
13301344 }
13311345 else {
1332- result = PyString_FromStringAndSize (s , (int )(len - 1 ));
1346+ result = PyString_FromStringAndSize (s ,
1347+ (int )(len - 1 ));
13331348 }
13341349 }
13351350 PyMem_FREE (s );
13361351 return result ;
13371352 }
13381353 if (v != NULL ) {
1339- f = PySys_GetObject ("stdout" );
1340- if (f == NULL ) {
1341- PyErr_SetString (PyExc_RuntimeError , "lost sys.stdout" );
1342- return NULL ;
1343- }
1344- if (Py_FlushLine () != 0 ||
1345- PyFile_WriteObject (v , f , Py_PRINT_RAW ) != 0 )
1354+ if (PyFile_WriteObject (v , fout , Py_PRINT_RAW ) != 0 )
13461355 return NULL ;
13471356 }
1348- f = PySys_GetObject ("stdin" );
1349- if (f == NULL ) {
1350- PyErr_SetString (PyExc_RuntimeError , "lost sys.stdin" );
1351- return NULL ;
1352- }
1353- return PyFile_GetLine (f , -1 );
1357+ return PyFile_GetLine (fin , -1 );
13541358}
13551359
13561360PyDoc_STRVAR (raw_input_doc ,
0 commit comments