From 838a2481750a9035877b7c9ba167189773040ee4 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Mon, 4 Jan 2021 22:20:04 -0500 Subject: [PATCH 1/6] bpo-42819: disable Readline bracketed paste --- Misc/ACKS | 1 + .../2021-01-04-23-54-34.bpo-42819.4KO6wU.rst | 3 +++ Modules/readline.c | 7 +++++++ 3 files changed, 11 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-01-04-23-54-34.bpo-42819.4KO6wU.rst diff --git a/Misc/ACKS b/Misc/ACKS index 211455b4dfc3c2..0cf3b9cf6cc8db 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1459,6 +1459,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 index 00000000000000..0014e362419c96 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-01-04-23-54-34.bpo-42819.4KO6wU.rst @@ -0,0 +1,3 @@ +Prevents bracketed paste from being enabled in the interactive interpreter, +even if it's set in the inputrc or is enabled by default (eg GNU Readline +8.1). Patch by Dustin Rodrigues. diff --git a/Modules/readline.c b/Modules/readline.c index 6cb3ee5c66a0d8..b66616295ac808 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -212,6 +212,9 @@ readline_read_init_file_impl(PyObject *module, PyObject *filename_obj) errno = rl_read_init_file(NULL); if (errno) return PyErr_SetFromErrno(PyExc_OSError); + if (!using_libedit_emulation) { + rl_variable_bind ("enable-bracketed-paste", "off"); + } Py_RETURN_NONE; } @@ -1241,6 +1244,10 @@ setup_readline(readlinestate *mod_state) else rl_initialize(); + if (!using_libedit_emulation) { + rl_variable_bind ("enable-bracketed-paste", "off"); + } + RESTORE_LOCALE(saved_locale) return 0; } From c5bd08ca62f5868d15849a6599322be536d00e24 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Mon, 15 Feb 2021 11:24:25 -0500 Subject: [PATCH 2/6] minor refactoring, add additional explanation for bracketed paste disabling --- .../2021-01-04-23-54-34.bpo-42819.4KO6wU.rst | 10 ++++--- Modules/readline.c | 26 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) 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 index 0014e362419c96..e2d4bf6745c585 100644 --- 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 @@ -1,3 +1,7 @@ -Prevents bracketed paste from being enabled in the interactive interpreter, -even if it's set in the inputrc or is enabled by default (eg GNU Readline -8.1). Patch by Dustin Rodrigues. +Explicitly disable bracketed paste in the interactive interpreter, even if it's +set in the inputrc or is enabled by default (eg GNU Readline 8.1). The Python +REPL has not implemented bracketed paste support so this prevents Readline +defaults or global user configuration from causing unexpected behavior within +Python. It can still be explicitly enabled by calling +``readline.parse_and_bind("set enable-bracketed-paste on")``. Patch by Dustin +Rodrigues. diff --git a/Modules/readline.c b/Modules/readline.c index b66616295ac808..41361953169400 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -151,6 +151,24 @@ decode(const char *s) } +/* + Explicitly disable bracketed paste mode. This is called both during module + initialization and after reading the init file. Even if the version of + Readline enables it by default or a user has it set, the Python REPL doesn't + support bracketed paste and it injects escape sequences which cause test + failures. This keeps the behavior consistent with user expectations for the + Python REPL when pasting multi-line strings. 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] @@ -212,9 +230,7 @@ readline_read_init_file_impl(PyObject *module, PyObject *filename_obj) errno = rl_read_init_file(NULL); if (errno) return PyErr_SetFromErrno(PyExc_OSError); - if (!using_libedit_emulation) { - rl_variable_bind ("enable-bracketed-paste", "off"); - } + disable_bracketed_paste(); Py_RETURN_NONE; } @@ -1244,9 +1260,7 @@ setup_readline(readlinestate *mod_state) else rl_initialize(); - if (!using_libedit_emulation) { - rl_variable_bind ("enable-bracketed-paste", "off"); - } + disable_bracketed_paste(); RESTORE_LOCALE(saved_locale) return 0; From 7d710ec7e2dc447f16fb80e60cdfe18dc325690c Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Mon, 15 Feb 2021 11:29:26 -0500 Subject: [PATCH 3/6] update readline bracketed paste changelog --- .../2021-01-04-23-54-34.bpo-42819.4KO6wU.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 index e2d4bf6745c585..537dbcf4ce305a 100644 --- 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 @@ -1,7 +1,7 @@ Explicitly disable bracketed paste in the interactive interpreter, even if it's -set in the inputrc or is enabled by default (eg GNU Readline 8.1). The Python -REPL has not implemented bracketed paste support so this prevents Readline -defaults or global user configuration from causing unexpected behavior within -Python. It can still be explicitly enabled by calling -``readline.parse_and_bind("set enable-bracketed-paste on")``. Patch by Dustin -Rodrigues. +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 so this prevents Readline defaults or global user configuration +from causing unexpected behavior within Python. It can still be explicitly +enabled by calling ``readline.parse_and_bind("set enable-bracketed-paste on")``. +Patch by Dustin Rodrigues. From 483f4970aa5c2fe9f8004259ce9264b91153fcc6 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Mon, 15 Feb 2021 12:05:59 -0500 Subject: [PATCH 4/6] update changelog wording, match function comment to changelog --- .../2021-01-04-23-54-34.bpo-42819.4KO6wU.rst | 16 +++++++++------- Modules/readline.c | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) 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 index 537dbcf4ce305a..fae88569665f9d 100644 --- 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 @@ -1,7 +1,9 @@ -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 so this prevents Readline defaults or global user configuration -from causing unexpected behavior within Python. It can still be explicitly -enabled by calling ``readline.parse_and_bind("set enable-bracketed-paste on")``. -Patch by Dustin Rodrigues. +: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")``. This +should be removed if bracketed paste mode is implemented (bpo-39820). Patch by +Dustin Rodrigues. diff --git a/Modules/readline.c b/Modules/readline.c index 41361953169400..e7f24c0315f6c7 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -152,13 +152,15 @@ decode(const char *s) /* - Explicitly disable bracketed paste mode. This is called both during module - initialization and after reading the init file. Even if the version of - Readline enables it by default or a user has it set, the Python REPL doesn't - support bracketed paste and it injects escape sequences which cause test - failures. This keeps the behavior consistent with user expectations for the - Python REPL when pasting multi-line strings. See bpo-42819 for more details. - This should be removed if bracketed paste mode is implemented (bpo-39820). +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 From c67290f64120795eb48d93fd293f1a62710bfef3 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Mon, 15 Feb 2021 14:13:27 -0500 Subject: [PATCH 5/6] formatting updates --- .../2021-01-04-23-54-34.bpo-42819.4KO6wU.rst | 5 ++--- Modules/readline.c | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) 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 index fae88569665f9d..e51bdaaeee1e6a 100644 --- 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 @@ -2,8 +2,7 @@ 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 +``"\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")``. This -should be removed if bracketed paste mode is implemented (bpo-39820). Patch by +calling ``readline.parse_and_bind("set enable-bracketed-paste on")``. Patch by Dustin Rodrigues. diff --git a/Modules/readline.c b/Modules/readline.c index e7f24c0315f6c7..6eb5b638ff75fb 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -154,11 +154,11 @@ 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 +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. +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). */ From 95a463d2c432bb64da7fe1c8571cac5197faddd5 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Mon, 15 Feb 2021 15:48:19 -0500 Subject: [PATCH 6/6] remove trailing whitespace --- .../Core and Builtins/2021-01-04-23-54-34.bpo-42819.4KO6wU.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index e51bdaaeee1e6a..d067f0bfa76448 100644 --- 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 @@ -1,4 +1,4 @@ -:mod:`readline`: Explicitly disable bracketed paste in the interactive +: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