@@ -1484,15 +1484,15 @@ equivalent to (x**y) % z, but may be more efficient (e.g. for longs).");
14841484static PyObject *
14851485builtin_print (PyObject * self , PyObject * args , PyObject * kwds )
14861486{
1487- static char * kwlist [] = {"sep" , "end" , "file" , 0 };
1487+ static char * kwlist [] = {"sep" , "end" , "file" , "flush" , 0 };
14881488 static PyObject * dummy_args ;
1489- PyObject * sep = NULL , * end = NULL , * file = NULL ;
1489+ PyObject * sep = NULL , * end = NULL , * file = NULL , * flush = NULL ;
14901490 int i , err ;
14911491
14921492 if (dummy_args == NULL && !(dummy_args = PyTuple_New (0 )))
1493- return NULL ;
1494- if (!PyArg_ParseTupleAndKeywords (dummy_args , kwds , "|OOO :print" ,
1495- kwlist , & sep , & end , & file ))
1493+ return NULL ;
1494+ if (!PyArg_ParseTupleAndKeywords (dummy_args , kwds , "|OOOO :print" ,
1495+ kwlist , & sep , & end , & file , & flush ))
14961496 return NULL ;
14971497 if (file == NULL || file == Py_None ) {
14981498 file = PySys_GetObject ("stdout" );
@@ -1543,6 +1543,20 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
15431543 if (err )
15441544 return NULL ;
15451545
1546+ if (flush != NULL ) {
1547+ PyObject * tmp ;
1548+ int do_flush = PyObject_IsTrue (flush );
1549+ if (do_flush == -1 )
1550+ return NULL ;
1551+ else if (do_flush ) {
1552+ tmp = PyObject_CallMethod (file , "flush" , "" );
1553+ if (tmp == NULL )
1554+ return NULL ;
1555+ else
1556+ Py_DECREF (tmp );
1557+ }
1558+ }
1559+
15461560 Py_RETURN_NONE ;
15471561}
15481562
0 commit comments