]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42819, readline: Disable bracketed paste (GH-24108)
authorDustin Rodrigues <dust.rod@gmail.com>
Mon, 15 Feb 2021 23:28:24 +0000 (18:28 -0500)
committerGitHub <noreply@github.com>
Mon, 15 Feb 2021 23:28:24 +0000 (00:28 +0100)
Misc/ACKS
Misc/NEWS.d/next/Core and Builtins/2021-01-04-23-54-34.bpo-42819.4KO6wU.rst [new file with mode: 0644]
Modules/readline.c

index 29ef9864f98271a7ba161696140a00505025661d..ca222e4371f5e481c6d9edf38d93414bc29c0ac4 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1461,6 +1461,7 @@ Mark Roddy
 Kevin Rodgers
 Sean Rodman
 Giampaolo Rodola
+Dustin Rodrigues
 Mauro S. M. Rodrigues
 Elson Rodriguez
 Adi Roiban
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-01-04-23-54-34.bpo-42819.4KO6wU.rst b/Misc/NEWS.d/next/Core and Builtins/2021-01-04-23-54-34.bpo-42819.4KO6wU.rst
new file mode 100644 (file)
index 0000000..d067f0b
--- /dev/null
@@ -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.
index c900e079543c4f85eca68b9d70ef950504b722a8..c79d22f85f84ea3b1b4a5809cf1dc7dcf72168b7 100644 (file)
@@ -156,6 +156,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]
@@ -217,6 +237,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;
 }
 
@@ -1267,6 +1288,8 @@ setup_readline(readlinestate *mod_state)
     else
         rl_initialize();
 
+    disable_bracketed_paste();
+
     RESTORE_LOCALE(saved_locale)
     return 0;
 }