From a030f7eb5e9a017584eaccfbdb08fcff144231cd 2011-10-18 20:17:52
From: Fernando Perez <Fernando.Perez@berkeley.edu>
Date: 2011-10-18 20:17:52
Subject: [PATCH] Merge branch 'djv-master': partial fix for issue #678.

Now multiline structures pasted from doctests with input prompts work
in most regular cases.

---

diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py
index 0856a53..b1c18a9 100644
--- a/IPython/core/inputsplitter.py
+++ b/IPython/core/inputsplitter.py
@@ -758,9 +758,11 @@ class IPythonInputSplitter(InputSplitter):
         
         try:
             push = super(IPythonInputSplitter, self).push
+            buf = self._buffer
             for line in lines_list:
-                if self._is_complete or not self._buffer or \
-                   (self._buffer and self._buffer[-1].rstrip().endswith(':')):
+                if self._is_complete or not buf or \
+                       (buf and (buf[-1].rstrip().endswith(':') or
+                                 buf[-1].rstrip().endswith(',')) ):
                     for f in transforms:
                         line = f(line)
 
diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py
index bf1d79c..c1ba2b7 100644
--- a/IPython/core/tests/test_inputsplitter.py
+++ b/IPython/core/tests/test_inputsplitter.py
@@ -534,6 +534,12 @@ syntax_ml = \
           ('   ....: ', ''),
           ],
          ],
+
+       multiline_datastructure =
+       [ [('>>> a = [1,','a = [1,'),
+          ('... 2]','2]'),
+         ],
+       ],
        )