FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ipython/IPython/kernel/inprocess/socket.py at master · PhML/ipython · GitHub
PhML
ipython
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ipython
/
IPython
/
kernel
/
inprocess
/
socket.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (49 loc) · 2.26 KB
Breadcrumbs
ipython
/
IPython
/
kernel
/
inprocess
/
socket.py
Copy path
File metadata and controls
65 lines (49 loc) · 2.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
""" Defines a dummy socket implementing (part of) the zmq.Socket interface. """
#-----------------------------------------------------------------------------
# Copyright (C) 2012 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
#-----------------------------------------------------------------------------
# Standard library imports.
import
abc
try
:
from
queue
import
Queue
# Py 3
except
ImportError
:
from
Queue
import
Queue
# Py 2
# System library imports.
import
zmq
# Local imports.
from
IPython
.
utils
.
traitlets
import
HasTraits
,
Instance
,
Int
from
IPython
.
utils
.
py3compat
import
with_metaclass
#-----------------------------------------------------------------------------
# Generic socket interface
#-----------------------------------------------------------------------------
class
SocketABC
(
with_metaclass
(
abc
.
ABCMeta
,
object
)):
@
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
#-----------------------------------------------------------------------------
class
DummySocket
(
HasTraits
):
""" A dummy socket implementing (part of) the zmq.Socket interface. """
queue
=
Instance
(
Queue
, ())
message_sent
=
Int
(
0
)
# Should be an Event
#-------------------------------------------------------------------------
# Socket interface
#-------------------------------------------------------------------------
def
recv_multipart
(
self
,
flags
=
0
,
copy
=
True
,
track
=
False
):
return
self
.
queue
.
get_nowait
()
def
send_multipart
(
self
,
msg_parts
,
flags
=
0
,
copy
=
True
,
track
=
False
):
msg_parts
=
list
(
map
(
zmq
.
Message
,
msg_parts
))
self
.
queue
.
put_nowait
(
msg_parts
)
self
.
message_sent
+=
1
SocketABC
.
register
(
DummySocket
)
Back
|
FazBrowse Home
|
New Git URL