From ab4e1b4df6b6401353c460624f21d2d35a40908f 2011-06-22 22:50:32 From: Thomas Kluyver Date: 2011-06-22 22:50:32 Subject: [PATCH] Reorder inputsplitter transformers so that prompts pasted into the input are removed before other transforms are applied. --- diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index 356a385..dfa0fc4 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -665,7 +665,7 @@ def _make_help_call(target, esc, lspace): _initial_space_re = re.compile(r'\s*') _help_end_re = re.compile(r"""(%? [a-zA-Z_*][a-zA-Z0-9_*]* # Variable name - (.[a-zA-Z_*][a-zA-Z0-9_*]*)* # .etc.etc + (\.[a-zA-Z_*][a-zA-Z0-9_*]*)* # .etc.etc ) (\?\??)$ # ? or ??""", re.VERBOSE) @@ -812,9 +812,9 @@ class IPythonInputSplitter(InputSplitter): lines_list = lines.splitlines() - transforms = [transform_escaped, transform_help_end, - transform_assign_system, transform_assign_magic, - transform_ipy_prompt, transform_classic_prompt] + transforms = [transform_ipy_prompt, transform_classic_prompt, + transform_escaped, transform_help_end, + transform_assign_system, transform_assign_magic] # Transform logic # diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index c32068e..077bf33 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -480,7 +480,15 @@ syntax = \ (' /f y', ' f(y)'), ('/f a b', 'f(a, b)'), ], - + + # Check that we transform prompts before other transforms + mixed = + [ ('In [1]: %lsmagic', 'get_ipython().magic(u"lsmagic")'), + ('>>> %lsmagic', 'get_ipython().magic(u"lsmagic")'), + ('In [2]: !ls', 'get_ipython().system(u"ls")'), + ('In [3]: abs?', 'get_ipython().magic(u"pinfo abs")'), + ('In [4]: b = %who', 'b = get_ipython().magic(u"who")'), + ], ) # multiline syntax examples. Each of these should be a list of lists, with