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