Show More
@@ -160,7 +160,7 class IPythonWidget(FrontendWidget): | |||||
160 | else: |
|
160 | else: | |
161 | super(IPythonWidget, self)._handle_execute_reply(msg) |
|
161 | super(IPythonWidget, self)._handle_execute_reply(msg) | |
162 |
|
162 | |||
163 |
def _handle_history_ |
|
163 | def _handle_history_reply(self, msg): | |
164 | """ Implemented to handle history tail replies, which are only supported |
|
164 | """ Implemented to handle history tail replies, which are only supported | |
165 | by the IPython kernel. |
|
165 | by the IPython kernel. | |
166 | """ |
|
166 | """ | |
@@ -212,7 +212,7 class IPythonWidget(FrontendWidget): | |||||
212 | """ Reimplemented to make a history request. |
|
212 | """ Reimplemented to make a history request. | |
213 | """ |
|
213 | """ | |
214 | super(IPythonWidget, self)._started_channels() |
|
214 | super(IPythonWidget, self)._started_channels() | |
215 |
self.kernel_manager.xreq_channel.history |
|
215 | self.kernel_manager.xreq_channel.history(hist_access_type='tail', n=1000) | |
216 |
|
216 | |||
217 | #--------------------------------------------------------------------------- |
|
217 | #--------------------------------------------------------------------------- | |
218 | # 'ConsoleWidget' public interface |
|
218 | # 'ConsoleWidget' public interface |
@@ -46,7 +46,7 class QtXReqSocketChannel(SocketChannelQObject, XReqSocketChannel): | |||||
46 | execute_reply = QtCore.Signal(object) |
|
46 | execute_reply = QtCore.Signal(object) | |
47 | complete_reply = QtCore.Signal(object) |
|
47 | complete_reply = QtCore.Signal(object) | |
48 | object_info_reply = QtCore.Signal(object) |
|
48 | object_info_reply = QtCore.Signal(object) | |
49 |
history_ |
|
49 | history_reply = QtCore.Signal(object) | |
50 |
|
50 | |||
51 | # Emitted when the first reply comes back. |
|
51 | # Emitted when the first reply comes back. | |
52 | first_reply = QtCore.Signal() |
|
52 | first_reply = QtCore.Signal() |
@@ -122,7 +122,7 class Kernel(Configurable): | |||||
122 |
|
122 | |||
123 | # Build dict of handlers for message types |
|
123 | # Build dict of handlers for message types | |
124 | msg_types = [ 'execute_request', 'complete_request', |
|
124 | msg_types = [ 'execute_request', 'complete_request', | |
125 |
'object_info_request', 'history_ |
|
125 | 'object_info_request', 'history_request', | |
126 | 'connect_request', 'shutdown_request'] |
|
126 | 'connect_request', 'shutdown_request'] | |
127 | self.handlers = {} |
|
127 | self.handlers = {} | |
128 | for msg_type in msg_types: |
|
128 | for msg_type in msg_types: | |
@@ -323,15 +323,32 class Kernel(Configurable): | |||||
323 | oinfo, parent, ident) |
|
323 | oinfo, parent, ident) | |
324 | logger.debug(msg) |
|
324 | logger.debug(msg) | |
325 |
|
325 | |||
326 |
def history_ |
|
326 | def history_request(self, ident, parent): | |
327 | # We need to pull these out, as passing **kwargs doesn't work with |
|
327 | # We need to pull these out, as passing **kwargs doesn't work with | |
328 | # unicode keys before Python 2.6.5. |
|
328 | # unicode keys before Python 2.6.5. | |
329 |
|
|
329 | hist_access_type = parent['content']['hist_access_type'] | |
330 | raw = parent['content']['raw'] |
|
330 | raw = parent['content']['raw'] | |
331 | output = parent['content']['output'] |
|
331 | output = parent['content']['output'] | |
332 | hist = self.shell.history_manager.get_tail(n, raw=raw, output=output) |
|
332 | if hist_access_type == 'tail': | |
|
333 | n = parent['content']['n'] | |||
|
334 | hist = self.shell.history_manager.get_tail(n, raw=raw, output=output, | |||
|
335 | include_latest=True) | |||
|
336 | ||||
|
337 | elif hist_access_type == 'range': | |||
|
338 | session = parent['content']['session'] | |||
|
339 | start = parent['content']['start'] | |||
|
340 | stop = parent['content']['stop'] | |||
|
341 | hist = self.shell.history_manager.get_range(session, start, stop, | |||
|
342 | raw=raw, output=output) | |||
|
343 | ||||
|
344 | elif hist_access_type == 'search': | |||
|
345 | pattern = parent['content']['pattern'] | |||
|
346 | hist = self.shell.history_manager.search(pattern, raw=raw, output=output) | |||
|
347 | ||||
|
348 | else: | |||
|
349 | hist = [] | |||
333 | content = {'history' : list(hist)} |
|
350 | content = {'history' : list(hist)} | |
334 |
msg = self.session.send(self.reply_socket, 'history_ |
|
351 | msg = self.session.send(self.reply_socket, 'history_reply', | |
335 | content, parent, ident) |
|
352 | content, parent, ident) | |
336 | logger.debug(str(msg)) |
|
353 | logger.debug(str(msg)) | |
337 |
|
354 |
@@ -282,24 +282,41 class XReqSocketChannel(ZmqSocketChannel): | |||||
282 | self._queue_request(msg) |
|
282 | self._queue_request(msg) | |
283 | return msg['header']['msg_id'] |
|
283 | return msg['header']['msg_id'] | |
284 |
|
284 | |||
285 |
def history |
|
285 | def history(self, raw=True, output=False, hist_access_type='range', **kwargs): | |
286 | """Get the history list. |
|
286 | """Get entries from the history list. | |
287 |
|
287 | |||
288 | Parameters |
|
288 | Parameters | |
289 | ---------- |
|
289 | ---------- | |
290 | n : int |
|
|||
291 | The number of lines of history to get. |
|
|||
292 | raw : bool |
|
290 | raw : bool | |
293 | If True, return the raw input. |
|
291 | If True, return the raw input. | |
294 | output : bool |
|
292 | output : bool | |
295 | If True, then return the output as well. |
|
293 | If True, then return the output as well. | |
|
294 | hist_access_type : str | |||
|
295 | 'range' (fill in session, start and stop params), 'tail' (fill in n) | |||
|
296 | or 'search' (fill in pattern param). | |||
|
297 | ||||
|
298 | session : int | |||
|
299 | For a range request, the session from which to get lines. Session | |||
|
300 | numbers are positive integers; negative ones count back from the | |||
|
301 | current session. | |||
|
302 | start : int | |||
|
303 | The first line number of a history range. | |||
|
304 | stop : int | |||
|
305 | The final (excluded) line number of a history range. | |||
|
306 | ||||
|
307 | n : int | |||
|
308 | The number of lines of history to get for a tail request. | |||
|
309 | ||||
|
310 | pattern : str | |||
|
311 | The glob-syntax pattern for a search request. | |||
296 |
|
312 | |||
297 | Returns |
|
313 | Returns | |
298 | ------- |
|
314 | ------- | |
299 | The msg_id of the message sent. |
|
315 | The msg_id of the message sent. | |
300 | """ |
|
316 | """ | |
301 |
content = dict( |
|
317 | content = dict(raw=raw, output=output, hist_access_type=hist_access_type, | |
302 | msg = self.session.msg('history_tail_request', content) |
|
318 | **kwargs) | |
|
319 | msg = self.session.msg('history_request', content) | |||
303 | self._queue_request(msg) |
|
320 | self._queue_request(msg) | |
304 | return msg['header']['msg_id'] |
|
321 | return msg['header']['msg_id'] | |
305 |
|
322 |
@@ -596,21 +596,34 Message type: ``history_request``:: | |||||
596 | # If True, return the raw input history, else the transformed input. |
|
596 | # If True, return the raw input history, else the transformed input. | |
597 | 'raw' : bool, |
|
597 | 'raw' : bool, | |
598 |
|
598 | |||
599 | # This parameter can be one of: A number, a pair of numbers, None |
|
599 | # So far, this can be 'range', 'tail' or 'search'. | |
600 | # If not given, last 40 are returned. |
|
600 | 'hist_access_type' : str, | |
601 | # - number n: return the last n entries. |
|
601 | ||
602 | # - pair n1, n2: return entries in the range(n1, n2). |
|
602 | # If hist_access_type is 'range', get a range of input cells. session can | |
603 | # - None: return all history |
|
603 | # be a positive session number, or a negative number to count back from | |
604 | 'index' : n or (n1, n2) or None, |
|
604 | # the current session. | |
|
605 | 'session' : int, | |||
|
606 | # start and stop are line numbers within that session. | |||
|
607 | 'start' : int, | |||
|
608 | 'stop' : int, | |||
|
609 | ||||
|
610 | # If hist_access_type is 'tail', get the last n cells. | |||
|
611 | 'n' : int, | |||
|
612 | ||||
|
613 | # If hist_access_type is 'search', get cells matching the specified glob | |||
|
614 | # pattern (with * and ? as wildcards). | |||
|
615 | 'pattern' : str, | |||
|
616 | ||||
605 | } |
|
617 | } | |
606 |
|
618 | |||
607 | Message type: ``history_reply``:: |
|
619 | Message type: ``history_reply``:: | |
608 |
|
620 | |||
609 | content = { |
|
621 | content = { | |
610 | # A dict with prompt numbers as keys and either (input, output) or input |
|
622 | # A list of 3 tuples, either: | |
611 | # as the value depending on whether output was True or False, |
|
623 | # (session, line_number, input) or | |
612 | # respectively. |
|
624 | # (session, line_number, (input, output)), | |
613 | 'history' : dict, |
|
625 | # depending on whether output was False or True, respectively. | |
|
626 | 'history' : list, | |||
614 | } |
|
627 | } | |
615 |
|
628 | |||
616 |
|
629 |
General Comments 0
You need to be logged in to leave comments.
Login now