--- configure.orig	2017-02-21 02:26:16.000000000 +0400
+++ configure	2017-02-21 02:22:55.000000000 +0400
@@ -14995,9 +14995,9 @@
 $as_echo_n "checking how to link readline libs... " >&6; }
 for py_libtermcap in "" tinfo 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
@@ -15041,13 +15041,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 ${ac_cv_lib_readline_rl_callback_handler_install+:} false; 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.  */
 
@@ -15087,7 +15087,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
@@ -15100,7 +15100,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 |
@@ -15113,7 +15113,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 |
@@ -15127,13 +15127,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 ${ac_cv_lib_readline_rl_pre_input_hook+:} false; 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.  */
 
@@ -15171,13 +15171,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 ${ac_cv_lib_readline_rl_completion_display_matches_hook+:} false; 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.  */
 
@@ -15259,13 +15259,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 ${ac_cv_lib_readline_rl_completion_matches+:} false; 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.  */
 
@@ -15305,7 +15305,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
@@ -15318,7 +15318,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	2017-02-21 02:26:29.000000000 +0400
+++ setup.py	2017-02-21 02:22:55.000000000 +0400
@@ -710,7 +710,7 @@
                                libraries=math_libs) )
 
         # 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 = ""
         # Cannot use os.popen here in py3k.
@@ -776,7 +776,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	2017-02-21 02:26:45.000000000 +0400
+++ Modules/readline.c	2017-02-21 02:22:55.000000000 +0400
@@ -29,8 +29,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) \
@@ -46,7 +45,7 @@
 #endif
 #endif
 
-#ifdef __APPLE__
+#ifndef __APPLE__
 /*
  * It is possible to link the readline module to the readline
  * emulation library of editline/libedit.
@@ -1099,7 +1098,7 @@
         Py_FatalError("not enough memory to save locale");
 #endif
 
-#ifdef __APPLE__
+#ifndef __APPLE__
     /* the libedit readline emulation resets key bindings etc
      * when calling rl_initialize.  So call it upfront
      */
@@ -1146,7 +1145,7 @@
     mod_state->begidx = PyLong_FromLong(0L);
     mod_state->endidx = PyLong_FromLong(0L);
 
-#ifdef __APPLE__
+#ifndef __APPLE__
     if (!using_libedit_emulation)
 #endif
     {
@@ -1168,7 +1167,7 @@
      * XXX: A bug in the readline-2.2 library causes a memory leak
      * inside this function.  Nothing we can do about it.
      */
-#ifdef __APPLE__
+#ifndef __APPLE__
     if (using_libedit_emulation)
         rl_read_init_file(NULL);
     else
@@ -1348,7 +1347,7 @@
         const char *line;
         int length = _py_get_history_length();
         if (length > 0)
-#ifdef __APPLE__
+#ifndef __APPLE__
             if (using_libedit_emulation) {
                 /* handle older 0-based or newer 1-based indexing */
                 line = (const char *)history_get(length + libedit_history_start - 1)->line;
@@ -1380,7 +1379,7 @@
 PyDoc_STRVAR(doc_module,
 "Importing this module enables command line editing using GNU readline.");
 
-#ifdef __APPLE__
+#ifndef __APPLE__
 PyDoc_STRVAR(doc_module_le,
 "Importing this module enables command line editing using libedit readline.");
 #endif /* __APPLE__ */
@@ -1404,7 +1403,7 @@
     PyObject *m;
     readlinestate *mod_state;
 
-#ifdef __APPLE__
+#ifndef __APPLE__
     if (strncmp(rl_library_version, libedit_version_tag, strlen(libedit_version_tag)) == 0) {
         using_libedit_emulation = 1;
     }
