blob: 4105ddb2f75bd9ceaa56f88ea1edeca5edf44c05 [file] [log] [blame]
Guido van Rossum290900a1997-09-26 21:51:21 +00001/* This module makes GNU readline available to Python. It has ideas
2 * contributed by Lee Busby, LLNL, and William Magro, Cornell Theory
3 * Center. The completer interface was inspired by Lele Gaifax.
4 *
5 * More recently, it was largely rewritten by Guido van Rossum who is
6 * now maintaining it.
Guido van Rossum0969d361997-08-05 21:27:50 +00007 */
8
Guido van Rossum290900a1997-09-26 21:51:21 +00009/* Standard definitions */
Guido van Rossum0969d361997-08-05 21:27:50 +000010#include "Python.h"
11#include <setjmp.h>
12#include <signal.h>
Guido van Rossum290900a1997-09-26 21:51:21 +000013#include <errno.h>
Guido van Rossum0969d361997-08-05 21:27:50 +000014
Guido van Rossum73bacfc1998-01-19 22:05:22 +000015#ifdef HAVE_UNISTD_H
16#include <unistd.h> /* For isatty() */
17#endif
18
Guido van Rossum290900a1997-09-26 21:51:21 +000019/* GNU readline definitions */
Guido van Rossumbcc20741998-08-04 22:53:56 +000020/* If you have string.h, you might need to add yourself to this #if... [cjh] */
21#if defined(__BEOS__)
22#undef HAVE_CONFIG_H
23/* At max warnings, we need protos for everything. [cjh] */
24#include <readline/readline.h>
25#include <readline/history.h>
26#include <unistd.h>
27#else
Guido van Rossum290900a1997-09-26 21:51:21 +000028#include <readline/readline.h> /* You may need to add an -I option to Setup */
29
Fred Drake8ce159a2000-08-31 05:18:54 +000030extern int rl_parse_and_bind(char *);
31extern int rl_read_init_file(char *);
32extern int rl_insert_text(char *);
33extern int rl_bind_key(int, Function *);
34extern int rl_bind_key_in_map(int, Function *, Keymap);
35extern int rl_initialize(void);
36extern int add_history(char *);
Guido van Rossumb9ce5ad2000-09-01 02:43:38 +000037extern int read_history(char *);
38extern int write_history(char *);
39extern int history_truncate_file(char *, int);
Guido van Rossum54ecc3d1999-01-27 17:53:11 +000040extern Function *rl_event_hook;
Guido van Rossum6c0f33f2000-09-20 20:24:21 +000041extern char *rl_library_version;
Guido van Rossumbcc20741998-08-04 22:53:56 +000042#endif
Guido van Rossum730806d1998-04-10 22:27:42 +000043
Guido van Rossum290900a1997-09-26 21:51:21 +000044/* Pointers needed from outside (but not declared in a header file). */
Thomas Wouters2c46eaf2000-07-22 23:51:19 +000045extern int (*PyOS_InputHook)(void);
Tim Petersdbd9ba62000-07-09 03:09:57 +000046extern char *(*PyOS_ReadlineFunctionPointer)(char *);
Guido van Rossum0969d361997-08-05 21:27:50 +000047
Guido van Rossum0969d361997-08-05 21:27:50 +000048
Guido van Rossum290900a1997-09-26 21:51:21 +000049/* Exported function to send one line to readline's init file parser */
50
51static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +000052parse_and_bind(PyObject *self, PyObject *args)
Guido van Rossum290900a1997-09-26 21:51:21 +000053{
Guido van Rossum3b5330e1998-12-04 15:34:39 +000054 char *s, *copy;
Guido van Rossum43713e52000-02-29 13:59:29 +000055 if (!PyArg_ParseTuple(args, "s:parse_and_bind", &s))
Guido van Rossum290900a1997-09-26 21:51:21 +000056 return NULL;
Guido van Rossum3b5330e1998-12-04 15:34:39 +000057 /* Make a copy -- rl_parse_and_bind() modifies its argument */
58 /* Bernard Herzog */
59 copy = malloc(1 + strlen(s));
60 if (copy == NULL)
61 return PyErr_NoMemory();
62 strcpy(copy, s);
63 rl_parse_and_bind(copy);
64 free(copy); /* Free the copy */
Guido van Rossum290900a1997-09-26 21:51:21 +000065 Py_INCREF(Py_None);
66 return Py_None;
67}
68
69static char doc_parse_and_bind[] = "\
70parse_and_bind(string) -> None\n\
71Parse and execute single line of a readline init file.\
72";
73
74
75/* Exported function to parse a readline init file */
76
77static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +000078read_init_file(PyObject *self, PyObject *args)
Guido van Rossum290900a1997-09-26 21:51:21 +000079{
80 char *s = NULL;
Guido van Rossum43713e52000-02-29 13:59:29 +000081 if (!PyArg_ParseTuple(args, "|z:read_init_file", &s))
Guido van Rossum290900a1997-09-26 21:51:21 +000082 return NULL;
83 errno = rl_read_init_file(s);
84 if (errno)
85 return PyErr_SetFromErrno(PyExc_IOError);
86 Py_INCREF(Py_None);
87 return Py_None;
88}
89
90static char doc_read_init_file[] = "\
91read_init_file([filename]) -> None\n\
92Parse a readline initialization file.\n\
93The default filename is the last filename used.\
94";
95
96
Skip Montanaro28067822000-07-06 18:55:12 +000097/* Exported function to load a readline history file */
98
99static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000100read_history_file(PyObject *self, PyObject *args)
Skip Montanaro28067822000-07-06 18:55:12 +0000101{
102 char *s = NULL;
103 if (!PyArg_ParseTuple(args, "|z:read_history_file", &s))
104 return NULL;
105 errno = read_history(s);
106 if (errno)
107 return PyErr_SetFromErrno(PyExc_IOError);
108 Py_INCREF(Py_None);
109 return Py_None;
110}
111
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000112static int history_length = -1; /* do not truncate history by default */
Skip Montanaro28067822000-07-06 18:55:12 +0000113static char doc_read_history_file[] = "\
114read_history_file([filename]) -> None\n\
115Load a readline history file.\n\
116The default filename is ~/.history.\
117";
118
119
120/* Exported function to save a readline history file */
121
122static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000123write_history_file(PyObject *self, PyObject *args)
Skip Montanaro28067822000-07-06 18:55:12 +0000124{
125 char *s = NULL;
126 if (!PyArg_ParseTuple(args, "|z:write_history_file", &s))
127 return NULL;
128 errno = write_history(s);
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000129 if (!errno && history_length >= 0)
130 history_truncate_file(s, history_length);
Skip Montanaro28067822000-07-06 18:55:12 +0000131 if (errno)
132 return PyErr_SetFromErrno(PyExc_IOError);
133 Py_INCREF(Py_None);
134 return Py_None;
135}
136
137static char doc_write_history_file[] = "\
138write_history_file([filename]) -> None\n\
139Save a readline history file.\n\
140The default filename is ~/.history.\
141";
142
143
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000144static char set_history_length_doc[] = "\
145set_history_length(length) -> None\n\
146set the maximal number of items which will be written to\n\
147the history file. A negative length is used to inhibit\n\
148history truncation.\n\
149";
150
151static PyObject*
152set_history_length(PyObject *self, PyObject *args)
153{
154 int length = history_length;
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000155 if (!PyArg_ParseTuple(args, "i:set_history_length", &length))
156 return NULL;
157 history_length = length;
158 Py_INCREF(Py_None);
159 return Py_None;
160}
161
162
163
164static char get_history_length_doc[] = "\
165get_history_length() -> int\n\
166return the current history length value.\n\
167";
168
169static PyObject*
170get_history_length(PyObject *self, PyObject *args)
171{
Skip Montanaro49bd24d2000-07-19 16:54:53 +0000172 if (!PyArg_ParseTuple(args, ":get_history_length"))
173 return NULL;
174 return Py_BuildValue("i", history_length);
175}
176
177
178
Guido van Rossum290900a1997-09-26 21:51:21 +0000179/* Exported function to specify a word completer in Python */
180
181static PyObject *completer = NULL;
182static PyThreadState *tstate = NULL;
183
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000184static PyObject *begidx = NULL;
185static PyObject *endidx = NULL;
186
187/* get the beginning index for the scope of the tab-completion */
188static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000189get_begidx(PyObject *self, PyObject *args)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000190{
191 if(!PyArg_NoArgs(args)) {
192 return NULL;
193 }
194 Py_INCREF(begidx);
195 return begidx;
196}
197
198static char doc_get_begidx[] = "\
199get_begidx() -> int\n\
200get the beginning index of the readline tab-completion scope";
201
202/* get the ending index for the scope of the tab-completion */
203static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000204get_endidx(PyObject *self, PyObject *args)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000205{
206 if(!PyArg_NoArgs(args)) {
207 return NULL;
208 }
209 Py_INCREF(endidx);
210 return endidx;
211}
212
213static char doc_get_endidx[] = "\
214get_endidx() -> int\n\
215get the ending index of the readline tab-completion scope";
216
217
218/* set the tab-completion word-delimiters that readline uses */
219
220static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000221set_completer_delims(PyObject *self, PyObject *args)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000222{
223 char *break_chars;
224
Guido van Rossum43713e52000-02-29 13:59:29 +0000225 if(!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) {
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000226 return NULL;
227 }
228 free(rl_completer_word_break_characters);
229 rl_completer_word_break_characters = strdup(break_chars);
230 Py_INCREF(Py_None);
231 return Py_None;
232}
233
234static char doc_set_completer_delims[] = "\
235set_completer_delims(string) -> None\n\
236set the readline word delimiters for tab-completion";
237
238
239/* get the tab-completion word-delimiters that readline uses */
240
241static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000242get_completer_delims(PyObject *self, PyObject *args)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000243{
244 if(!PyArg_NoArgs(args)) {
245 return NULL;
246 }
247 return PyString_FromString(rl_completer_word_break_characters);
248}
249
250static char doc_get_completer_delims[] = "\
251get_completer_delims() -> string\n\
252get the readline word delimiters for tab-completion";
253
Guido van Rossum290900a1997-09-26 21:51:21 +0000254static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000255set_completer(PyObject *self, PyObject *args)
Guido van Rossum290900a1997-09-26 21:51:21 +0000256{
257 PyObject *function = Py_None;
Guido van Rossum43713e52000-02-29 13:59:29 +0000258 if (!PyArg_ParseTuple(args, "|O:set_completer", &function))
Guido van Rossum290900a1997-09-26 21:51:21 +0000259 return NULL;
260 if (function == Py_None) {
261 Py_XDECREF(completer);
262 completer = NULL;
263 tstate = NULL;
264 }
265 else if (PyCallable_Check(function)) {
266 PyObject *tmp = completer;
267 Py_INCREF(function);
268 completer = function;
269 Py_XDECREF(tmp);
270 tstate = PyThreadState_Get();
271 }
272 else {
273 PyErr_SetString(PyExc_TypeError,
274 "set_completer(func): argument not callable");
275 return NULL;
276 }
277 Py_INCREF(Py_None);
278 return Py_None;
279}
280
281static char doc_set_completer[] = "\
282set_completer([function]) -> None\n\
283Set or remove the completer function.\n\
284The function is called as function(text, state),\n\
285for i in [0, 1, 2, ...] until it returns a non-string.\n\
286It should return the next possible completion starting with 'text'.\
287";
288
Guido van Rossum79378ff1997-10-07 14:53:21 +0000289/* Exported function to read the current line buffer */
290
291static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000292get_line_buffer(PyObject *self, PyObject *args)
Guido van Rossum79378ff1997-10-07 14:53:21 +0000293{
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000294 if (!PyArg_NoArgs(args))
Guido van Rossum79378ff1997-10-07 14:53:21 +0000295 return NULL;
296 return PyString_FromString(rl_line_buffer);
297}
298
299static char doc_get_line_buffer[] = "\
Guido van Rossuma88c5f31998-05-20 15:50:56 +0000300get_line_buffer() -> string\n\
Guido van Rossum79378ff1997-10-07 14:53:21 +0000301return the current contents of the line buffer.\
302";
303
304/* Exported function to insert text into the line buffer */
305
306static PyObject *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000307insert_text(PyObject *self, PyObject *args)
Guido van Rossum79378ff1997-10-07 14:53:21 +0000308{
309 char *s;
Guido van Rossum43713e52000-02-29 13:59:29 +0000310 if (!PyArg_ParseTuple(args, "s:insert_text", &s))
Guido van Rossum79378ff1997-10-07 14:53:21 +0000311 return NULL;
312 rl_insert_text(s);
313 Py_INCREF(Py_None);
314 return Py_None;
315}
316
317
318static char doc_insert_text[] = "\
319insert_text(string) -> None\n\
320Insert text into the command line.\
321";
322
Guido van Rossum290900a1997-09-26 21:51:21 +0000323
324/* Table of functions exported by the module */
Guido van Rossum0969d361997-08-05 21:27:50 +0000325
326static struct PyMethodDef readline_methods[] =
Guido van Rossum290900a1997-09-26 21:51:21 +0000327{
Andrew M. Kuchlinge365fb82000-08-03 02:06:16 +0000328 {"parse_and_bind", parse_and_bind, METH_VARARGS, doc_parse_and_bind},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000329 {"get_line_buffer", get_line_buffer,
330 METH_OLDARGS, doc_get_line_buffer},
Andrew M. Kuchlinge365fb82000-08-03 02:06:16 +0000331 {"insert_text", insert_text, METH_VARARGS, doc_insert_text},
332 {"read_init_file", read_init_file, METH_VARARGS, doc_read_init_file},
333 {"read_history_file", read_history_file,
334 METH_VARARGS, doc_read_history_file},
335 {"write_history_file", write_history_file,
336 METH_VARARGS, doc_write_history_file},
337 {"set_history_length", set_history_length,
338 METH_VARARGS, set_history_length_doc},
339 {"get_history_length", get_history_length,
340 METH_VARARGS, get_history_length_doc},
341 {"set_completer", set_completer, METH_VARARGS, doc_set_completer},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000342 {"get_begidx", get_begidx, METH_OLDARGS, doc_get_begidx},
343 {"get_endidx", get_endidx, METH_OLDARGS, doc_get_endidx},
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000344
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000345 {"set_completer_delims", set_completer_delims,
346 METH_VARARGS, doc_set_completer_delims},
347 {"get_completer_delims", get_completer_delims,
348 METH_OLDARGS, doc_get_completer_delims},
Guido van Rossum290900a1997-09-26 21:51:21 +0000349 {0, 0}
Guido van Rossum0969d361997-08-05 21:27:50 +0000350};
351
Guido van Rossum290900a1997-09-26 21:51:21 +0000352/* C function to call the Python completer. */
Guido van Rossum0969d361997-08-05 21:27:50 +0000353
Guido van Rossum290900a1997-09-26 21:51:21 +0000354static char *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000355on_completion(char *text, int state)
Guido van Rossum0969d361997-08-05 21:27:50 +0000356{
Guido van Rossum290900a1997-09-26 21:51:21 +0000357 char *result = NULL;
358 if (completer != NULL) {
359 PyObject *r;
Guido van Rossuma59406a1997-10-10 17:39:19 +0000360 PyThreadState *save_tstate;
Guido van Rossum290900a1997-09-26 21:51:21 +0000361 /* Note that readline is called with the interpreter
362 lock released! */
Guido van Rossuma59406a1997-10-10 17:39:19 +0000363 save_tstate = PyThreadState_Swap(NULL);
Guido van Rossum290900a1997-09-26 21:51:21 +0000364 PyEval_RestoreThread(tstate);
365 r = PyObject_CallFunction(completer, "si", text, state);
366 if (r == NULL)
367 goto error;
368 if (r == Py_None) {
369 result = NULL;
370 }
371 else {
372 char *s = PyString_AsString(r);
373 if (s == NULL)
374 goto error;
375 result = strdup(s);
376 }
377 Py_DECREF(r);
378 goto done;
379 error:
380 PyErr_Clear();
381 Py_XDECREF(r);
382 done:
383 PyEval_SaveThread();
Guido van Rossuma59406a1997-10-10 17:39:19 +0000384 PyThreadState_Swap(save_tstate);
Guido van Rossum290900a1997-09-26 21:51:21 +0000385 }
386 return result;
Guido van Rossum0969d361997-08-05 21:27:50 +0000387}
388
Guido van Rossum290900a1997-09-26 21:51:21 +0000389
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000390/* a more flexible constructor that saves the "begidx" and "endidx"
391 * before calling the normal completer */
392
393char **
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000394flex_complete(char *text, int start, int end)
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000395{
396 Py_XDECREF(begidx);
397 Py_XDECREF(endidx);
398 begidx = PyInt_FromLong((long) start);
399 endidx = PyInt_FromLong((long) end);
400 return completion_matches(text, *on_completion);
401}
402
Guido van Rossum290900a1997-09-26 21:51:21 +0000403/* Helper to initialize GNU readline properly. */
404
405static void
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000406setup_readline(void)
Guido van Rossum290900a1997-09-26 21:51:21 +0000407{
408 rl_readline_name = "python";
409 /* Force rebind of TAB to insert-tab */
410 rl_bind_key('\t', rl_insert);
411 /* Bind both ESC-TAB and ESC-ESC to the completion function */
412 rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
413 rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
414 /* Set our completion function */
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000415 rl_attempted_completion_function = (CPPFunction *)flex_complete;
Guido van Rossumb6c935a1997-09-26 23:00:37 +0000416 /* Set Python word break characters */
417 rl_completer_word_break_characters =
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000418 strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?");
Guido van Rossumb6c935a1997-09-26 23:00:37 +0000419 /* All nonalphanums except '.' */
Guido van Rossumb960e7a1999-11-18 17:51:02 +0000420
421 begidx = PyInt_FromLong(0L);
422 endidx = PyInt_FromLong(0L);
Barry Warsawf7612871999-01-29 21:55:03 +0000423 /* Initialize (allows .inputrc to override)
424 *
425 * XXX: A bug in the readline-2.2 library causes a memory leak
426 * inside this function. Nothing we can do about it.
427 */
Guido van Rossum290900a1997-09-26 21:51:21 +0000428 rl_initialize();
429}
430
431
432/* Interrupt handler */
433
434static jmp_buf jbuf;
435
Guido van Rossum0969d361997-08-05 21:27:50 +0000436/* ARGSUSED */
Tim Peters4f1b2082000-07-23 21:18:09 +0000437static void
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000438onintr(int sig)
Guido van Rossum0969d361997-08-05 21:27:50 +0000439{
Guido van Rossum290900a1997-09-26 21:51:21 +0000440 longjmp(jbuf, 1);
Guido van Rossum0969d361997-08-05 21:27:50 +0000441}
442
Guido van Rossum290900a1997-09-26 21:51:21 +0000443
444/* Wrapper around GNU readline that handles signals differently. */
Guido van Rossum0969d361997-08-05 21:27:50 +0000445
446static char *
Peter Schneider-Kampa788a7f2000-07-10 09:57:19 +0000447call_readline(char *prompt)
Guido van Rossum0969d361997-08-05 21:27:50 +0000448{
Guido van Rossum26418a92000-06-28 21:30:31 +0000449 size_t n;
Guido van Rossumb18618d2000-05-03 23:44:39 +0000450 char *p, *q;
Guido van Rossum174efc92000-09-16 16:37:53 +0000451 PyOS_sighandler_t old_inthandler;
452
453 old_inthandler = PyOS_setsig(SIGINT, onintr);
Guido van Rossum0969d361997-08-05 21:27:50 +0000454 if (setjmp(jbuf)) {
455#ifdef HAVE_SIGRELSE
456 /* This seems necessary on SunOS 4.1 (Rasmus Hahn) */
457 sigrelse(SIGINT);
458#endif
Guido van Rossum174efc92000-09-16 16:37:53 +0000459 PyOS_setsig(SIGINT, old_inthandler);
Guido van Rossum0969d361997-08-05 21:27:50 +0000460 return NULL;
461 }
Guido van Rossum44620641997-08-11 18:57:29 +0000462 rl_event_hook = PyOS_InputHook;
Guido van Rossum0969d361997-08-05 21:27:50 +0000463 p = readline(prompt);
Guido van Rossum174efc92000-09-16 16:37:53 +0000464 PyOS_setsig(SIGINT, old_inthandler);
Guido van Rossumb18618d2000-05-03 23:44:39 +0000465
466 /* We must return a buffer allocated with PyMem_Malloc. */
Guido van Rossum0969d361997-08-05 21:27:50 +0000467 if (p == NULL) {
Guido van Rossumb18618d2000-05-03 23:44:39 +0000468 p = PyMem_Malloc(1);
Guido van Rossum0969d361997-08-05 21:27:50 +0000469 if (p != NULL)
470 *p = '\0';
471 return p;
472 }
473 n = strlen(p);
474 if (n > 0)
475 add_history(p);
Guido van Rossumb18618d2000-05-03 23:44:39 +0000476 /* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
477 release the original. */
478 q = p;
479 p = PyMem_Malloc(n+2);
480 if (p != NULL) {
481 strncpy(p, q, n);
Guido van Rossum0969d361997-08-05 21:27:50 +0000482 p[n] = '\n';
483 p[n+1] = '\0';
484 }
Guido van Rossumb18618d2000-05-03 23:44:39 +0000485 free(q);
Guido van Rossum0969d361997-08-05 21:27:50 +0000486 return p;
487}
488
Guido van Rossum290900a1997-09-26 21:51:21 +0000489
490/* Initialize the module */
491
492static char doc_module[] =
493"Importing this module enables command line editing using GNU readline.";
494
Guido van Rossum3886bb61998-12-04 18:50:17 +0000495DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000496initreadline(void)
Guido van Rossum290900a1997-09-26 21:51:21 +0000497{
Guido van Rossum174efc92000-09-16 16:37:53 +0000498 PyObject *m, *d, *v;
Guido van Rossum290900a1997-09-26 21:51:21 +0000499
500 m = Py_InitModule4("readline", readline_methods, doc_module,
501 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum174efc92000-09-16 16:37:53 +0000502
503 d = PyModule_GetDict(m);
504 v = PyString_FromString(rl_library_version);
505 PyDict_SetItemString(d, "library_version", v);
506 Py_XDECREF(v);
507
Guido van Rossum290900a1997-09-26 21:51:21 +0000508 if (isatty(fileno(stdin))) {
509 PyOS_ReadlineFunctionPointer = call_readline;
510 setup_readline();
511 }
Guido van Rossum0969d361997-08-05 21:27:50 +0000512}