Back to index

python3.2  3.2.2
Defines | Functions | Variables
readline.c File Reference
#include "Python.h"
#include <setjmp.h>
#include <signal.h>
#include <errno.h>
#include <sys/time.h>
#include <readline/readline.h>
#include <readline/history.h>

Go to the source code of this file.

Defines

#define RESTORE_LOCALE(sl)

Functions

char ** completion_matches (char *, CPFunction *)
static PyObjectparse_and_bind (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_parse_and_bind,"parse_and_bind(string) -> None\n\ Parse and execute single line of a readline init file.")
static PyObjectread_init_file (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_read_init_file,"read_init_file([filename]) -> None\n\ Parse a readline initialization file.\n\ The default filename is the last filename used.")
static PyObjectread_history_file (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_read_history_file,"read_history_file([filename]) -> None\n\ Load a readline history file.\n\ The default filename is ~/.history.")
static PyObjectwrite_history_file (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_write_history_file,"write_history_file([filename]) -> None\n\ Save a readline history file.\n\ The default filename is ~/.history.")
static PyObjectset_history_length (PyObject *self, PyObject *args)
 PyDoc_STRVAR (set_history_length_doc,"set_history_length(length) -> None\n\ set the maximal number of items which will be written to\n\ the history file. A negative length is used to inhibit\n\ history truncation.")
static PyObjectget_history_length (PyObject *self, PyObject *noarg)
 PyDoc_STRVAR (get_history_length_doc,"get_history_length() -> int\n\ return the maximum number of items that will be written to\n\ the history file.")
static PyObjectset_hook (const char *funcname, PyObject **hook_var, PyObject *args)
static PyObjectset_completion_display_matches_hook (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_set_completion_display_matches_hook,"set_completion_display_matches_hook([function]) -> None\n\ Set or remove the completion display function.\n\ The function is called as\n\ function(substitution, [matches], longest_match_length)\n\ once each time matches need to be displayed.")
static PyObjectset_startup_hook (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_set_startup_hook,"set_startup_hook([function]) -> None\n\ Set or remove the startup_hook function.\n\ The function is called with no arguments just\n\ before readline prints the first prompt.")
static PyObjectget_completion_type (PyObject *self, PyObject *noarg)
 PyDoc_STRVAR (doc_get_completion_type,"get_completion_type() -> int\n\ Get the type of completion being attempted.")
static PyObjectget_begidx (PyObject *self, PyObject *noarg)
 PyDoc_STRVAR (doc_get_begidx,"get_begidx() -> int\n\ get the beginning index of the readline tab-completion scope")
static PyObjectget_endidx (PyObject *self, PyObject *noarg)
 PyDoc_STRVAR (doc_get_endidx,"get_endidx() -> int\n\ get the ending index of the readline tab-completion scope")
static PyObjectset_completer_delims (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_set_completer_delims,"set_completer_delims(string) -> None\n\ set the readline word delimiters for tab-completion")
static void _py_free_history_entry (HIST_ENTRY *entry)
static PyObjectpy_remove_history (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_remove_history,"remove_history_item(pos) -> None\n\ remove history item given by its position")
static PyObjectpy_replace_history (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_replace_history,"replace_history_item(pos, line) -> None\n\ replaces history item given by its position with contents of line")
static PyObjectpy_add_history (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_add_history,"add_history(string) -> None\n\ add a line to the history buffer")
static PyObjectget_completer_delims (PyObject *self, PyObject *noarg)
 PyDoc_STRVAR (doc_get_completer_delims,"get_completer_delims() -> string\n\ get the readline word delimiters for tab-completion")
static PyObjectset_completer (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_set_completer,"set_completer([function]) -> None\n\ Set or remove the completer function.\n\ The function is called as function(text, state),\n\ for state in 0, 1, 2, ..., until it returns a non-string.\n\ It should return the next possible completion starting with 'text'.")
static PyObjectget_completer (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (doc_get_completer,"get_completer() -> function\n\ \n\ Returns current completer function.")
static int _py_get_history_length (void)
static PyObjectget_history_item (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_get_history_item,"get_history_item() -> string\n\ return the current contents of history item at index.")
static PyObjectget_current_history_length (PyObject *self, PyObject *noarg)
 PyDoc_STRVAR (doc_get_current_history_length,"get_current_history_length() -> integer\n\ return the current (not the maximum) length of history.")
static PyObjectget_line_buffer (PyObject *self, PyObject *noarg)
 PyDoc_STRVAR (doc_get_line_buffer,"get_line_buffer() -> string\n\ return the current contents of the line buffer.")
static PyObjectinsert_text (PyObject *self, PyObject *args)
 PyDoc_STRVAR (doc_insert_text,"insert_text(string) -> None\n\ Insert text into the command line.")
static PyObjectredisplay (PyObject *self, PyObject *noarg)
 PyDoc_STRVAR (doc_redisplay,"redisplay() -> None\n\ Change what's displayed on the screen to reflect the current\n\ contents of the line buffer.")
static int on_hook (PyObject *func)
static int on_startup_hook (void)
static char * on_completion (const char *text, int state)
static char ** flex_complete (char *text, int start, int end)
static void setup_readline (void)
static void onintr (int sig)
static char * readline_until_enter_or_signal (char *prompt, int *signal)
static char * call_readline (FILE *sys_stdin, FILE *sys_stdout, char *prompt)
 PyDoc_STRVAR (doc_module,"Importing this module enables command line editing using GNU readline.")
PyMODINIT_FUNC PyInit_readline (void)

Variables

static int _history_length = -1
static PyObjectcompletion_display_matches_hook = NULL
static PyObjectstartup_hook = NULL
static PyObjectcompleter = NULL
static PyObjectbegidx = NULL
static PyObjectendidx = NULL
static struct PyMethodDef []
static jmp_buf jbuf
static struct PyModuleDef

Define Documentation

#define RESTORE_LOCALE (   sl)

Definition at line 26 of file readline.c.


Function Documentation

static void _py_free_history_entry ( HIST_ENTRY *  entry) [static]

Definition at line 403 of file readline.c.

{
    if (entry->line)
        free((void *)entry->line);
    if (entry->data)
        free(entry->data);
    free(entry);
}

Here is the caller graph for this function:

static int _py_get_history_length ( void  ) [static]

Definition at line 544 of file readline.c.

{
    HISTORY_STATE *hist_st = history_get_history_state();
    int length = hist_st->length;
    /* the history docs don't say so, but the address of hist_st changes each
       time history_get_history_state is called which makes me think it's
       freshly malloc'd memory...  on the other hand, the address of the last
       line stays the same as long as history isn't extended, so it appears to
       be malloc'd but managed by the history package... */
    free(hist_st);
    return length;
}

Here is the caller graph for this function:

static char* call_readline ( FILE *  sys_stdin,
FILE *  sys_stdout,
char *  prompt 
) [static]

Definition at line 1058 of file readline.c.

{
    size_t n;
    char *p, *q;
    int signal;

#ifdef SAVE_LOCALE
    char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
    if (!saved_locale)
        Py_FatalError("not enough memory to save locale");
    setlocale(LC_CTYPE, "");
#endif

    if (sys_stdin != rl_instream || sys_stdout != rl_outstream) {
        rl_instream = sys_stdin;
        rl_outstream = sys_stdout;
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
        rl_prep_terminal (1);
#endif
    }

    p = readline_until_enter_or_signal(prompt, &signal);

    /* we got an interrupt signal */
    if (signal) {
        RESTORE_LOCALE(saved_locale)
        return NULL;
    }

    /* We got an EOF, return a empty string. */
    if (p == NULL) {
        p = PyMem_Malloc(1);
        if (p != NULL)
            *p = '\0';
        RESTORE_LOCALE(saved_locale)
        return p;
    }

    /* we have a valid line */
    n = strlen(p);
    if (n > 0) {
        const char *line;
        int length = _py_get_history_length();
        if (length > 0)
#ifdef __APPLE__
            if (using_libedit_emulation) {
                /*
                 * Libedit's emulation uses 0-based indexes,
                 * the real readline uses 1-based indexes.
                 */
                line = (const char *)history_get(length - 1)->line;
            } else
#endif /* __APPLE__ */
            line = (const char *)history_get(length)->line;
        else
            line = "";
        if (strcmp(p, line))
            add_history(p);
    }
    /* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and
       release the original. */
    q = p;
    p = PyMem_Malloc(n+2);
    if (p != NULL) {
        strncpy(p, q, n);
        p[n] = '\n';
        p[n+1] = '\0';
    }
    free(q);
    RESTORE_LOCALE(saved_locale)
    return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char** completion_matches ( char *  ,
CPFunction *   
)

Here is the caller graph for this function:

static char** flex_complete ( char *  text,
int  start,
int  end 
) [static]

Definition at line 865 of file readline.c.

{
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
    rl_completion_append_character ='\0';
#endif
#ifdef HAVE_RL_COMPLETION_SUPPRESS_APPEND
    rl_completion_suppress_append = 0;
#endif
    Py_XDECREF(begidx);
    Py_XDECREF(endidx);
    begidx = PyLong_FromLong((long) start);
    endidx = PyLong_FromLong((long) end);
    return completion_matches(text, *on_completion);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* get_begidx ( PyObject self,
PyObject noarg 
) [static]

Definition at line 338 of file readline.c.

{
    Py_INCREF(begidx);
    return begidx;
}
static PyObject* get_completer ( PyObject self,
PyObject noargs 
) [static]

Definition at line 524 of file readline.c.

static PyObject* get_completer_delims ( PyObject self,
PyObject noarg 
) [static]

Definition at line 497 of file readline.c.

{
    return PyUnicode_FromString(rl_completer_word_break_characters);
}

Here is the call graph for this function:

static PyObject* get_completion_type ( PyObject self,
PyObject noarg 
) [static]

Definition at line 325 of file readline.c.

{
  return PyLong_FromLong(rl_completion_type);
}

Here is the call graph for this function:

static PyObject* get_current_history_length ( PyObject self,
PyObject noarg 
) [static]

Definition at line 603 of file readline.c.

Here is the call graph for this function:

static PyObject* get_endidx ( PyObject self,
PyObject noarg 
) [static]

Definition at line 352 of file readline.c.

{
    Py_INCREF(endidx);
    return endidx;
}
static PyObject* get_history_item ( PyObject self,
PyObject args 
) [static]

Definition at line 560 of file readline.c.

{
    int idx = 0;
    HIST_ENTRY *hist_ent;

    if (!PyArg_ParseTuple(args, "i:index", &idx))
        return NULL;
#ifdef  __APPLE__
    if (using_libedit_emulation) {
        /* Libedit emulation uses 0-based indexes,
         * the real one uses 1-based indexes,
         * adjust the index to ensure that Python
         * code doesn't have to worry about the
         * difference.
         */
        int length = _py_get_history_length();
        idx --;

        /*
         * Apple's readline emulation crashes when
         * the index is out of range, therefore
         * test for that and fail gracefully.
         */
        if (idx < 0 || idx >= length) {
            Py_RETURN_NONE;
        }
    }
#endif /* __APPLE__ */
    if ((hist_ent = history_get(idx)))
        return PyUnicode_FromString(hist_ent->line);
    else {
        Py_RETURN_NONE;
    }
}

Here is the call graph for this function:

static PyObject* get_history_length ( PyObject self,
PyObject noarg 
) [static]

Definition at line 204 of file readline.c.

Here is the call graph for this function:

static PyObject* get_line_buffer ( PyObject self,
PyObject noarg 
) [static]

Definition at line 616 of file readline.c.

{
    return PyUnicode_FromString(rl_line_buffer);
}

Here is the call graph for this function:

static PyObject* insert_text ( PyObject self,
PyObject args 
) [static]

Definition at line 646 of file readline.c.

{
    char *s;
    if (!PyArg_ParseTuple(args, "s:insert_text", &s))
        return NULL;
    rl_insert_text(s);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static char* on_completion ( const char *  text,
int  state 
) [static]

Definition at line 825 of file readline.c.

{
    char *result = NULL;
    if (completer != NULL) {
        PyObject *r;
#ifdef WITH_THREAD
        PyGILState_STATE gilstate = PyGILState_Ensure();
#endif
        rl_attempted_completion_over = 1;
        r = PyObject_CallFunction(completer, "si", text, state);
        if (r == NULL)
            goto error;
        if (r == Py_None) {
            result = NULL;
        }
        else {
            char *s = _PyUnicode_AsString(r);
            if (s == NULL)
                goto error;
            result = strdup(s);
        }
        Py_DECREF(r);
        goto done;
      error:
        PyErr_Clear();
        Py_XDECREF(r);
      done:
#ifdef WITH_THREAD
        PyGILState_Release(gilstate);
#endif
        return result;
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int on_hook ( PyObject func) [static]

Definition at line 729 of file readline.c.

{
    int result = 0;
    if (func != NULL) {
        PyObject *r;
#ifdef WITH_THREAD
        PyGILState_STATE gilstate = PyGILState_Ensure();
#endif
        r = PyObject_CallFunction(func, NULL);
        if (r == NULL)
            goto error;
        if (r == Py_None)
            result = 0;
        else {
            result = PyLong_AsLong(r);
            if (result == -1 && PyErr_Occurred())
                goto error;
        }
        Py_DECREF(r);
        goto done;
      error:
        PyErr_Clear();
        Py_XDECREF(r);
      done:
#ifdef WITH_THREAD
        PyGILState_Release(gilstate);
#endif
        return result;
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int on_startup_hook ( void  ) [static]

Definition at line 762 of file readline.c.

{
    return on_hook(startup_hook);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void onintr ( int  sig) [static]

Definition at line 1024 of file readline.c.

{
    longjmp(jbuf, 1);
}

Here is the caller graph for this function:

static PyObject* parse_and_bind ( PyObject self,
PyObject args 
) [static]

Definition at line 76 of file readline.c.

{
    char *s, *copy;
    if (!PyArg_ParseTuple(args, "s:parse_and_bind", &s))
        return NULL;
    /* Make a copy -- rl_parse_and_bind() modifies its argument */
    /* Bernard Herzog */
    copy = malloc(1 + strlen(s));
    if (copy == NULL)
        return PyErr_NoMemory();
    strcpy(copy, s);
    rl_parse_and_bind(copy);
    free(copy); /* Free the copy */
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* py_add_history ( PyObject self,
PyObject args 
) [static]

Definition at line 478 of file readline.c.

{
    char *line;

    if(!PyArg_ParseTuple(args, "s:add_history", &line)) {
        return NULL;
    }
    add_history(line);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* py_remove_history ( PyObject self,
PyObject args 
) [static]

Definition at line 415 of file readline.c.

{
    int entry_number;
    HIST_ENTRY *entry;

    if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number))
        return NULL;
    if (entry_number < 0) {
        PyErr_SetString(PyExc_ValueError,
                        "History index cannot be negative");
        return NULL;
    }
    entry = remove_history(entry_number);
    if (!entry) {
        PyErr_Format(PyExc_ValueError,
                     "No history item at position %d",
                      entry_number);
        return NULL;
    }
    /* free memory allocated for the history entry */
    _py_free_history_entry(entry);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* py_replace_history ( PyObject self,
PyObject args 
) [static]

Definition at line 444 of file readline.c.

{
    int entry_number;
    char *line;
    HIST_ENTRY *old_entry;

    if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number,
                          &line)) {
        return NULL;
    }
    if (entry_number < 0) {
        PyErr_SetString(PyExc_ValueError,
                        "History index cannot be negative");
        return NULL;
    }
    old_entry = replace_history_entry(entry_number, line, (void *)NULL);
    if (!old_entry) {
        PyErr_Format(PyExc_ValueError,
                     "No history item at position %d",
                     entry_number);
        return NULL;
    }
    /* free memory allocated for the old history entry */
    _py_free_history_entry(old_entry);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

PyDoc_STRVAR ( doc_parse_and_bind  ,
"parse_and_bind(string) -> None\n\Parse and execute single line of a readline init file."   
)
PyDoc_STRVAR ( doc_read_init_file  ,
"read_init_file([filename]) -> None\n\Parse a readline initialization file.\n\The default filename is the last filename used."   
)
PyDoc_STRVAR ( doc_read_history_file  ,
"read_history_file([filename]) -> None\n\Load a readline history file.\n\The default filename is ~/.history."   
)
PyDoc_STRVAR ( doc_write_history_file  ,
"write_history_file([filename]) -> None\n\Save a readline history file.\n\The default filename is ~/.history."   
)
PyDoc_STRVAR ( set_history_length_doc  ,
"set_history_length(length) -> None\n\set the maximal number of items which will be written to\n\the history file. A negative length is used to inhibit\n\history truncation."   
)
PyDoc_STRVAR ( get_history_length_doc  ,
"get_history_length() -> int\n\return the maximum number of items that will be written to\n\the history file."   
)
PyDoc_STRVAR ( doc_set_completion_display_matches_hook  ,
"set_completion_display_matches_hook([function]) -> None\n\Set or remove the completion display function.\n\The function is called as\n\ function(substitution, [matches], longest_match_length)\n\once each time matches need to be displayed."   
)
PyDoc_STRVAR ( doc_set_startup_hook  ,
"set_startup_hook([function]) -> None\n\Set or remove the startup_hook function.\n\The function is called with no arguments just\n\before readline prints the first prompt."   
)
PyDoc_STRVAR ( doc_get_completion_type  ,
"get_completion_type() -> int\n\Get the type of completion being attempted."   
)
PyDoc_STRVAR ( doc_get_begidx  ,
"get_begidx() -> int\n\get the beginning index of the readline tab-completion scope"   
)
PyDoc_STRVAR ( doc_get_endidx  ,
"get_endidx() -> int\n\get the ending index of the readline tab-completion scope"   
)
PyDoc_STRVAR ( doc_set_completer_delims  ,
"set_completer_delims(string) -> None\n\set the readline word delimiters for tab-completion"   
)
PyDoc_STRVAR ( doc_remove_history  ,
"remove_history_item(pos) -> None\n\remove history item given by its position  
)
PyDoc_STRVAR ( doc_replace_history  ,
"replace_history_item(pos, line) -> None\n\replaces history item given by its position with contents of line"   
)
PyDoc_STRVAR ( doc_add_history  ,
"add_history(string) -> None\n\add a line to the history buffer  
)
PyDoc_STRVAR ( doc_get_completer_delims  ,
"get_completer_delims() -> string\n\get the readline word delimiters for tab-completion"   
)
PyDoc_STRVAR ( doc_set_completer  ,
set_completer[function]) -> None\n\Set or remove the completer function.\n\The function is called as function(text, state,
\n\for state in  0,
,
,
  ...,
until it returns a non-string.\n\It should return the next possible completion starting with 'text'."   
)
PyDoc_STRVAR ( doc_get_completer  ,
"get_completer() -> function\n\\n\Returns current completer function."   
)
PyDoc_STRVAR ( doc_get_history_item  ,
"get_history_item() -> string\n\return the current contents of history item at index."   
)
PyDoc_STRVAR ( doc_get_current_history_length  ,
"get_current_history_length() -> integer\n\return the current (not the maximum) length of history."   
)
PyDoc_STRVAR ( doc_get_line_buffer  ,
"get_line_buffer() -> string\n\return the current contents of the line buffer."   
)
PyDoc_STRVAR ( doc_insert_text  ,
"insert_text(string) -> None\n\Insert text into the command line."   
)
PyDoc_STRVAR ( doc_redisplay  ,
"redisplay() -> None\n\Change what's displayed on the screen to reflect the current\n\contents of the line buffer."   
)
PyDoc_STRVAR ( doc_module  ,
"Importing this module enables command line editing using GNU readline."   
)

Definition at line 1156 of file readline.c.

{
    PyObject *m;

#ifdef __APPLE__
    if (strncmp(rl_library_version, libedit_version_tag, strlen(libedit_version_tag)) == 0) {
        using_libedit_emulation = 1;
    }

    if (using_libedit_emulation)
        readlinemodule.m_doc = doc_module_le;

#endif /* __APPLE__ */

    m = PyModule_Create(&readlinemodule);

    if (m == NULL)
        return NULL;



    PyOS_ReadlineFunctionPointer = call_readline;
    setup_readline();
    return m;
}

Here is the call graph for this function:

static PyObject* read_history_file ( PyObject self,
PyObject args 
) [static]

Definition at line 126 of file readline.c.

{
    PyObject *filename_obj = Py_None, *filename_bytes;
    if (!PyArg_ParseTuple(args, "|O:read_history_file", &filename_obj))
        return NULL;
    if (filename_obj != Py_None) {
        if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
            return NULL;
        errno = read_history(PyBytes_AsString(filename_bytes));
        Py_DECREF(filename_bytes);
    } else
        errno = read_history(NULL);
    if (errno)
        return PyErr_SetFromErrno(PyExc_IOError);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* read_init_file ( PyObject self,
PyObject args 
) [static]

Definition at line 100 of file readline.c.

{
    PyObject *filename_obj = Py_None, *filename_bytes;
    if (!PyArg_ParseTuple(args, "|O:read_init_file", &filename_obj))
        return NULL;
    if (filename_obj != Py_None) {
        if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
            return NULL;
        errno = rl_read_init_file(PyBytes_AsString(filename_bytes));
        Py_DECREF(filename_bytes);
    } else
        errno = rl_read_init_file(NULL);
    if (errno)
        return PyErr_SetFromErrno(PyExc_IOError);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static char* readline_until_enter_or_signal ( char *  prompt,
int signal 
) [static]

Definition at line 1031 of file readline.c.

{
    PyOS_sighandler_t old_inthandler;
    char *p;

    *signal = 0;

    old_inthandler = PyOS_setsig(SIGINT, onintr);
    if (setjmp(jbuf)) {
#ifdef HAVE_SIGRELSE
        /* This seems necessary on SunOS 4.1 (Rasmus Hahn) */
        sigrelse(SIGINT);
#endif
        PyOS_setsig(SIGINT, old_inthandler);
        *signal = 1;
        return NULL;
    }
    rl_event_hook = PyOS_InputHook;
    p = readline(prompt);
    PyOS_setsig(SIGINT, old_inthandler);

    return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* redisplay ( PyObject self,
PyObject noarg 
) [static]

Definition at line 663 of file readline.c.

{
    rl_redisplay();
    Py_RETURN_NONE;
}
static PyObject* set_completer ( PyObject self,
PyObject args 
) [static]

Definition at line 510 of file readline.c.

{
    return set_hook("completer", &completer, args);
}

Here is the call graph for this function:

static PyObject* set_completer_delims ( PyObject self,
PyObject args 
) [static]

Definition at line 366 of file readline.c.

{
    char *break_chars;

    if(!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) {
        return NULL;
    }
    free((void*)rl_completer_word_break_characters);
    rl_completer_word_break_characters = strdup(break_chars);
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* set_completion_display_matches_hook ( PyObject self,
PyObject args 
) [static]

Definition at line 256 of file readline.c.

{
    PyObject *result = set_hook("completion_display_matches_hook",
                    &completion_display_matches_hook, args);
#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
    /* We cannot set this hook globally, since it replaces the
       default completion display. */
    rl_completion_display_matches_hook =
        completion_display_matches_hook ?
#if defined(_RL_FUNCTION_TYPEDEF)
        (rl_compdisp_func_t *)on_completion_display_matches_hook : 0;
#else
        (VFunction *)on_completion_display_matches_hook : 0;
#endif
#endif
    return result;

}

Here is the call graph for this function:

static PyObject* set_history_length ( PyObject self,
PyObject args 
) [static]

Definition at line 185 of file readline.c.

{
    int length = _history_length;
    if (!PyArg_ParseTuple(args, "i:set_history_length", &length))
        return NULL;
    _history_length = length;
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* set_hook ( const char *  funcname,
PyObject **  hook_var,
PyObject args 
) [static]

Definition at line 218 of file readline.c.

{
    PyObject *function = Py_None;
    char buf[80];
    PyOS_snprintf(buf, sizeof(buf), "|O:set_%.50s", funcname);
    if (!PyArg_ParseTuple(args, buf, &function))
        return NULL;
    if (function == Py_None) {
        Py_XDECREF(*hook_var);
        *hook_var = NULL;
    }
    else if (PyCallable_Check(function)) {
        PyObject *tmp = *hook_var;
        Py_INCREF(function);
        *hook_var = function;
        Py_XDECREF(tmp);
    }
    else {
        PyOS_snprintf(buf, sizeof(buf),
                      "set_%.50s(func): argument not callable",
                      funcname);
        PyErr_SetString(PyExc_TypeError, buf);
        return NULL;
    }
    Py_RETURN_NONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* set_startup_hook ( PyObject self,
PyObject args 
) [static]

Definition at line 283 of file readline.c.

{
    return set_hook("startup_hook", &startup_hook, args);
}

Here is the call graph for this function:

static void setup_readline ( void  ) [static]

Definition at line 884 of file readline.c.

{
#ifdef SAVE_LOCALE
    char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
    if (!saved_locale)
        Py_FatalError("not enough memory to save locale");
#endif

#ifdef __APPLE__
    /* the libedit readline emulation resets key bindings etc 
     * when calling rl_initialize.  So call it upfront
     */
    if (using_libedit_emulation)
        rl_initialize();
#endif /* __APPLE__ */

    using_history();

    rl_readline_name = "python";
#if defined(PYOS_OS2) && defined(PYCC_GCC)
    /* Allow $if term= in .inputrc to work */
    rl_terminal_name = getenv("TERM");
#endif
    /* Force rebind of TAB to insert-tab */
    rl_bind_key('\t', rl_insert);
    /* Bind both ESC-TAB and ESC-ESC to the completion function */
    rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
    rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
    /* Set our hook functions */
    rl_startup_hook = (Function *)on_startup_hook;
#ifdef HAVE_RL_PRE_INPUT_HOOK
    rl_pre_input_hook = (Function *)on_pre_input_hook;
#endif
    /* Set our completion function */
    rl_attempted_completion_function = (CPPFunction *)flex_complete;
    /* Set Python word break characters */
    rl_completer_word_break_characters =
        strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?");
        /* All nonalphanums except '.' */

    begidx = PyLong_FromLong(0L);
    endidx = PyLong_FromLong(0L);
    /* Initialize (allows .inputrc to override)
     *
     * XXX: A bug in the readline-2.2 library causes a memory leak
     * inside this function.  Nothing we can do about it.
     */
#ifdef __APPLE__
    if (using_libedit_emulation)
       rl_read_init_file(NULL);
    else
#endif /* __APPLE__ */
        rl_initialize();
    
    RESTORE_LOCALE(saved_locale)
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* write_history_file ( PyObject self,
PyObject args 
) [static]

Definition at line 153 of file readline.c.

{
    PyObject *filename_obj = Py_None, *filename_bytes;
    char *filename;
    if (!PyArg_ParseTuple(args, "|O:write_history_file", &filename_obj))
        return NULL;
    if (filename_obj != Py_None) {
        if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
            return NULL;
        filename = PyBytes_AsString(filename_bytes);
    } else {
        filename_bytes = NULL;
        filename = NULL;
    }
    errno = write_history(filename);
    if (!errno && _history_length >= 0)
        history_truncate_file(filename, _history_length);
    Py_XDECREF(filename_bytes);
    if (errno)
        return PyErr_SetFromErrno(PyExc_IOError);
    Py_RETURN_NONE;
}

Here is the call graph for this function:


Variable Documentation

int _history_length = -1 [static]

Definition at line 143 of file readline.c.

PyObject* begidx = NULL [static]

Definition at line 319 of file readline.c.

PyObject* completer = NULL [static]

Definition at line 317 of file readline.c.

Definition at line 248 of file readline.c.

PyObject* endidx = NULL [static]

Definition at line 320 of file readline.c.

jmp_buf jbuf [static]

Definition at line 1020 of file readline.c.

struct PyMethodDef[] [static]

Definition at line 677 of file readline.c.

struct PyModuleDef [static]
Initial value:
 {
    PyModuleDef_HEAD_INIT,
    "readline",
    doc_module,
    -1,
    readline_methods,
    NULL,
    NULL,
    NULL,
    NULL
}

Definition at line 1142 of file readline.c.

PyObject* startup_hook = NULL [static]

Definition at line 249 of file readline.c.