Skip to content

Commit 755f3c1

Browse files
authored
bpo-42819, readline: Disable bracketed paste (GH-24108)
1 parent 813db24 commit 755f3c1

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,7 @@ Mark Roddy
14611461
Kevin Rodgers
14621462
Sean Rodman
14631463
Giampaolo Rodola
1464+
Dustin Rodrigues
14641465
Mauro S. M. Rodrigues
14651466
Elson Rodriguez
14661467
Adi Roiban
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:mod:`readline`: Explicitly disable bracketed paste in the interactive
2+
interpreter, even if it's set in the inputrc, is enabled by default (eg GNU
3+
Readline 8.1), or a user calls ``readline.read_init_file()``. The Python REPL
4+
has not implemented bracketed paste support. Also, bracketed mode writes the
5+
``"\x1b[?2004h"`` escape sequence into stdout which causes test failures in
6+
applications that don't support it. It can still be explicitly enabled by
7+
calling ``readline.parse_and_bind("set enable-bracketed-paste on")``. Patch by
8+
Dustin Rodrigues.

Modules/readline.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ decode(const char *s)
156156
}
157157

158158

159+
/*
160+
Explicitly disable bracketed paste in the interactive interpreter, even if it's
161+
set in the inputrc, is enabled by default (eg GNU Readline 8.1), or a user calls
162+
readline.read_init_file(). The Python REPL has not implemented bracketed
163+
paste support. Also, bracketed mode writes the "\x1b[?2004h" escape sequence
164+
into stdout which causes test failures in applications that don't support it.
165+
It can still be explicitly enabled by calling readline.parse_and_bind("set
166+
enable-bracketed-paste on"). See bpo-42819 for more details.
167+
168+
This should be removed if bracketed paste mode is implemented (bpo-39820).
169+
*/
170+
171+
static void
172+
disable_bracketed_paste(void)
173+
{
174+
if (!using_libedit_emulation) {
175+
rl_variable_bind ("enable-bracketed-paste", "off");
176+
}
177+
}
178+
159179
/* Exported function to send one line to readline's init file parser */
160180

161181
/*[clinic input]
@@ -217,6 +237,7 @@ readline_read_init_file_impl(PyObject *module, PyObject *filename_obj)
217237
errno = rl_read_init_file(NULL);
218238
if (errno)
219239
return PyErr_SetFromErrno(PyExc_OSError);
240+
disable_bracketed_paste();
220241
Py_RETURN_NONE;
221242
}
222243

@@ -1267,6 +1288,8 @@ setup_readline(readlinestate *mod_state)
12671288
else
12681289
rl_initialize();
12691290

1291+
disable_bracketed_paste();
1292+
12701293
RESTORE_LOCALE(saved_locale)
12711294
return 0;
12721295
}

0 commit comments

Comments
 (0)