Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def process_control_event(self, e):
if isinstance(e, bpythonevents.ScheduledRefreshRequestEvent):
# This is a scheduled refresh - it's really just a refresh (so nop)
pass
elif isinstance(e, bpythonevents.RefreshRequestEvent):
logger.info("received ASAP refresh request event")
if self.status_bar.has_focus:
self.status_bar.process_event(e)
else:
assert self.coderunner.code_is_waiting
self.run_code_and_maybe_finish()
elif self.status_bar.has_focus:
return self.status_bar.process_event(e)
# handles paste events for both stdin and repl
elif isinstance(e, events.PasteEvent):
ctrl_char = compress_paste_event(e)
if ctrl_char is not None:
return self.process_event(ctrl_char)
with self.in_paste_mode():
self.coderunner.interp = self.interp
self.initialize_interp()
self.buffer = []
self.display_buffer = []
self.highlighted_paren = None
self.process_event(bpythonevents.RunStartupFileEvent())
self.reevaluating = True
sys.stdin = ReevaluateFakeStdin(self.stdin, self)
for line in old_logical_lines:
self._current_line = line
self.on_enter(insert_into_history=insert_into_history)
while self.fake_refresh_requested:
self.fake_refresh_requested = False
self.process_event(bpythonevents.RefreshRequestEvent())
sys.stdin = self.stdin
self.reevaluating = False
num_lines_onscreen = len(self.lines_for_display) - max(
0, self.scroll_offset
)
display_lines_offscreen = self.display_lines[
: len(self.display_lines) - num_lines_onscreen
]
old_display_lines_offscreen = old_display_lines[
: (len(self.display_lines) - num_lines_onscreen)
]
logger.debug(
"old_display_lines_offscreen %s",
"|".join(str(x) for x in old_display_lines_offscreen),
)
def process_simple_keypress(self, e):
# '\n' needed for pastes
if e in ("", "", "", "\n", "\r"):
self.on_enter()
while self.fake_refresh_requested:
self.fake_refresh_requested = False
self.process_event(bpythonevents.RefreshRequestEvent())
elif isinstance(e, events.Event):
pass # ignore events
elif e == "":
self.add_normal_character(" ")
else:
self.add_normal_character(e)
def process_event(self, e):
"""Returns True if shutting down"""
assert self.in_prompt or self.in_confirm or self.waiting_for_refresh
if isinstance(e, RefreshRequestEvent):
self.waiting_for_refresh = False
self.request_context.switch()
elif isinstance(e, events.PasteEvent):
for ee in e.events:
# strip control seq
self.add_normal_character(ee if len(ee) == 1 else ee[-1])
elif e in [""] or isinstance(e, events.SigIntEvent):
self.request_context.switch(False)
self.escape()
elif e in edit_keys:
self.cursor_offset_in_line, self._current_line = edit_keys[e](
self.cursor_offset_in_line, self._current_line
)
elif e == "": # TODO can this be removed?
raise KeyboardInterrupt()
elif e == "": # TODO this isn't a very intuitive behavior
def _request_refresh(self):
self.requested_events.append(bpythonevents.RefreshRequestEvent())