summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-08-14 15:46:02 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-08-14 15:46:02 (GMT)
commit31d2df5b60a20e43e3a8e23bc1cb8cebc41c96e4 (patch)
tree2b008a8788fdef906ba84e1698a4ae2d8ed823c2 /Python/bltinmodule.c
parent04490bf225a821455cd89821479bd0277dcbb3dc (diff)
downloadcpython-31d2df5b60a20e43e3a8e23bc1cb8cebc41c96e4.zip
cpython-31d2df5b60a20e43e3a8e23bc1cb8cebc41c96e4.tar.gz
cpython-31d2df5b60a20e43e3a8e23bc1cb8cebc41c96e4.tar.bz2
Patch #550192: Set softspace to 0 in raw_input().
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 7a53065..83931d9 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1289,12 +1289,25 @@ static PyObject *
builtin_raw_input(PyObject *self, PyObject *args)
{
PyObject *v = NULL;
- PyObject *f;
+ PyObject *fin = PySys_GetObject("stdin");
+ PyObject *fout = PySys_GetObject("stdout");
if (!PyArg_ParseTuple(args, "|O:[raw_]input", &v))
return NULL;
- if (PyFile_AsFile(PySys_GetObject("stdin")) == stdin &&
- PyFile_AsFile(PySys_GetObject("stdout")) == stdout &&
+
+ if (fin == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.stdin");
+ return NULL;
+ }
+ if (fout == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
+ return NULL;
+ }
+ if (PyFile_SoftSpace(fout, 0)) {
+ if (PyFile_WriteString(" ", fout) != 0)
+ return NULL;
+ }
+ if (PyFile_AsFile(fin) == stdin && PyFile_AsFile(fout) == stdout &&
isatty(fileno(stdin)) && isatty(fileno(stdout))) {
PyObject *po;
char *prompt;
@@ -1325,32 +1338,23 @@ builtin_raw_input(PyObject *self, PyObject *args)
else { /* strip trailing '\n' */
size_t len = strlen(s);
if (len > INT_MAX) {
- PyErr_SetString(PyExc_OverflowError, "input too long");
+ PyErr_SetString(PyExc_OverflowError,
+ "input too long");
result = NULL;
}
else {
- result = PyString_FromStringAndSize(s, (int)(len-1));
+ result = PyString_FromStringAndSize(s,
+ (int)(len-1));
}
}
PyMem_FREE(s);
return result;
}
if (v != NULL) {
- f = PySys_GetObject("stdout");
- if (f == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
- return NULL;
- }
- if (Py_FlushLine() != 0 ||
- PyFile_WriteObject(v, f, Py_PRINT_RAW) != 0)
+ if (PyFile_WriteObject(v, fout, Py_PRINT_RAW) != 0)
return NULL;
}
- f = PySys_GetObject("stdin");
- if (f == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "lost sys.stdin");
- return NULL;
- }
- return PyFile_GetLine(f, -1);
+ return PyFile_GetLine(fin, -1);
}
PyDoc_STRVAR(raw_input_doc,