##// END OF EJS Templates
Rename input modes of input splitter to 'line' and 'block'....
Fernando Perez -
Show More
@@ -202,7 +202,7 b' class InputSplitter(object):'
202 202 # object; it will be None if the source doesn't compile to valid Python.
203 203 code = None
204 204 # Input mode
205 input_mode = 'append'
205 input_mode = 'line'
206 206
207 207 # Private attributes
208 208
@@ -222,14 +222,18 b' class InputSplitter(object):'
222 222 ----------
223 223 input_mode : str
224 224
225 One of ['append', 'replace']; default is 'append'. This controls how
226 new inputs are used: in 'append' mode, they are appended to the
227 existing buffer and the whole buffer is compiled; in 'replace' mode,
228 each new input completely replaces all prior inputs. Replace mode is
229 thus equivalent to prepending a full reset() to every push() call.
225 One of ['line', 'block']; default is 'line'.
230 226
231 In practice, line-oriented clients likely want to use 'append' mode
232 while block-oriented ones will want to use 'replace'.
227 The input_mode parameter controls how new inputs are used when fed via
228 the :meth:`push` method:
229
230 - 'line': meant for line-oriented clients, inputs are appended one at a
231 time to the internal buffer and the whole buffer is compiled.
232
233 - 'block': meant for clients that can edit multi-line blocks of text at
234 a time. Each new input new input completely replaces all prior
235 inputs. Block mode is thus equivalent to prepending a full reset()
236 to every push() call.
233 237 """
234 238 self._buffer = []
235 239 self._compile = codeop.CommandCompiler()
@@ -275,7 +279,7 b' class InputSplitter(object):'
275 279 this value is also stored as a private attribute (_is_complete), so it
276 280 can be queried at any time.
277 281 """
278 if self.input_mode == 'replace':
282 if self.input_mode == 'block':
279 283 self.reset()
280 284
281 285 # If the source code has leading blanks, add 'if 1:\n' to it
@@ -829,18 +833,18 b' class IPythonInputSplitter(InputSplitter):'
829 833 #
830 834 # FIXME: try to find a cleaner approach for this last bit.
831 835
832 # If we were in 'replace' mode, since we're going to pump the parent
836 # If we were in 'block' mode, since we're going to pump the parent
833 837 # class by hand line by line, we need to temporarily switch out to
834 # 'append' mode, do a single manual reset and then feed the lines one
838 # 'line' mode, do a single manual reset and then feed the lines one
835 839 # by one. Note that this only matters if the input has more than one
836 840 # line.
837 841 changed_input_mode = False
838 842
839 if len(lines_list)>1 and self.input_mode == 'replace':
843 if len(lines_list)>1 and self.input_mode == 'block':
840 844 self.reset()
841 845 changed_input_mode = True
842 saved_input_mode = 'replace'
843 self.input_mode = 'append'
846 saved_input_mode = 'block'
847 self.input_mode = 'line'
844 848
845 849 try:
846 850 push = super(IPythonInputSplitter, self).push
@@ -204,7 +204,7 b' class InputSplitterTestCase(unittest.TestCase):'
204 204
205 205 def test_replace_mode(self):
206 206 isp = self.isp
207 isp.input_mode = 'replace'
207 isp.input_mode = 'block'
208 208 isp.push('x=1')
209 209 self.assertEqual(isp.source, 'x=1\n')
210 210 isp.push('x=2')
@@ -556,7 +556,7 b' class IPythonInputTestCase(InputSplitterTestCase):'
556 556 """
557 557
558 558 def setUp(self):
559 self.isp = isp.IPythonInputSplitter(input_mode='append')
559 self.isp = isp.IPythonInputSplitter(input_mode='line')
560 560
561 561 def test_syntax(self):
562 562 """Call all single-line syntax tests from the main object"""
@@ -590,7 +590,7 b' class BlockIPythonInputTestCase(IPythonInputTestCase):'
590 590 test_push3 = test_split = lambda s: None
591 591
592 592 def setUp(self):
593 self.isp = isp.IPythonInputSplitter(input_mode='replace')
593 self.isp = isp.IPythonInputSplitter(input_mode='block')
594 594
595 595 def test_syntax_multiline(self):
596 596 isp = self.isp
@@ -103,7 +103,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
103 103 self._completion_lexer = CompletionLexer(PythonLexer())
104 104 self._hidden = False
105 105 self._highlighter = self._highlighter_class(self)
106 self._input_splitter = self._input_splitter_class(input_mode='replace')
106 self._input_splitter = self._input_splitter_class(input_mode='block')
107 107 self._kernel_manager = None
108 108
109 109 # Configure the ConsoleWidget.
General Comments 0
You need to be logged in to leave comments. Login now