diff options
author | Skip Montanaro <skip@pobox.com> | 2004-05-23 17:46:50 (GMT) |
---|---|---|
committer | Skip Montanaro <skip@pobox.com> | 2004-05-23 17:46:50 (GMT) |
commit | 0dc23101a070fd6a5cceb66ee87eac70f94e7bd1 (patch) | |
tree | 6a5d93c35a7b68383a02931f04b9b628ef17b26a /Modules | |
parent | ddc819c9643dd5d47a940760b88d8aa3262fddf6 (diff) | |
download | cpython-0dc23101a070fd6a5cceb66ee87eac70f94e7bd1.zip cpython-0dc23101a070fd6a5cceb66ee87eac70f94e7bd1.tar.gz cpython-0dc23101a070fd6a5cceb66ee87eac70f94e7bd1.tar.bz2 |
Exposed readline() function from the readline module.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/readline.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Modules/readline.c b/Modules/readline.c index 37baf87..50ceef4 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -32,6 +32,28 @@ #endif +/* Exported function to get a line from the user */ + +static PyObject * +py_readline(PyObject *self, PyObject *args) +{ + char *s = NULL; + char *line = NULL; + if (!PyArg_ParseTuple(args, "|s:readline", &s)) + return NULL; + line = readline(s); + if (line == NULL) { + PyErr_SetString(PyExc_EOFError, "End of file on input"); + return NULL; + } + return PyString_FromString(line); +} + +PyDoc_STRVAR(doc_py_readline, +"readline([prompt]) -> line\n\ +Prompt for and read a line of text. Raise EOFError on EOF."); + + /* Exported function to send one line to readline's init file parser */ static PyObject * @@ -468,6 +490,7 @@ contents of the line buffer."); static struct PyMethodDef readline_methods[] = { + {"readline", py_readline, METH_VARARGS, doc_py_readline}, {"parse_and_bind", parse_and_bind, METH_VARARGS, doc_parse_and_bind}, {"get_line_buffer", get_line_buffer, METH_NOARGS, doc_get_line_buffer}, {"insert_text", insert_text, METH_VARARGS, doc_insert_text}, |