Repository navigation
gh-154730: Add timeout in PyREPL to distinguish between bare Esc and multibyte escape sequence - #154731
gh-154730: Add timeout in PyREPL to distinguish between bare Esc and multibyte escape sequence#154731tanloong wants to merge 11 commits into
Esc and multibyte escape sequence#154731Conversation
Esc and multibyte escape sequenceEsc and multibyte escape sequence
|
This PR is stale because it has been open for 90 days with no activity. |
| self.encoding = encoding | ||
| self.events: deque[Event] = deque() | ||
| self.buf = bytearray() | ||
| default = float(os.environ.get("PYREPL_ESC_TIMEOUT", ESC_TIMEOUT_DEFAULT)) |
There was a problem hiding this comment.
PYREPL_ESC_TIMEOUT=bad disables PyREPL at startup. Can we use the default when the value is invalid?
There was a problem hiding this comment.
Added fallback when PYREPL_ESC_TIMEOUT is non-numeric / negative / NaN / infinite.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Revert "Ignore mypy error: "bytearray" has no attribute "take_bytes"" This reverts commit 277ada7.
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @pablogsal: please review the changes made to this pull request. |
This adds a timeout to disambiguate bare Esc from the start of a longer escape sequence.
pending()toBaseEventQueue: returnsTruewhen the queue has consumed a prefix (e.g.,\x1b) but is still waiting for more bytes.flush()toBaseEventQueue: finalises a pending prefix as a standalone key (emits \x1b and re-feeds any remaining buffered bytes).esc_timeoutparameter toBaseEventQueue(default 0.1 seconds; override viaPYREPL_ESC_TIMEOUTenv var).In both
unix_console.get_event()andwindows_console.get_event(), whenevent_queue.pending()isTrue, the next read blocks only foresc_timeoutseconds. If the timeout expires, callflush()and deliver the standaloneEscevent.