@@ -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