Skip to content

Commit 85fd9f4

Browse files
bpo-42819, readline: Disable bracketed paste (GH-24108) (GH-24545)
(cherry picked from commit 755f3c1) Co-authored-by: Dustin Rodrigues <[email protected]> Co-authored-by: Dustin Rodrigues <[email protected]>
1 parent 9cc70bc commit 85fd9f4

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
@@ -1444,6 +1444,7 @@ Mark Roddy
14441444
Kevin Rodgers
14451445
Sean Rodman
14461446
Giampaolo Rodola
1447+
Dustin Rodrigues
14471448
Mauro S. M. Rodrigues
14481449
Elson Rodriguez
14491450
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
@@ -146,6 +146,26 @@ decode(const char *s)
146146
}
147147

148148

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

151171
static PyObject *
@@ -192,6 +212,7 @@ read_init_file(PyObject *self, PyObject *args)
192212
errno = rl_read_init_file(NULL);
193213
if (errno)
194214
return PyErr_SetFromErrno(PyExc_OSError);
215+
disable_bracketed_paste();
195216
Py_RETURN_NONE;
196217
}
197218

@@ -1152,6 +1173,8 @@ setup_readline(readlinestate *mod_state)
11521173
else
11531174
rl_initialize();
11541175

1176+
disable_bracketed_paste();
1177+
11551178
RESTORE_LOCALE(saved_locale)
11561179
return 0;
11571180
}

0 commit comments

Comments
 (0)