MCPcopy Index your code
hub / github.com/python/cpython / copy_with_prompts_callback

Method copy_with_prompts_callback

Lib/idlelib/pyshell.py:1005–1023  ·  view source on GitHub ↗

Copy selected lines to the clipboard, with prompts. This makes the copied text useful for doc-tests and interactive shell code examples. This always copies entire lines, even if only part of the first and/or last lines is selected.

(self, event=None)

Source from the content-addressed store, hash-verified

1003
1004
1005 def copy_with_prompts_callback(self, event=None):
1006 """Copy selected lines to the clipboard, with prompts.
1007
1008 This makes the copied text useful for doc-tests and interactive
1009 shell code examples.
1010
1011 This always copies entire lines, even if only part of the first
1012 and/or last lines is selected.
1013 """
1014 text = self.text
1015 selfirst = text.index('sel.first linestart')
1016 if selfirst is None: # Should not be possible.
1017 return # No selection, do nothing.
1018 sellast = text.index('sel.last')
1019 if sellast[-1] != '0':
1020 sellast = text.index("sel.last+1line linestart")
1021 text.clipboard_clear()
1022 prompt_text = self.get_prompt_text(selfirst, sellast)
1023 text.clipboard_append(prompt_text)
1024
1025 reading = False
1026 executing = False

Callers

nothing calls this directly

Calls 4

get_prompt_textMethod · 0.95
clipboard_clearMethod · 0.80
clipboard_appendMethod · 0.80
indexMethod · 0.45

Tested by

no test coverage detected