def SagePromptTransformer(): r""" Strip the sage:/....: prompts of Sage. EXAMPLES:: sage: from sage.repl.interpreter import SagePromptTransformer sage: spt = SagePromptTransformer() sage: spt.push("sage: 2 + 2") '2 + 2' sage: spt.push('') '' sage: spt.push("....: 2+2") '2+2' This should strip multiple prompts: see :trac:`16297`:: sage: spt.push("sage: sage: 2+2") '2+2' sage: spt.push(" sage: ....: 2+2") '2+2' The prompt contains a trailing space. Extra spaces between the last prompt and the remainder should not be stripped:: sage: spt.push(" sage: ....: 2+2") ' 2+2' We test that the input transformer is enabled on the Sage command line:: sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell() sage: shell.run_cell('sage: a = 123') # single line sage: shell.run_cell('sage: a = [\n... 123]') # old-style multi-line sage: shell.run_cell('sage: a = [\n....: 123]') # new-style multi-line We test that :trac:`16196` is resolved:: sage: shell.run_cell(' sage: 1+1') 2 sage: shell.quit() """ _sage_prompt_re = re.compile(r'^(\s*(:?sage: |\.\.\.\.: ))+') return _strip_prompts(_sage_prompt_re)
def sage_prompt_transformer(): """ Strip the sage:/... prompts of Sage. EXAMPLES:: sage: from sage.misc.interpreter import sage_prompt_transformer sage: spt = sage_prompt_transformer() sage: spt.push("sage: sage: 2 + 2") '2 + 2' sage: spt.push('') '' sage: spt.push("sage: 2+2") '2+2' sage: spt.push("... .... ....: ...: 2+2") '2+2' """ _sage_prompt_re = re.compile(r'^(sage: |\.\.\.\.?:? )+') return _strip_prompts(_sage_prompt_re)
def SagePromptTransformer(): r""" Strip the sage:/....: prompts of Sage. EXAMPLES:: sage: from sage.repl.interpreter import SagePromptTransformer sage: spt = SagePromptTransformer() sage: spt.push("sage: 2 + 2") '2 + 2' sage: spt.push('') '' sage: spt.push("....: 2+2") '2+2' To match IPython behavior, this only strips one prompt:: sage: spt.push("sage: sage: 2+2") 'sage: 2+2' sage: spt.push("sage: ....: 2+2") '....: 2+2' We test that the input transformer is enabled on the Sage command line:: sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell() sage: shell.run_cell('sage: a = 123') # single line sage: shell.run_cell('sage: a = [\n... 123]') # old-style multi-line sage: shell.run_cell('sage: a = [\n....: 123]') # new-style multi-line We test that :trac:`16196` is resolved:: sage: shell.run_cell(' sage: 1+1') 2 """ _sage_prompt_re = re.compile(r'^(:?sage: |\.\.\.\.: )') return _strip_prompts(_sage_prompt_re)