mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-05 12:19:58 +08:00
Merge pull request #5752 from minrk/msgspec-adapter
Add adapter for msg spec versions
This commit is contained in:
commit
2483e0a0e1
@ -1,20 +1,7 @@
|
||||
"""Tornado handlers for WebSocket <-> ZMQ sockets.
|
||||
"""Tornado handlers for WebSocket <-> ZMQ sockets."""
|
||||
|
||||
Authors:
|
||||
|
||||
* Brian Granger
|
||||
"""
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Copyright (C) 2008-2011 The IPython Development Team
|
||||
#
|
||||
# Distributed under the terms of the BSD License. The full license is in
|
||||
# the file COPYING, distributed as part of this software.
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Imports
|
||||
#-----------------------------------------------------------------------------
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
try:
|
||||
from urllib.parse import urlparse # Py 3
|
||||
@ -37,9 +24,6 @@ from IPython.utils.py3compat import PY3, cast_unicode
|
||||
|
||||
from .handlers import IPythonHandler
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# ZMQ handlers
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
class ZMQStreamHandler(websocket.WebSocketHandler):
|
||||
|
||||
|
@ -1,20 +1,7 @@
|
||||
"""Tornado handlers for the notebook.
|
||||
"""Tornado handlers for kernels."""
|
||||
|
||||
Authors:
|
||||
|
||||
* Brian Granger
|
||||
"""
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Copyright (C) 2008-2011 The IPython Development Team
|
||||
#
|
||||
# Distributed under the terms of the BSD License. The full license is in
|
||||
# the file COPYING, distributed as part of this software.
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Imports
|
||||
#-----------------------------------------------------------------------------
|
||||
# Copyright (c) IPython Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import logging
|
||||
from tornado import web
|
||||
@ -22,15 +9,13 @@ from tornado import web
|
||||
from zmq.utils import jsonapi
|
||||
|
||||
from IPython.utils.jsonutil import date_default
|
||||
from IPython.utils.py3compat import string_types
|
||||
from IPython.html.utils import url_path_join, url_escape
|
||||
|
||||
from ...base.handlers import IPythonHandler, json_errors
|
||||
from ...base.zmqhandlers import AuthenticatedZMQStreamHandler
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Kernel handlers
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
from IPython.core.release import kernel_protocol_version
|
||||
|
||||
class MainKernelHandler(IPythonHandler):
|
||||
|
||||
@ -96,6 +81,41 @@ class ZMQChannelHandler(AuthenticatedZMQStreamHandler):
|
||||
km = self.kernel_manager
|
||||
meth = getattr(km, 'connect_%s' % self.channel)
|
||||
self.zmq_stream = meth(self.kernel_id, identity=self.session.bsession)
|
||||
# Create a kernel_info channel to query the kernel protocol version.
|
||||
# This channel will be closed after the kernel_info reply is received.
|
||||
self.kernel_info_channel = None
|
||||
self.kernel_info_channel = km.connect_shell(self.kernel_id)
|
||||
self.kernel_info_channel.on_recv(self._handle_kernel_info_reply)
|
||||
self._request_kernel_info()
|
||||
|
||||
def _request_kernel_info(self):
|
||||
"""send a request for kernel_info"""
|
||||
self.log.debug("requesting kernel info")
|
||||
self.session.send(self.kernel_info_channel, "kernel_info_request")
|
||||
|
||||
def _handle_kernel_info_reply(self, msg):
|
||||
"""process the kernel_info_reply
|
||||
|
||||
enabling msg spec adaptation, if necessary
|
||||
"""
|
||||
idents,msg = self.session.feed_identities(msg)
|
||||
try:
|
||||
msg = self.session.unserialize(msg)
|
||||
except:
|
||||
self.log.error("Bad kernel_info reply", exc_info=True)
|
||||
self._request_kernel_info()
|
||||
return
|
||||
else:
|
||||
if msg['msg_type'] != 'kernel_info_reply' or 'protocol_version' not in msg['content']:
|
||||
self.log.error("Kernel info request failed, assuming current %s", msg['content'])
|
||||
else:
|
||||
protocol_version = msg['content']['protocol_version']
|
||||
if protocol_version != kernel_protocol_version:
|
||||
self.session.adapt_version = int(protocol_version.split('.')[0])
|
||||
self.log.info("adapting kernel to %s" % protocol_version)
|
||||
self.kernel_info_channel.close()
|
||||
self.kernel_info_channel = None
|
||||
|
||||
|
||||
def initialize(self, *args, **kwargs):
|
||||
self.zmq_stream = None
|
||||
|
@ -171,6 +171,15 @@ var IPython = (function (IPython) {
|
||||
var matches = content.matches;
|
||||
|
||||
var cur = this.editor.getCursor();
|
||||
if (end === null) {
|
||||
// adapted message spec replies don't have cursor position info,
|
||||
// interpret end=null as current position,
|
||||
// and negative start relative to that
|
||||
end = utils.to_absolute_cursor_pos(this.editor, cur);
|
||||
if (start < 0) {
|
||||
start = end + start;
|
||||
}
|
||||
}
|
||||
var results = CodeMirror.contextHint(this.editor);
|
||||
var filtered_results = [];
|
||||
//remove results from context completion
|
||||
|
Loading…
Reference in New Issue
Block a user