--- configure.orig	2012-04-12 13:22:40.000000000 +0300
+++ configure	2012-04-13 09:43:22.000000000 +0300
@@ -12879,9 +12879,9 @@
 $as_echo_n "checking how to link readline libs... " >&6; }
 for py_libtermcap in "" ncursesw ncurses curses termcap; do
   if test -z "$py_libtermcap"; then
-    READLINE_LIBS="-lreadline"
+    READLINE_LIBS="-ledit"
   else
-    READLINE_LIBS="-lreadline -l$py_libtermcap"
+    READLINE_LIBS="-ledit -l$py_libtermcap"
   fi
   LIBS="$READLINE_LIBS $LIBS_no_readline"
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -12925,13 +12925,13 @@
 fi
 
 # check for readline 2.1
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_callback_handler_install in -lreadline" >&5
-$as_echo_n "checking for rl_callback_handler_install in -lreadline... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_callback_handler_install in -ledit" >&5
+$as_echo_n "checking for rl_callback_handler_install in -ledit... " >&6; }
 if test "${ac_cv_lib_readline_rl_callback_handler_install+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-ledit $READLINE_LIBS $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -12971,7 +12971,7 @@
 # check for readline 2.2
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <readline/readline.h>
+#include <editline/readline.h>
 _ACEOF
 if ac_fn_c_try_cpp "$LINENO"; then :
   have_readline=yes
@@ -12984,7 +12984,7 @@
 then
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <readline/readline.h>
+#include <editline/readline.h>
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
@@ -12997,7 +12997,7 @@
 
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <readline/readline.h>
+#include <editline/readline.h>
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
@@ -13011,13 +13011,13 @@
 fi
 
 # check for readline 4.0
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_pre_input_hook in -lreadline" >&5
-$as_echo_n "checking for rl_pre_input_hook in -lreadline... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_pre_input_hook in -ledit" >&5
+$as_echo_n "checking for rl_pre_input_hook in -ledit... " >&6; }
 if test "${ac_cv_lib_readline_rl_pre_input_hook+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-ledit $READLINE_LIBS $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -13055,13 +13055,13 @@
 
 
 # also in 4.0
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_display_matches_hook in -lreadline" >&5
-$as_echo_n "checking for rl_completion_display_matches_hook in -lreadline... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_display_matches_hook in -ledit" >&5
+$as_echo_n "checking for rl_completion_display_matches_hook in -ledit... " >&6; }
 if test "${ac_cv_lib_readline_rl_completion_display_matches_hook+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-ledit $READLINE_LIBS $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -13099,13 +13099,13 @@
 
 
 # check for readline 4.2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_matches in -lreadline" >&5
-$as_echo_n "checking for rl_completion_matches in -lreadline... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_completion_matches in -ledit" >&5
+$as_echo_n "checking for rl_completion_matches in -ledit... " >&6; }
 if test "${ac_cv_lib_readline_rl_completion_matches+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lreadline $READLINE_LIBS $LIBS"
+LIBS="-ledit $READLINE_LIBS $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -13145,7 +13145,7 @@
 # also in readline 4.2
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <readline/readline.h>
+#include <editline/readline.h>
 _ACEOF
 if ac_fn_c_try_cpp "$LINENO"; then :
   have_readline=yes
@@ -13158,7 +13158,7 @@
 then
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <readline/readline.h>
+#include <editline/readline.h>
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
--- setup.py.orig	2011-10-31 14:58:43.000000000 +1100
+++ setup.py	2011-10-31 15:03:30.000000000 +1100
@@ -620,7 +620,7 @@
             missing.extend(['imageop'])
 
         # readline
-        do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
+        do_readline = self.compiler.find_library_file(lib_dirs, 'edit')
         readline_termcap_library = ""
         curses_library = ""
         # Determine if readline is already linked against curses or tinfo.
@@ -671,7 +671,7 @@
             else:
                 readline_extra_link_args = ()
 
-            readline_libs = ['readline']
+            readline_libs = ['edit']
             if readline_termcap_library:
                 pass # Issue 7384: Already linked against curses or tinfo.
             elif curses_library:
--- Modules/readline.c.orig	2011-06-12 01:46:27.000000000 +1000
+++ Modules/readline.c	2011-10-31 15:07:35.000000000 +1100
@@ -28,8 +28,7 @@
 
 /* GNU readline definitions */
 #undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */
-#include <readline/readline.h>
-#include <readline/history.h>
+#include <editline/readline.h>
 
 #ifdef HAVE_RL_COMPLETION_MATCHES
 #define completion_matches(x, y) \
@@ -550,14 +549,13 @@ get_history_item(PyObject *self, PyObjec
          * 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) {
+        if (idx < 1 || idx > length) {
             Py_RETURN_NONE;
         }
     }
@@ -976,7 +974,6 @@ readline_until_enter_or_signal(char *pro
             PyEval_SaveThread();
 #endif
             if (s < 0) {
-                rl_free_line_state();
                 rl_cleanup_after_signal();
                 rl_callback_handler_remove();
                 *signal = 1;
@@ -1075,15 +1072,6 @@ call_readline(FILE *sys_stdin, FILE *sys
         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 = history_get(length - 1)->line;
-            } else
-#endif /* __APPLE__ */
             line = history_get(length)->line;
         else
             line = "";
