Skip to content

Commit

Permalink
bpo-42819, readline: Disable bracketed paste (GH-24108)
Browse files Browse the repository at this point in the history
(cherry picked from commit 755f3c1)

Co-authored-by: Dustin Rodrigues <dust.rod@gmail.com>
  • Loading branch information
miss-islington and dtrodrigues committed Feb 15, 2021
1 parent f30aa3c commit f9d7c12
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Misc/ACKS
Expand Up @@ -1415,6 +1415,7 @@ Mark Roddy
Kevin Rodgers
Sean Rodman
Giampaolo Rodola
Dustin Rodrigues
Mauro S. M. Rodrigues
Elson Rodriguez
Adi Roiban
Expand Down
@@ -0,0 +1,8 @@
:mod:`readline`: Explicitly disable bracketed paste in the interactive
interpreter, even if it's set in the inputrc, is enabled by default (eg GNU
Readline 8.1), or a user calls ``readline.read_init_file()``. The Python REPL
has not implemented bracketed paste support. Also, bracketed mode writes the
``"\x1b[?2004h"`` escape sequence into stdout which causes test failures in
applications that don't support it. It can still be explicitly enabled by
calling ``readline.parse_and_bind("set enable-bracketed-paste on")``. Patch by
Dustin Rodrigues.
23 changes: 23 additions & 0 deletions Modules/readline.c
Expand Up @@ -141,6 +141,26 @@ decode(const char *s)
}


/*
Explicitly disable bracketed paste in the interactive interpreter, even if it's
set in the inputrc, is enabled by default (eg GNU Readline 8.1), or a user calls
readline.read_init_file(). The Python REPL has not implemented bracketed
paste support. Also, bracketed mode writes the "\x1b[?2004h" escape sequence
into stdout which causes test failures in applications that don't support it.
It can still be explicitly enabled by calling readline.parse_and_bind("set
enable-bracketed-paste on"). See bpo-42819 for more details.
This should be removed if bracketed paste mode is implemented (bpo-39820).
*/

static void
disable_bracketed_paste(void)
{
if (!using_libedit_emulation) {
rl_variable_bind ("enable-bracketed-paste", "off");
}
}

/* Exported function to send one line to readline's init file parser */

static PyObject *
Expand Down Expand Up @@ -187,6 +207,7 @@ read_init_file(PyObject *self, PyObject *args)
errno = rl_read_init_file(NULL);
if (errno)
return PyErr_SetFromErrno(PyExc_OSError);
disable_bracketed_paste();
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -1146,6 +1167,8 @@ setup_readline(readlinestate *mod_state)
else
rl_initialize();

disable_bracketed_paste();

RESTORE_LOCALE(saved_locale)
}

Expand Down

0 comments on commit f9d7c12

Please sign in to comment.