Show More
@@ -12,6 +12,7 b'' | |||||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | # Standard library imports. |
|
14 | # Standard library imports. | |
|
15 | import abc | |||
15 | import Queue |
|
16 | import Queue | |
16 |
|
17 | |||
17 | # System library imports. |
|
18 | # System library imports. | |
@@ -21,6 +22,23 b' import zmq' | |||||
21 | from IPython.utils.traitlets import HasTraits, Instance, Int |
|
22 | from IPython.utils.traitlets import HasTraits, Instance, Int | |
22 |
|
23 | |||
23 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
|
25 | # Generic socket interface | |||
|
26 | #----------------------------------------------------------------------------- | |||
|
27 | ||||
|
28 | class SocketABC(object): | |||
|
29 | __metaclass__ = abc.ABCMeta | |||
|
30 | ||||
|
31 | @abc.abstractmethod | |||
|
32 | def recv_multipart(self, flags=0, copy=True, track=False): | |||
|
33 | raise NotImplementedError | |||
|
34 | ||||
|
35 | @abc.abstractmethod | |||
|
36 | def send_multipart(self, msg_parts, flags=0, copy=True, track=False): | |||
|
37 | raise NotImplementedError | |||
|
38 | ||||
|
39 | SocketABC.register(zmq.Socket) | |||
|
40 | ||||
|
41 | #----------------------------------------------------------------------------- | |||
24 | # Dummy socket class |
|
42 | # Dummy socket class | |
25 | #----------------------------------------------------------------------------- |
|
43 | #----------------------------------------------------------------------------- | |
26 |
|
44 | |||
@@ -31,7 +49,7 b' class DummySocket(HasTraits):' | |||||
31 | message_sent = Int(0) # Should be an Event |
|
49 | message_sent = Int(0) # Should be an Event | |
32 |
|
50 | |||
33 | #------------------------------------------------------------------------- |
|
51 | #------------------------------------------------------------------------- | |
34 |
# |
|
52 | # Socket interface | |
35 | #------------------------------------------------------------------------- |
|
53 | #------------------------------------------------------------------------- | |
36 |
|
54 | |||
37 | def recv_multipart(self, flags=0, copy=True, track=False): |
|
55 | def recv_multipart(self, flags=0, copy=True, track=False): | |
@@ -41,3 +59,5 b' class DummySocket(HasTraits):' | |||||
41 | msg_parts = map(zmq.Message, msg_parts) |
|
59 | msg_parts = map(zmq.Message, msg_parts) | |
42 | self.queue.put_nowait(msg_parts) |
|
60 | self.queue.put_nowait(msg_parts) | |
43 | self.message_sent += 1 |
|
61 | self.message_sent += 1 | |
|
62 | ||||
|
63 | SocketABC.register(DummySocket) |
@@ -13,10 +13,9 b'' | |||||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | from IPython.config import Configurable |
|
15 | from IPython.config import Configurable | |
16 |
|
16 | from IPython.embedded.socket import SocketABC | ||
17 | from IPython.utils.jsonutil import json_clean |
|
17 | from IPython.utils.jsonutil import json_clean | |
18 |
from IPython.utils.traitlets import |
|
18 | from IPython.utils.traitlets import Instance, Dict, CBytes | |
19 |
|
||||
20 | from IPython.zmq.serialize import serialize_object |
|
19 | from IPython.zmq.serialize import serialize_object | |
21 | from IPython.zmq.session import Session, extract_header |
|
20 | from IPython.zmq.session import Session, extract_header | |
22 |
|
21 | |||
@@ -29,7 +28,7 b' class ZMQDataPublisher(Configurable):' | |||||
29 |
|
28 | |||
30 | topic = topic = CBytes(b'datapub') |
|
29 | topic = topic = CBytes(b'datapub') | |
31 | session = Instance(Session) |
|
30 | session = Instance(Session) | |
32 |
pub_socket = |
|
31 | pub_socket = Instance(SocketABC) | |
33 | parent_header = Dict({}) |
|
32 | parent_header = Dict({}) | |
34 |
|
33 | |||
35 | def set_parent(self, parent): |
|
34 | def set_parent(self, parent): |
@@ -2,8 +2,9 b' import __builtin__' | |||||
2 | import sys |
|
2 | import sys | |
3 |
|
3 | |||
4 | from IPython.core.displayhook import DisplayHook |
|
4 | from IPython.core.displayhook import DisplayHook | |
|
5 | from IPython.embedded.socket import SocketABC | |||
5 | from IPython.utils.jsonutil import encode_images |
|
6 | from IPython.utils.jsonutil import encode_images | |
6 |
from IPython.utils.traitlets import |
|
7 | from IPython.utils.traitlets import Instance, Dict | |
7 | from session import extract_header, Session |
|
8 | from session import extract_header, Session | |
8 |
|
9 | |||
9 | class ZMQDisplayHook(object): |
|
10 | class ZMQDisplayHook(object): | |
@@ -37,7 +38,7 b' class ZMQShellDisplayHook(DisplayHook):' | |||||
37 | topic=None |
|
38 | topic=None | |
38 |
|
39 | |||
39 | session = Instance(Session) |
|
40 | session = Instance(Session) | |
40 |
pub_socket = |
|
41 | pub_socket = Instance(SocketABC) | |
41 | parent_header = Dict({}) |
|
42 | parent_header = Dict({}) | |
42 |
|
43 | |||
43 | def set_parent(self, parent): |
|
44 | def set_parent(self, parent): |
@@ -34,6 +34,7 b' from IPython.core.error import UsageError' | |||||
34 | from IPython.core.magics import MacroToEdit, CodeMagics |
|
34 | from IPython.core.magics import MacroToEdit, CodeMagics | |
35 | from IPython.core.magic import magics_class, line_magic, Magics |
|
35 | from IPython.core.magic import magics_class, line_magic, Magics | |
36 | from IPython.core.payloadpage import install_payload_page |
|
36 | from IPython.core.payloadpage import install_payload_page | |
|
37 | from IPython.embedded.socket import SocketABC | |||
37 | from IPython.lib.kernel import ( |
|
38 | from IPython.lib.kernel import ( | |
38 | get_connection_file, get_connection_info, connect_qtconsole |
|
39 | get_connection_file, get_connection_info, connect_qtconsole | |
39 | ) |
|
40 | ) | |
@@ -42,7 +43,7 b' from IPython.utils import io, openpy' | |||||
42 | from IPython.utils.jsonutil import json_clean, encode_images |
|
43 | from IPython.utils.jsonutil import json_clean, encode_images | |
43 | from IPython.utils.process import arg_split |
|
44 | from IPython.utils.process import arg_split | |
44 | from IPython.utils import py3compat |
|
45 | from IPython.utils import py3compat | |
45 |
from IPython.utils.traitlets import |
|
46 | from IPython.utils.traitlets import Instance, Type, Dict, CBool, CBytes | |
46 | from IPython.utils.warn import warn, error |
|
47 | from IPython.utils.warn import warn, error | |
47 | from IPython.zmq.displayhook import ZMQShellDisplayHook |
|
48 | from IPython.zmq.displayhook import ZMQShellDisplayHook | |
48 | from IPython.zmq.datapub import ZMQDataPublisher |
|
49 | from IPython.zmq.datapub import ZMQDataPublisher | |
@@ -57,7 +58,7 b' class ZMQDisplayPublisher(DisplayPublisher):' | |||||
57 | """A display publisher that publishes data using a ZeroMQ PUB socket.""" |
|
58 | """A display publisher that publishes data using a ZeroMQ PUB socket.""" | |
58 |
|
59 | |||
59 | session = Instance(Session) |
|
60 | session = Instance(Session) | |
60 |
pub_socket = |
|
61 | pub_socket = Instance(SocketABC) | |
61 | parent_header = Dict({}) |
|
62 | parent_header = Dict({}) | |
62 | topic = CBytes(b'displaypub') |
|
63 | topic = CBytes(b'displaypub') | |
63 |
|
64 |
General Comments 0
You need to be logged in to leave comments.
Login now