@@ -141,6 +141,26 @@ decode(const char *s)
141141}
142142
143143
144+ /*
145+ Explicitly disable bracketed paste in the interactive interpreter, even if it's
146+ set in the inputrc, is enabled by default (eg GNU Readline 8.1), or a user calls
147+ readline.read_init_file(). The Python REPL has not implemented bracketed
148+ paste support. Also, bracketed mode writes the "\x1b[?2004h" escape sequence
149+ into stdout which causes test failures in applications that don't support it.
150+ It can still be explicitly enabled by calling readline.parse_and_bind("set
151+ enable-bracketed-paste on"). See bpo-42819 for more details.
152+
153+ This should be removed if bracketed paste mode is implemented (bpo-39820).
154+ */
155+
156+ static void
157+ disable_bracketed_paste (void )
158+ {
159+ if (!using_libedit_emulation ) {
160+ rl_variable_bind ("enable-bracketed-paste" , "off" );
161+ }
162+ }
163+
144164/* Exported function to send one line to readline's init file parser */
145165
146166static PyObject *
@@ -187,6 +207,7 @@ read_init_file(PyObject *self, PyObject *args)
187207 errno = rl_read_init_file (NULL );
188208 if (errno )
189209 return PyErr_SetFromErrno (PyExc_OSError );
210+ disable_bracketed_paste ();
190211 Py_RETURN_NONE ;
191212}
192213
@@ -1146,6 +1167,8 @@ setup_readline(readlinestate *mod_state)
11461167 else
11471168 rl_initialize ();
11481169
1170+ disable_bracketed_paste ();
1171+
11491172 RESTORE_LOCALE (saved_locale )
11501173}
11511174
0 commit comments