Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add abstract base class (ABC) for sockets used in kernel.

  • Loading branch information...
commit 40e9f497c4b067dadd1ce47c8b21805ddbb772e0 1 parent 8d53a55
Evan Patterson epatters authored
22 IPython/embedded/socket.py
View
@@ -12,6 +12,7 @@
#-----------------------------------------------------------------------------
# Standard library imports.
+import abc
import Queue
# System library imports.
@@ -21,6 +22,23 @@
from IPython.utils.traitlets import HasTraits, Instance, Int
#-----------------------------------------------------------------------------
+# Generic socket interface
+#-----------------------------------------------------------------------------
+
+class SocketABC(object):
+ __metaclass__ = abc.ABCMeta
+
+ @abc.abstractmethod
+ def recv_multipart(self, flags=0, copy=True, track=False):
+ raise NotImplementedError
+
+ @abc.abstractmethod
+ def send_multipart(self, msg_parts, flags=0, copy=True, track=False):
+ raise NotImplementedError
+
+SocketABC.register(zmq.Socket)
+
+#-----------------------------------------------------------------------------
# Dummy socket class
#-----------------------------------------------------------------------------
@@ -31,7 +49,7 @@ class DummySocket(HasTraits):
message_sent = Int(0) # Should be an Event
#-------------------------------------------------------------------------
- # zmq.Socket interface
+ # Socket interface
#-------------------------------------------------------------------------
def recv_multipart(self, flags=0, copy=True, track=False):
@@ -41,3 +59,5 @@ def send_multipart(self, msg_parts, flags=0, copy=True, track=False):
msg_parts = map(zmq.Message, msg_parts)
self.queue.put_nowait(msg_parts)
self.message_sent += 1
+
+SocketABC.register(DummySocket)
7 IPython/zmq/datapub.py
View
@@ -13,10 +13,9 @@
#-----------------------------------------------------------------------------
from IPython.config import Configurable
-
+from IPython.embedded.socket import SocketABC
from IPython.utils.jsonutil import json_clean
-from IPython.utils.traitlets import Any, Instance, Dict, CBytes
-
+from IPython.utils.traitlets import Instance, Dict, CBytes
from IPython.zmq.serialize import serialize_object
from IPython.zmq.session import Session, extract_header
@@ -29,7 +28,7 @@ class ZMQDataPublisher(Configurable):
topic = topic = CBytes(b'datapub')
session = Instance(Session)
- pub_socket = Any()
+ pub_socket = Instance(SocketABC)
parent_header = Dict({})
def set_parent(self, parent):
5 IPython/zmq/displayhook.py
View
@@ -2,8 +2,9 @@
import sys
from IPython.core.displayhook import DisplayHook
+from IPython.embedded.socket import SocketABC
from IPython.utils.jsonutil import encode_images
-from IPython.utils.traitlets import Any, Instance, Dict
+from IPython.utils.traitlets import Instance, Dict
from session import extract_header, Session
class ZMQDisplayHook(object):
@@ -37,7 +38,7 @@ class ZMQShellDisplayHook(DisplayHook):
topic=None
session = Instance(Session)
- pub_socket = Any()
+ pub_socket = Instance(SocketABC)
parent_header = Dict({})
def set_parent(self, parent):
5 IPython/zmq/zmqshell.py
View
@@ -34,6 +34,7 @@
from IPython.core.magics import MacroToEdit, CodeMagics
from IPython.core.magic import magics_class, line_magic, Magics
from IPython.core.payloadpage import install_payload_page
+from IPython.embedded.socket import SocketABC
from IPython.lib.kernel import (
get_connection_file, get_connection_info, connect_qtconsole
)
@@ -42,7 +43,7 @@
from IPython.utils.jsonutil import json_clean, encode_images
from IPython.utils.process import arg_split
from IPython.utils import py3compat
-from IPython.utils.traitlets import Any, Instance, Type, Dict, CBool, CBytes
+from IPython.utils.traitlets import Instance, Type, Dict, CBool, CBytes
from IPython.utils.warn import warn, error
from IPython.zmq.displayhook import ZMQShellDisplayHook
from IPython.zmq.datapub import ZMQDataPublisher
@@ -57,7 +58,7 @@ class ZMQDisplayPublisher(DisplayPublisher):
"""A display publisher that publishes data using a ZeroMQ PUB socket."""
session = Instance(Session)
- pub_socket = Any()
+ pub_socket = Instance(SocketABC)
parent_header = Dict({})
topic = CBytes(b'displaypub')
Please sign in to comment.
Something went wrong with that request. Please try again.