Show More
@@ -133,7 +133,10 b' def _detect_screen_size(screen_lines_def):' | |||||
133 | #screen_cols,'columns.' # dbg |
|
133 | #screen_cols,'columns.' # dbg | |
134 |
|
134 | |||
135 | def page(strng, start=0, screen_lines=0, pager_cmd=None): |
|
135 | def page(strng, start=0, screen_lines=0, pager_cmd=None): | |
136 |
""" |
|
136 | """Display a string, piping through a pager after a certain length. | |
|
137 | ||||
|
138 | strng can be a mime-bundle dict, supplying multiple representations, | |||
|
139 | keyed by mime-type. | |||
137 |
|
140 | |||
138 | The screen_lines parameter specifies the number of *usable* lines of your |
|
141 | The screen_lines parameter specifies the number of *usable* lines of your | |
139 | terminal screen (total lines minus lines you need to reserve to show other |
|
142 | terminal screen (total lines minus lines you need to reserve to show other |
@@ -40,8 +40,8 b' version = __version__ # backwards compatibility name' | |||||
40 | version_info = (_version_major, _version_minor, _version_patch, _version_extra) |
|
40 | version_info = (_version_major, _version_minor, _version_patch, _version_extra) | |
41 |
|
41 | |||
42 | # Change this when incrementing the kernel protocol version |
|
42 | # Change this when incrementing the kernel protocol version | |
43 |
kernel_protocol_version_info = (5, 0 |
|
43 | kernel_protocol_version_info = (5, 0) | |
44 |
kernel_protocol_version = "%i.%i |
|
44 | kernel_protocol_version = "%i.%i" % kernel_protocol_version_info | |
45 |
|
45 | |||
46 | description = "IPython: Productive Interactive Computing" |
|
46 | description = "IPython: Productive Interactive Computing" | |
47 |
|
47 |
@@ -251,11 +251,6 b' var IPython = (function (IPython) {' | |||||
251 | this.reset_tabs_function (cell, text); |
|
251 | this.reset_tabs_function (cell, text); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | // don't do anything if line begins with '(' or is empty |
|
|||
255 | // if (text === "" || text === "(") { |
|
|||
256 | // return; |
|
|||
257 | // } |
|
|||
258 |
|
||||
259 | this.tabs_functions[this._consecutive_counter](cell, text, cursor_pos); |
|
254 | this.tabs_functions[this._consecutive_counter](cell, text, cursor_pos); | |
260 |
|
255 | |||
261 | // then if we are at the end of list function, reset |
|
256 | // then if we are at the end of list function, reset |
@@ -270,7 +270,7 b' class ShellChannel(ZMQSocketChannel):' | |||||
270 | self._queue_send(msg) |
|
270 | self._queue_send(msg) | |
271 | return msg['header']['msg_id'] |
|
271 | return msg['header']['msg_id'] | |
272 |
|
272 | |||
273 |
def complete(self, code, cursor_pos= |
|
273 | def complete(self, code, cursor_pos=None): | |
274 | """Tab complete text in the kernel's namespace. |
|
274 | """Tab complete text in the kernel's namespace. | |
275 |
|
275 | |||
276 | Parameters |
|
276 | Parameters | |
@@ -280,17 +280,20 b' class ShellChannel(ZMQSocketChannel):' | |||||
280 | Can be anything between a variable name and an entire cell. |
|
280 | Can be anything between a variable name and an entire cell. | |
281 | cursor_pos : int, optional |
|
281 | cursor_pos : int, optional | |
282 | The position of the cursor in the block of code where the completion was requested. |
|
282 | The position of the cursor in the block of code where the completion was requested. | |
|
283 | Default: ``len(code)`` | |||
283 |
|
284 | |||
284 | Returns |
|
285 | Returns | |
285 | ------- |
|
286 | ------- | |
286 | The msg_id of the message sent. |
|
287 | The msg_id of the message sent. | |
287 | """ |
|
288 | """ | |
|
289 | if cursor_pos is None: | |||
|
290 | cursor_pos = len(code) | |||
288 | content = dict(code=code, cursor_pos=cursor_pos) |
|
291 | content = dict(code=code, cursor_pos=cursor_pos) | |
289 | msg = self.session.msg('complete_request', content) |
|
292 | msg = self.session.msg('complete_request', content) | |
290 | self._queue_send(msg) |
|
293 | self._queue_send(msg) | |
291 | return msg['header']['msg_id'] |
|
294 | return msg['header']['msg_id'] | |
292 |
|
295 | |||
293 |
def inspect(self, code, cursor_pos= |
|
296 | def inspect(self, code, cursor_pos=None, detail_level=0): | |
294 | """Get metadata information about an object in the kernel's namespace. |
|
297 | """Get metadata information about an object in the kernel's namespace. | |
295 |
|
298 | |||
296 | It is up to the kernel to determine the appropriate object to inspect. |
|
299 | It is up to the kernel to determine the appropriate object to inspect. | |
@@ -302,6 +305,7 b' class ShellChannel(ZMQSocketChannel):' | |||||
302 | Can be anything between a variable name and an entire cell. |
|
305 | Can be anything between a variable name and an entire cell. | |
303 | cursor_pos : int, optional |
|
306 | cursor_pos : int, optional | |
304 | The position of the cursor in the block of code where the info was requested. |
|
307 | The position of the cursor in the block of code where the info was requested. | |
|
308 | Default: ``len(code)`` | |||
305 | detail_level : int, optional |
|
309 | detail_level : int, optional | |
306 | The level of detail for the introspection (0-2) |
|
310 | The level of detail for the introspection (0-2) | |
307 |
|
311 | |||
@@ -309,6 +313,8 b' class ShellChannel(ZMQSocketChannel):' | |||||
309 | ------- |
|
313 | ------- | |
310 | The msg_id of the message sent. |
|
314 | The msg_id of the message sent. | |
311 | """ |
|
315 | """ | |
|
316 | if cursor_pos is None: | |||
|
317 | cursor_pos = len(code) | |||
312 | content = dict(code=code, cursor_pos=cursor_pos, |
|
318 | content = dict(code=code, cursor_pos=cursor_pos, | |
313 | detail_level=detail_level, |
|
319 | detail_level=detail_level, | |
314 | ) |
|
320 | ) |
@@ -94,13 +94,17 b' class InProcessShellChannel(InProcessChannel):' | |||||
94 | self._dispatch_to_kernel(msg) |
|
94 | self._dispatch_to_kernel(msg) | |
95 | return msg['header']['msg_id'] |
|
95 | return msg['header']['msg_id'] | |
96 |
|
96 | |||
97 |
def complete(self, code, cursor_pos= |
|
97 | def complete(self, code, cursor_pos=None): | |
|
98 | if cursor_pos is None: | |||
|
99 | cursor_pos = len(code) | |||
98 | content = dict(code=code, cursor_pos=cursor_pos) |
|
100 | content = dict(code=code, cursor_pos=cursor_pos) | |
99 | msg = self.client.session.msg('complete_request', content) |
|
101 | msg = self.client.session.msg('complete_request', content) | |
100 | self._dispatch_to_kernel(msg) |
|
102 | self._dispatch_to_kernel(msg) | |
101 | return msg['header']['msg_id'] |
|
103 | return msg['header']['msg_id'] | |
102 |
|
104 | |||
103 |
def inspect(self, code, cursor_pos= |
|
105 | def inspect(self, code, cursor_pos=None, detail_level=0): | |
|
106 | if cursor_pos is None: | |||
|
107 | cursor_pos = len(code) | |||
104 | content = dict(code=code, cursor_pos=cursor_pos, |
|
108 | content = dict(code=code, cursor_pos=cursor_pos, | |
105 | detail_level=detail_level, |
|
109 | detail_level=detail_level, | |
106 | ) |
|
110 | ) |
@@ -59,11 +59,20 b' class Reference(HasTraits):' | |||||
59 | except TraitError as e: |
|
59 | except TraitError as e: | |
60 | assert False, str(e) |
|
60 | assert False, str(e) | |
61 |
|
61 | |||
|
62 | ||||
62 | class Version(Unicode): |
|
63 | class Version(Unicode): | |
|
64 | def __init__(self, *args, **kwargs): | |||
|
65 | self.min = kwargs.pop('min', None) | |||
|
66 | self.max = kwargs.pop('max', None) | |||
|
67 | kwargs['default_value'] = self.min | |||
|
68 | super(Version, self).__init__(*args, **kwargs) | |||
|
69 | ||||
63 | def validate(self, obj, value): |
|
70 | def validate(self, obj, value): | |
64 | min_version = self.default_value |
|
71 | if self.min and V(value) < V(self.min): | |
65 | if V(value) < V(min_version): |
|
72 | raise TraitError("bad version: %s < %s" % (value, self.min)) | |
66 | raise TraitError("bad version: %s < %s" % (value, min_version)) |
|
73 | if self.max and (V(value) > V(self.max)): | |
|
74 | raise TraitError("bad version: %s > %s" % (value, self.max)) | |||
|
75 | ||||
67 |
|
76 | |||
68 | class RMessage(Reference): |
|
77 | class RMessage(Reference): | |
69 | msg_id = Unicode() |
|
78 | msg_id = Unicode() | |
@@ -83,9 +92,9 b' class RHeader(Reference):' | |||||
83 | msg_type = Unicode() |
|
92 | msg_type = Unicode() | |
84 | session = Unicode() |
|
93 | session = Unicode() | |
85 | username = Unicode() |
|
94 | username = Unicode() | |
86 | version = Version('5.0') |
|
95 | version = Version(min='5.0') | |
87 |
|
96 | |||
88 |
mime_pat = re.compile(r'\w |
|
97 | mime_pat = re.compile(r'^[\w\-\+\.]+/[\w\-\+\.]+$') | |
89 |
|
98 | |||
90 | class MimeBundle(Reference): |
|
99 | class MimeBundle(Reference): | |
91 | metadata = Dict() |
|
100 | metadata = Dict() | |
@@ -143,10 +152,10 b' class CompleteReply(Reference):' | |||||
143 |
|
152 | |||
144 |
|
153 | |||
145 | class KernelInfoReply(Reference): |
|
154 | class KernelInfoReply(Reference): | |
146 | protocol_version = Version('5.0') |
|
155 | protocol_version = Version(min='5.0') | |
147 | implementation = Unicode('ipython') |
|
156 | implementation = Unicode('ipython') | |
148 | implementation_version = Version('2.1') |
|
157 | implementation_version = Version(min='2.1') | |
149 | language_version = Version('2.7') |
|
158 | language_version = Version(min='2.7') | |
150 | language = Unicode('python') |
|
159 | language = Unicode('python') | |
151 | banner = Unicode() |
|
160 | banner = Unicode() | |
152 |
|
161 |
@@ -369,9 +369,13 b' class Kernel(Configurable):' | |||||
369 | getpass.getpass = self._save_getpass |
|
369 | getpass.getpass = self._save_getpass | |
370 |
|
370 | |||
371 | def set_parent(self, ident, parent): |
|
371 | def set_parent(self, ident, parent): | |
372 |
""" |
|
372 | """Set the current parent_header | |
373 |
|
373 | |||
374 | For associating side effects with their requests. |
|
374 | Side effects (IOPub messages) and replies are associated with | |
|
375 | the request that caused them via the parent_header. | |||
|
376 | ||||
|
377 | The parent identity is used to route input_request messages | |||
|
378 | on the stdin channel. | |||
375 | """ |
|
379 | """ | |
376 | self._parent_ident = ident |
|
380 | self._parent_ident = ident | |
377 | self._parent_header = parent |
|
381 | self._parent_header = parent | |
@@ -617,9 +621,6 b' class Kernel(Configurable):' | |||||
617 | shell = self.shell |
|
621 | shell = self.shell | |
618 | shell.set_parent(parent) |
|
622 | shell.set_parent(parent) | |
619 |
|
623 | |||
620 | # execute_input_msg = self.session.msg(u'execute_input',{u'code':code}, parent=parent) |
|
|||
621 | # self.iopub_socket.send(execute_input_msg) |
|
|||
622 | # self.session.send(self.iopub_socket, u'execute_input', {u'code':code},parent=parent) |
|
|||
623 | md = self._make_metadata(parent['metadata']) |
|
624 | md = self._make_metadata(parent['metadata']) | |
624 | try: |
|
625 | try: | |
625 | working = shell.user_ns |
|
626 | working = shell.user_ns |
@@ -512,10 +512,6 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
512 | info = self._request_info.get('call_tip') |
|
512 | info = self._request_info.get('call_tip') | |
513 | if info and info.id == rep['parent_header']['msg_id'] and \ |
|
513 | if info and info.id == rep['parent_header']['msg_id'] and \ | |
514 | info.pos == cursor.position(): |
|
514 | info.pos == cursor.position(): | |
515 | # Get the information for a call tip. For now we format the call |
|
|||
516 | # line as string, later we can pass False to format_call and |
|
|||
517 | # syntax-highlight it ourselves for nicer formatting in the |
|
|||
518 | # calltip. |
|
|||
519 | content = rep['content'] |
|
515 | content = rep['content'] | |
520 | if content.get('status') == 'ok': |
|
516 | if content.get('status') == 'ok': | |
521 | self._call_tip_widget.show_inspect_data(content) |
|
517 | self._call_tip_widget.show_inspect_data(content) |
@@ -10,14 +10,12 b' The execution of use code consists of the following phases:' | |||||
10 | 3. Execute the ``code`` field, see below for details. |
|
10 | 3. Execute the ``code`` field, see below for details. | |
11 | 4. If execution succeeds, expressions in ``user_expressions`` are computed. |
|
11 | 4. If execution succeeds, expressions in ``user_expressions`` are computed. | |
12 | This ensures that any error in the expressions don't affect the main code execution. |
|
12 | This ensures that any error in the expressions don't affect the main code execution. | |
13 | 5. Fire the post_execute eventCall any method registered with :meth:`register_post_execute`. |
|
13 | 5. Fire the post_execute event. | |
14 |
|
14 | |||
15 | .. warning:: |
|
15 | .. seealso:: | |
|
16 | ||||
|
17 | :doc:`config/callbacks` | |||
16 |
|
18 | |||
17 | The API for running code before/after the main code block is likely to |
|
|||
18 | change soon. Both the ``pre_runcode_hook`` and the |
|
|||
19 | :meth:`register_post_execute` are susceptible to modification, as we find a |
|
|||
20 | consistent model for both. |
|
|||
21 |
|
19 | |||
22 | To understand how the ``code`` field is executed, one must know that Python |
|
20 | To understand how the ``code`` field is executed, one must know that Python | |
23 | code can be compiled in one of three modes (controlled by the ``mode`` argument |
|
21 | code can be compiled in one of three modes (controlled by the ``mode`` argument | |
@@ -64,7 +62,3 b" execution in 'single' mode, and then:" | |||||
64 | unit. |
|
62 | unit. | |
65 |
|
63 | |||
66 |
|
64 | |||
67 | Errors in any registered post_execute functions are reported, |
|
|||
68 | and the failing function is removed from the post_execution set so that it does |
|
|||
69 | not continue triggering failures. |
|
|||
70 |
|
@@ -9,7 +9,7 b' Versioning' | |||||
9 | ========== |
|
9 | ========== | |
10 |
|
10 | |||
11 | The IPython message specification is versioned independently of IPython. |
|
11 | The IPython message specification is versioned independently of IPython. | |
12 |
The current version of the specification is 5.0. |
|
12 | The current version of the specification is 5.0. | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | Introduction |
|
15 | Introduction | |
@@ -107,7 +107,7 b' A message is defined by the following four-dictionary structure::' | |||||
107 | # All recognized message type strings are listed below. |
|
107 | # All recognized message type strings are listed below. | |
108 | 'msg_type' : str, |
|
108 | 'msg_type' : str, | |
109 | # the message protocol version |
|
109 | # the message protocol version | |
110 |
'version' : '5.0 |
|
110 | 'version' : '5.0', | |
111 | }, |
|
111 | }, | |
112 |
|
112 | |||
113 | # In a chain of messages, the header from the parent is copied so that |
|
113 | # In a chain of messages, the header from the parent is copied so that | |
@@ -122,7 +122,7 b' A message is defined by the following four-dictionary structure::' | |||||
122 | 'content' : dict, |
|
122 | 'content' : dict, | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 |
.. versionchanged:: 5.0 |
|
125 | .. versionchanged:: 5.0 | |
126 |
|
126 | |||
127 | ``version`` key added to the header. |
|
127 | ``version`` key added to the header. | |
128 |
|
128 | |||
@@ -281,7 +281,7 b' Message type: ``execute_request``::' | |||||
281 | 'allow_stdin' : True, |
|
281 | 'allow_stdin' : True, | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 |
.. versionchanged:: 5.0 |
|
284 | .. versionchanged:: 5.0 | |
285 |
|
285 | |||
286 | ``user_variables`` removed, because it is redundant with user_expressions. |
|
286 | ``user_variables`` removed, because it is redundant with user_expressions. | |
287 |
|
287 | |||
@@ -366,7 +366,7 b" When status is 'ok', the following extra fields are present::" | |||||
366 | 'user_expressions' : dict, |
|
366 | 'user_expressions' : dict, | |
367 | } |
|
367 | } | |
368 |
|
368 | |||
369 |
.. versionchanged:: 5.0 |
|
369 | .. versionchanged:: 5.0 | |
370 |
|
370 | |||
371 | ``user_variables`` is removed, use user_expressions instead. |
|
371 | ``user_variables`` is removed, use user_expressions instead. | |
372 |
|
372 | |||
@@ -433,11 +433,11 b' Message type: ``inspect_request``::' | |||||
433 | 'detail_level' : 0 or 1, |
|
433 | 'detail_level' : 0 or 1, | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 |
.. versionchanged:: 5.0 |
|
436 | .. versionchanged:: 5.0 | |
437 |
|
437 | |||
438 | ``object_info_request`` renamed to ``inspect_request``. |
|
438 | ``object_info_request`` renamed to ``inspect_request``. | |
439 |
|
439 | |||
440 |
.. versionchanged:: 5.0 |
|
440 | .. versionchanged:: 5.0 | |
441 |
|
441 | |||
442 | ``name`` key replaced with ``code`` and ``cursor_pos``, |
|
442 | ``name`` key replaced with ``code`` and ``cursor_pos``, | |
443 | moving the lexing responsibility to the kernel. |
|
443 | moving the lexing responsibility to the kernel. | |
@@ -457,11 +457,11 b' Message type: ``inspect_reply``::' | |||||
457 | 'metadata' : dict, |
|
457 | 'metadata' : dict, | |
458 | } |
|
458 | } | |
459 |
|
459 | |||
460 |
.. versionchanged:: 5.0 |
|
460 | .. versionchanged:: 5.0 | |
461 |
|
461 | |||
462 | ``object_info_reply`` renamed to ``inspect_reply``. |
|
462 | ``object_info_reply`` renamed to ``inspect_reply``. | |
463 |
|
463 | |||
464 |
.. versionchanged:: 5.0 |
|
464 | .. versionchanged:: 5.0 | |
465 |
|
465 | |||
466 | Reply is changed from structured data to a mime bundle, allowing formatting decisions to be made by the kernel. |
|
466 | Reply is changed from structured data to a mime bundle, allowing formatting decisions to be made by the kernel. | |
467 |
|
467 | |||
@@ -480,7 +480,7 b' Message type: ``complete_request``::' | |||||
480 | 'cursor_pos' : int, |
|
480 | 'cursor_pos' : int, | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 |
.. versionchanged:: 5.0 |
|
483 | .. versionchanged:: 5.0 | |
484 |
|
484 | |||
485 | ``line``, ``block``, and ``text`` keys are removed in favor of a single ``code`` for context. |
|
485 | ``line``, ``block``, and ``text`` keys are removed in favor of a single ``code`` for context. | |
486 | Lexing is up to the kernel. |
|
486 | Lexing is up to the kernel. | |
@@ -507,7 +507,7 b' Message type: ``complete_reply``::' | |||||
507 | 'status' : 'ok' |
|
507 | 'status' : 'ok' | |
508 | } |
|
508 | } | |
509 |
|
509 | |||
510 |
.. versionchanged:: 5.0 |
|
510 | .. versionchanged:: 5.0 | |
511 |
|
511 | |||
512 | - ``matched_text`` is removed in favor of ``cursor_start`` and ``cursor_end``. |
|
512 | - ``matched_text`` is removed in favor of ``cursor_start`` and ``cursor_end``. | |
513 | - ``metadata`` is added for extended information. |
|
513 | - ``metadata`` is added for extended information. | |
@@ -638,15 +638,15 b' Message type: ``kernel_info_reply``::' | |||||
638 | 'banner' : str, |
|
638 | 'banner' : str, | |
639 | } |
|
639 | } | |
640 |
|
640 | |||
641 |
.. versionchanged:: 5.0 |
|
641 | .. versionchanged:: 5.0 | |
642 |
|
642 | |||
643 | Versions changed from lists of integers to strings. |
|
643 | Versions changed from lists of integers to strings. | |
644 |
|
644 | |||
645 |
.. versionchanged:: 5.0 |
|
645 | .. versionchanged:: 5.0 | |
646 |
|
646 | |||
647 | ``ipython_version`` is removed. |
|
647 | ``ipython_version`` is removed. | |
648 |
|
648 | |||
649 |
.. versionchanged:: 5.0 |
|
649 | .. versionchanged:: 5.0 | |
650 |
|
650 | |||
651 | ``implementation``, ``implementation_version``, and ``banner`` keys are added. |
|
651 | ``implementation``, ``implementation_version``, and ``banner`` keys are added. | |
652 |
|
652 | |||
@@ -760,7 +760,7 b' of images::' | |||||
760 | } |
|
760 | } | |
761 |
|
761 | |||
762 |
|
762 | |||
763 |
.. versionchanged:: 5.0 |
|
763 | .. versionchanged:: 5.0 | |
764 |
|
764 | |||
765 | `application/json` data should be unpacked JSON data, |
|
765 | `application/json` data should be unpacked JSON data, | |
766 | not double-serialized as a JSON string. |
|
766 | not double-serialized as a JSON string. | |
@@ -822,7 +822,7 b' Message type: ``execute_input``::' | |||||
822 | 'execution_count' : int |
|
822 | 'execution_count' : int | |
823 | } |
|
823 | } | |
824 |
|
824 | |||
825 |
.. versionchanged:: 5.0 |
|
825 | .. versionchanged:: 5.0 | |
826 |
|
826 | |||
827 | ``pyin`` is renamed to ``execute_input``. |
|
827 | ``pyin`` is renamed to ``execute_input``. | |
828 |
|
828 | |||
@@ -868,7 +868,7 b' Message type: ``error``::' | |||||
868 | # except the 'status' field is omitted. |
|
868 | # except the 'status' field is omitted. | |
869 | } |
|
869 | } | |
870 |
|
870 | |||
871 |
.. versionchanged:: 5.0 |
|
871 | .. versionchanged:: 5.0 | |
872 |
|
872 | |||
873 | ``pyerr`` renamed to ``error`` |
|
873 | ``pyerr`` renamed to ``error`` | |
874 |
|
874 | |||
@@ -937,7 +937,7 b' Message type: ``input_reply``::' | |||||
937 |
|
937 | |||
938 | When ``password`` is True, the frontend should not echo the input as it is entered. |
|
938 | When ``password`` is True, the frontend should not echo the input as it is entered. | |
939 |
|
939 | |||
940 |
.. versionchanged:: 5.0 |
|
940 | .. versionchanged:: 5.0 | |
941 |
|
941 | |||
942 | ``password`` key added. |
|
942 | ``password`` key added. | |
943 |
|
943 |
General Comments 0
You need to be logged in to leave comments.
Login now