Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-42819: disable Readline bracketed paste #24108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,7 @@ Mark Roddy
Kevin Rodgers
Sean Rodman
Giampaolo Rodola
Dustin Rodrigues
Mauro S. M. Rodrigues
Elson Rodriguez
Adi Roiban
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,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 */

/*[clinic input]
Expand Down Expand Up @@ -212,6 +232,7 @@ readline_read_init_file_impl(PyObject *module, PyObject *filename_obj)
errno = rl_read_init_file(NULL);
if (errno)
return PyErr_SetFromErrno(PyExc_OSError);
disable_bracketed_paste();
Py_RETURN_NONE;
}

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

disable_bracketed_paste();

RESTORE_LOCALE(saved_locale)
return 0;
}
Expand Down