Show More
@@ -30,7 +30,7 b' from IPython.kernel.zmq.kernelapp import (' | |||||
30 | IPKernelApp |
|
30 | IPKernelApp | |
31 | ) |
|
31 | ) | |
32 | from IPython.kernel.zmq.pylab.config import InlineBackend |
|
32 | from IPython.kernel.zmq.pylab.config import InlineBackend | |
33 |
from IPython.kernel.zmq.session import Session |
|
33 | from IPython.kernel.zmq.session import Session | |
34 | from IPython.kernel.zmq.zmqshell import ZMQInteractiveShell |
|
34 | from IPython.kernel.zmq.zmqshell import ZMQInteractiveShell | |
35 | from IPython.kernel.connect import ConnectionFileMixin |
|
35 | from IPython.kernel.connect import ConnectionFileMixin | |
36 |
|
36 | |||
@@ -338,7 +338,6 b' class IPythonConsoleApp(ConnectionFileMixin):' | |||||
338 | IPythonConsoleApp.initialize(self,argv) |
|
338 | IPythonConsoleApp.initialize(self,argv) | |
339 | """ |
|
339 | """ | |
340 | self.init_connection_file() |
|
340 | self.init_connection_file() | |
341 | default_secure(self.config) |
|
|||
342 | self.init_ssh() |
|
341 | self.init_ssh() | |
343 | self.init_kernel_manager() |
|
342 | self.init_kernel_manager() | |
344 | self.init_kernel_client() |
|
343 | self.init_kernel_client() |
@@ -77,7 +77,7 b' from IPython.core.application import (' | |||||
77 | from IPython.core.profiledir import ProfileDir |
|
77 | from IPython.core.profiledir import ProfileDir | |
78 | from IPython.kernel import KernelManager |
|
78 | from IPython.kernel import KernelManager | |
79 | from IPython.kernel.kernelspec import KernelSpecManager |
|
79 | from IPython.kernel.kernelspec import KernelSpecManager | |
80 |
from IPython.kernel.zmq.session import |
|
80 | from IPython.kernel.zmq.session import Session | |
81 | from IPython.nbformat.sign import NotebookNotary |
|
81 | from IPython.nbformat.sign import NotebookNotary | |
82 | from IPython.utils.importstring import import_item |
|
82 | from IPython.utils.importstring import import_item | |
83 | from IPython.utils import submodule |
|
83 | from IPython.utils import submodule | |
@@ -764,9 +764,6 b' class NotebookApp(BaseIPythonApplication):' | |||||
764 | self.ipython_kernel_argv = ["--profile-dir", self.profile_dir.location] |
|
764 | self.ipython_kernel_argv = ["--profile-dir", self.profile_dir.location] | |
765 |
|
765 | |||
766 | def init_configurables(self): |
|
766 | def init_configurables(self): | |
767 | # force Session default to be secure |
|
|||
768 | default_secure(self.config) |
|
|||
769 |
|
||||
770 | self.kernel_spec_manager = self.kernel_spec_manager_class( |
|
767 | self.kernel_spec_manager = self.kernel_spec_manager_class( | |
771 | parent=self, |
|
768 | parent=self, | |
772 | ipython_dir=self.ipython_dir, |
|
769 | ipython_dir=self.ipython_dir, |
@@ -179,6 +179,8 b' class ZMQChannelsHandler(AuthenticatedZMQStreamHandler):' | |||||
179 | # then request kernel info, waiting up to a certain time before giving up. |
|
179 | # then request kernel info, waiting up to a certain time before giving up. | |
180 | # We don't want to wait forever, because browsers don't take it well when |
|
180 | # We don't want to wait forever, because browsers don't take it well when | |
181 | # servers never respond to websocket connection requests. |
|
181 | # servers never respond to websocket connection requests. | |
|
182 | kernel = self.kernel_manager.get_kernel(self.kernel_id) | |||
|
183 | self.session.key = kernel.session.key | |||
182 | future = self.request_kernel_info() |
|
184 | future = self.request_kernel_info() | |
183 |
|
185 | |||
184 | def give_up(): |
|
186 | def give_up(): |
@@ -124,7 +124,7 b' class InProcessKernel(IPythonKernel):' | |||||
124 |
|
124 | |||
125 | def _session_default(self): |
|
125 | def _session_default(self): | |
126 | from IPython.kernel.zmq.session import Session |
|
126 | from IPython.kernel.zmq.session import Session | |
127 | return Session(parent=self) |
|
127 | return Session(parent=self, key=b'') | |
128 |
|
128 | |||
129 | def _shell_class_default(self): |
|
129 | def _shell_class_default(self): | |
130 | return InProcessInteractiveShell |
|
130 | return InProcessInteractiveShell |
@@ -1,23 +1,13 b'' | |||||
1 | """A kernel manager for in-process kernels.""" |
|
1 | """A kernel manager for in-process kernels.""" | |
2 |
|
2 | |||
3 | #----------------------------------------------------------------------------- |
|
3 | # Copyright (c) IPython Development Team. | |
4 | # Copyright (C) 2013 The IPython Development Team |
|
4 | # Distributed under the terms of the Modified BSD License. | |
5 | # |
|
|||
6 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
7 | # the file COPYING, distributed as part of this software. |
|
|||
8 | #----------------------------------------------------------------------------- |
|
|||
9 |
|
||||
10 | #----------------------------------------------------------------------------- |
|
|||
11 | # Imports |
|
|||
12 | #----------------------------------------------------------------------------- |
|
|||
13 |
|
5 | |||
14 | from IPython.utils.traitlets import Instance, DottedObjectName |
|
6 | from IPython.utils.traitlets import Instance, DottedObjectName | |
15 | from IPython.kernel.managerabc import KernelManagerABC |
|
7 | from IPython.kernel.managerabc import KernelManagerABC | |
16 | from IPython.kernel.manager import KernelManager |
|
8 | from IPython.kernel.manager import KernelManager | |
|
9 | from IPython.kernel.zmq.session import Session | |||
17 |
|
10 | |||
18 | #----------------------------------------------------------------------------- |
|
|||
19 | # Main kernel manager class |
|
|||
20 | #----------------------------------------------------------------------------- |
|
|||
21 |
|
11 | |||
22 | class InProcessKernelManager(KernelManager): |
|
12 | class InProcessKernelManager(KernelManager): | |
23 | """A manager for an in-process kernel. |
|
13 | """A manager for an in-process kernel. | |
@@ -33,14 +23,18 b' class InProcessKernelManager(KernelManager):' | |||||
33 | kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel') |
|
23 | kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel') | |
34 | # the client class for KM.client() shortcut |
|
24 | # the client class for KM.client() shortcut | |
35 | client_class = DottedObjectName('IPython.kernel.inprocess.BlockingInProcessKernelClient') |
|
25 | client_class = DottedObjectName('IPython.kernel.inprocess.BlockingInProcessKernelClient') | |
36 |
|
26 | |||
|
27 | def _session_default(self): | |||
|
28 | # don't sign in-process messages | |||
|
29 | return Session(key=b'', parent=self) | |||
|
30 | ||||
37 | #-------------------------------------------------------------------------- |
|
31 | #-------------------------------------------------------------------------- | |
38 | # Kernel management methods |
|
32 | # Kernel management methods | |
39 | #-------------------------------------------------------------------------- |
|
33 | #-------------------------------------------------------------------------- | |
40 |
|
34 | |||
41 | def start_kernel(self, **kwds): |
|
35 | def start_kernel(self, **kwds): | |
42 | from IPython.kernel.inprocess.ipkernel import InProcessKernel |
|
36 | from IPython.kernel.inprocess.ipkernel import InProcessKernel | |
43 | self.kernel = InProcessKernel() |
|
37 | self.kernel = InProcessKernel(parent=self, session=self.session) | |
44 |
|
38 | |||
45 | def shutdown_kernel(self): |
|
39 | def shutdown_kernel(self): | |
46 | self._kill_kernel() |
|
40 | self._kill_kernel() |
@@ -25,7 +25,7 b' class InProcessKernelTestCase(unittest.TestCase):' | |||||
25 | def setUp(self): |
|
25 | def setUp(self): | |
26 | self.km = InProcessKernelManager() |
|
26 | self.km = InProcessKernelManager() | |
27 | self.km.start_kernel() |
|
27 | self.km.start_kernel() | |
28 | self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel) |
|
28 | self.kc = self.km.client() | |
29 | self.kc.start_channels() |
|
29 | self.kc.start_channels() | |
30 | self.kc.wait_for_ready() |
|
30 | self.kc.wait_for_ready() | |
31 |
|
31 | |||
@@ -61,7 +61,7 b' class InProcessKernelTestCase(unittest.TestCase):' | |||||
61 | kernel.shell.run_cell('print("foo")') |
|
61 | kernel.shell.run_cell('print("foo")') | |
62 | self.assertEqual(io.stdout, 'foo\n') |
|
62 | self.assertEqual(io.stdout, 'foo\n') | |
63 |
|
63 | |||
64 | kc = BlockingInProcessKernelClient(kernel=kernel) |
|
64 | kc = BlockingInProcessKernelClient(kernel=kernel, session=kernel.session) | |
65 | kernel.frontends.append(kc) |
|
65 | kernel.frontends.append(kc) | |
66 | kc.execute('print("bar")') |
|
66 | kc.execute('print("bar")') | |
67 | out, err = assemble_output(kc.iopub_channel) |
|
67 | out, err = assemble_output(kc.iopub_channel) |
@@ -24,7 +24,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
24 | self.assert_(km.has_kernel) |
|
24 | self.assert_(km.has_kernel) | |
25 | self.assert_(km.kernel is not None) |
|
25 | self.assert_(km.kernel is not None) | |
26 |
|
26 | |||
27 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
27 | kc = km.client() | |
28 | self.assert_(not kc.channels_running) |
|
28 | self.assert_(not kc.channels_running) | |
29 |
|
29 | |||
30 | kc.start_channels() |
|
30 | kc.start_channels() | |
@@ -49,7 +49,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
49 | """ |
|
49 | """ | |
50 | km = InProcessKernelManager() |
|
50 | km = InProcessKernelManager() | |
51 | km.start_kernel() |
|
51 | km.start_kernel() | |
52 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
52 | kc = km.client() | |
53 | kc.start_channels() |
|
53 | kc.start_channels() | |
54 | kc.wait_for_ready() |
|
54 | kc.wait_for_ready() | |
55 | kc.execute('foo = 1') |
|
55 | kc.execute('foo = 1') | |
@@ -60,7 +60,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
60 | """ |
|
60 | """ | |
61 | km = InProcessKernelManager() |
|
61 | km = InProcessKernelManager() | |
62 | km.start_kernel() |
|
62 | km.start_kernel() | |
63 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
63 | kc = km.client() | |
64 | kc.start_channels() |
|
64 | kc.start_channels() | |
65 | kc.wait_for_ready() |
|
65 | kc.wait_for_ready() | |
66 | km.kernel.shell.push({'my_bar': 0, 'my_baz': 1}) |
|
66 | km.kernel.shell.push({'my_bar': 0, 'my_baz': 1}) | |
@@ -75,7 +75,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
75 | """ |
|
75 | """ | |
76 | km = InProcessKernelManager() |
|
76 | km = InProcessKernelManager() | |
77 | km.start_kernel() |
|
77 | km.start_kernel() | |
78 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
78 | kc = km.client() | |
79 | kc.start_channels() |
|
79 | kc.start_channels() | |
80 | kc.wait_for_ready() |
|
80 | kc.wait_for_ready() | |
81 | km.kernel.shell.user_ns['foo'] = 1 |
|
81 | km.kernel.shell.user_ns['foo'] = 1 | |
@@ -92,7 +92,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
92 | """ |
|
92 | """ | |
93 | km = InProcessKernelManager() |
|
93 | km = InProcessKernelManager() | |
94 | km.start_kernel() |
|
94 | km.start_kernel() | |
95 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
95 | kc = km.client() | |
96 | kc.start_channels() |
|
96 | kc.start_channels() | |
97 | kc.wait_for_ready() |
|
97 | kc.wait_for_ready() | |
98 | kc.execute('%who') |
|
98 | kc.execute('%who') |
@@ -36,7 +36,7 b' from .heartbeat import Heartbeat' | |||||
36 | from .ipkernel import IPythonKernel |
|
36 | from .ipkernel import IPythonKernel | |
37 | from .parentpoller import ParentPollerUnix, ParentPollerWindows |
|
37 | from .parentpoller import ParentPollerUnix, ParentPollerWindows | |
38 | from .session import ( |
|
38 | from .session import ( | |
39 |
Session, session_flags, session_aliases, |
|
39 | Session, session_flags, session_aliases, | |
40 | ) |
|
40 | ) | |
41 | from .zmqshell import ZMQInteractiveShell |
|
41 | from .zmqshell import ZMQInteractiveShell | |
42 |
|
42 | |||
@@ -342,7 +342,6 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp,' | |||||
342 | @catch_config_error |
|
342 | @catch_config_error | |
343 | def initialize(self, argv=None): |
|
343 | def initialize(self, argv=None): | |
344 | super(IPKernelApp, self).initialize(argv) |
|
344 | super(IPKernelApp, self).initialize(argv) | |
345 | default_secure(self.config) |
|
|||
346 | self.init_blackhole() |
|
345 | self.init_blackhole() | |
347 | self.init_connection_file() |
|
346 | self.init_connection_file() | |
348 | self.init_poller() |
|
347 | self.init_poller() |
@@ -122,7 +122,7 b' def default_secure(cfg):' | |||||
122 | If Session.key/keyfile have not been set, set Session.key to |
|
122 | If Session.key/keyfile have not been set, set Session.key to | |
123 | a new random UUID. |
|
123 | a new random UUID. | |
124 | """ |
|
124 | """ | |
125 |
|
125 | warnings.warn("default_secure is deprecated", DeprecationWarning) | ||
126 | if 'Session' in cfg: |
|
126 | if 'Session' in cfg: | |
127 | if 'key' in cfg.Session or 'keyfile' in cfg.Session: |
|
127 | if 'key' in cfg.Session or 'keyfile' in cfg.Session: | |
128 | return |
|
128 | return | |
@@ -315,8 +315,11 b' class Session(Configurable):' | |||||
315 |
|
315 | |||
316 | # message signature related traits: |
|
316 | # message signature related traits: | |
317 |
|
317 | |||
318 |
key = CBytes( |
|
318 | key = CBytes(config=True, | |
319 |
help="""execution key, for |
|
319 | help="""execution key, for signing messages.""") | |
|
320 | def _key_default(self): | |||
|
321 | return str_to_bytes(str(uuid.uuid4())) | |||
|
322 | ||||
320 | def _key_changed(self): |
|
323 | def _key_changed(self): | |
321 | self._new_auth() |
|
324 | self._new_auth() | |
322 |
|
325 | |||
@@ -433,6 +436,7 b' class Session(Configurable):' | |||||
433 | # ensure self._session_default() if necessary, so bsession is defined: |
|
436 | # ensure self._session_default() if necessary, so bsession is defined: | |
434 | self.session |
|
437 | self.session | |
435 | self.pid = os.getpid() |
|
438 | self.pid = os.getpid() | |
|
439 | self._new_auth() | |||
436 |
|
440 | |||
437 | @property |
|
441 | @property | |
438 | def msg_id(self): |
|
442 | def msg_id(self): |
@@ -1,16 +1,9 b'' | |||||
1 |
"""test building messages with |
|
1 | """test building messages with Session""" | |
2 |
|
2 | |||
3 | #------------------------------------------------------------------------------- |
|
3 | # Copyright (c) IPython Development Team. | |
4 | # Copyright (C) 2011 The IPython Development Team |
|
4 | # Distributed under the terms of the Modified BSD License. | |
5 | # |
|
|||
6 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
7 | # the file COPYING, distributed as part of this software. |
|
|||
8 | #------------------------------------------------------------------------------- |
|
|||
9 |
|
||||
10 | #------------------------------------------------------------------------------- |
|
|||
11 | # Imports |
|
|||
12 | #------------------------------------------------------------------------------- |
|
|||
13 |
|
5 | |||
|
6 | import hmac | |||
14 | import os |
|
7 | import os | |
15 | import uuid |
|
8 | import uuid | |
16 | from datetime import datetime |
|
9 | from datetime import datetime | |
@@ -71,6 +64,10 b' class TestSession(SessionTestCase):' | |||||
71 | # ensure floats don't come out as Decimal: |
|
64 | # ensure floats don't come out as Decimal: | |
72 | self.assertEqual(type(new_msg['content']['b']),type(new_msg['content']['b'])) |
|
65 | self.assertEqual(type(new_msg['content']['b']),type(new_msg['content']['b'])) | |
73 |
|
66 | |||
|
67 | def test_default_secure(self): | |||
|
68 | self.assertIsInstance(self.session.key, bytes) | |||
|
69 | self.assertIsInstance(self.session.auth, hmac.HMAC) | |||
|
70 | ||||
74 | def test_send(self): |
|
71 | def test_send(self): | |
75 | ctx = zmq.Context.instance() |
|
72 | ctx = zmq.Context.instance() | |
76 | A = ctx.socket(zmq.PAIR) |
|
73 | A = ctx.socket(zmq.PAIR) | |
@@ -91,9 +88,10 b' class TestSession(SessionTestCase):' | |||||
91 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
88 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) | |
92 | self.assertEqual(new_msg['metadata'],msg['metadata']) |
|
89 | self.assertEqual(new_msg['metadata'],msg['metadata']) | |
93 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
90 | self.assertEqual(new_msg['buffers'],[b'bar']) | |
94 |
|
91 | |||
95 | content = msg['content'] |
|
92 | content = msg['content'] | |
96 | header = msg['header'] |
|
93 | header = msg['header'] | |
|
94 | header['date'] = datetime.now() | |||
97 | parent = msg['parent_header'] |
|
95 | parent = msg['parent_header'] | |
98 | metadata = msg['metadata'] |
|
96 | metadata = msg['metadata'] | |
99 | msg_type = header['msg_type'] |
|
97 | msg_type = header['msg_type'] | |
@@ -109,7 +107,9 b' class TestSession(SessionTestCase):' | |||||
109 | self.assertEqual(new_msg['metadata'],msg['metadata']) |
|
107 | self.assertEqual(new_msg['metadata'],msg['metadata']) | |
110 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
108 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) | |
111 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
109 | self.assertEqual(new_msg['buffers'],[b'bar']) | |
112 |
|
110 | |||
|
111 | header['date'] = datetime.now() | |||
|
112 | ||||
113 | self.session.send(A, msg, ident=b'foo', buffers=[b'bar']) |
|
113 | self.session.send(A, msg, ident=b'foo', buffers=[b'bar']) | |
114 | ident, new_msg = self.session.recv(B) |
|
114 | ident, new_msg = self.session.recv(B) | |
115 | self.assertEqual(ident[0], b'foo') |
|
115 | self.assertEqual(ident[0], b'foo') |
@@ -48,7 +48,7 b' from IPython.utils.localinterfaces import localhost, public_ips' | |||||
48 | from IPython.utils.traitlets import Instance, Unicode, Bool, List, Dict, TraitError |
|
48 | from IPython.utils.traitlets import Instance, Unicode, Bool, List, Dict, TraitError | |
49 |
|
49 | |||
50 | from IPython.kernel.zmq.session import ( |
|
50 | from IPython.kernel.zmq.session import ( | |
51 |
Session, session_aliases, session_flags, |
|
51 | Session, session_aliases, session_flags, | |
52 | ) |
|
52 | ) | |
53 |
|
53 | |||
54 | from IPython.parallel.controller.heartmonitor import HeartMonitor |
|
54 | from IPython.parallel.controller.heartmonitor import HeartMonitor | |
@@ -314,8 +314,6 b' class IPControllerApp(BaseParallelApplication):' | |||||
314 | # no need to wite back the same file |
|
314 | # no need to wite back the same file | |
315 | self.write_connection_files = False |
|
315 | self.write_connection_files = False | |
316 |
|
316 | |||
317 | # switch Session.key default to secure |
|
|||
318 | default_secure(self.config) |
|
|||
319 | self.log.debug("Config changed") |
|
317 | self.log.debug("Config changed") | |
320 | self.log.debug(repr(self.config)) |
|
318 | self.log.debug(repr(self.config)) | |
321 |
|
319 |
General Comments 0
You need to be logged in to leave comments.
Login now