summaryrefslogtreecommitdiff
path: root/gr-zeromq
diff options
context:
space:
mode:
authorDouglas Anderson <danderson@ntia.doc.gov>2017-02-12 15:52:19 -0800
committerJohnathan Corgan <johnathan@corganlabs.com>2017-02-26 18:21:22 -0800
commit9e625c4821f4c63421b3d3747c0c4f358fef6c5f (patch)
tree41dedbe053417be7314cdce15d64fbbb89db4d8d /gr-zeromq
parente5aabcc6a4a9335f3ef8abf5f89104b626e9364d (diff)
python3: update non-GRC components to use python2 or python3
Diffstat (limited to 'gr-zeromq')
-rw-r--r--[-rwxr-xr-x]gr-zeromq/examples/python/client.py10
-rw-r--r--[-rwxr-xr-x]gr-zeromq/examples/python/gui.py3
-rw-r--r--[-rwxr-xr-x]gr-zeromq/examples/python/server.py10
-rw-r--r--gr-zeromq/python/zeromq/CMakeLists.txt2
-rw-r--r--gr-zeromq/python/zeromq/__init__.py10
-rw-r--r--gr-zeromq/python/zeromq/probe_manager.py6
-rw-r--r--[-rwxr-xr-x]gr-zeromq/python/zeromq/qa_zeromq_pub.py3
-rw-r--r--[-rwxr-xr-x]gr-zeromq/python/zeromq/qa_zeromq_pubsub.py3
-rw-r--r--[-rwxr-xr-x]gr-zeromq/python/zeromq/qa_zeromq_pushpull.py3
-rw-r--r--[-rwxr-xr-x]gr-zeromq/python/zeromq/qa_zeromq_reqrep.py3
-rw-r--r--gr-zeromq/python/zeromq/rpc_manager.py23
11 files changed, 45 insertions, 31 deletions
diff --git a/gr-zeromq/examples/python/client.py b/gr-zeromq/examples/python/client.py
index ca7ad1830a..39055bd3fb 100755..100644
--- a/gr-zeromq/examples/python/client.py
+++ b/gr-zeromq/examples/python/client.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+from __future__ import unicode_literals
#
# Copyright 2013 Free Software Foundation, Inc.
#
@@ -67,14 +69,14 @@ class top_block(gr.top_block):
self.rpc_manager.start_watcher()
def start_fg(self):
- print "Start Flowgraph"
+ print("Start Flowgraph")
try:
self.start()
except RuntimeError:
- print "Can't start, flowgraph already running!"
+ print("Can't start, flowgraph already running!")
def stop_fg(self):
- print "Stop Flowgraph"
+ print("Stop Flowgraph")
self.stop()
self.wait()
@@ -110,7 +112,7 @@ if __name__ == "__main__":
time.sleep(1)
except KeyboardInterrupt:
pass
- print "Shutting down flowgraph."
+ print("Shutting down flowgraph.")
tb.rpc_manager.stop_watcher()
tb.stop()
tb.wait()
diff --git a/gr-zeromq/examples/python/gui.py b/gr-zeromq/examples/python/gui.py
index c932549408..832392f0a2 100755..100644
--- a/gr-zeromq/examples/python/gui.py
+++ b/gr-zeromq/examples/python/gui.py
@@ -1,3 +1,4 @@
+from __future__ import unicode_literals
#
# Copyright 2013 Free Software Foundation, Inc.
#
@@ -112,7 +113,7 @@ class gui(QtGui.QMainWindow):
# plot the data from the queues
def plot_data(self, plot, samples):
- self.x = range(0,len(samples),1)
+ self.x = list(range(0,len(samples),1))
self.y = samples
# clear the previous points from the plot
plot.clear()
diff --git a/gr-zeromq/examples/python/server.py b/gr-zeromq/examples/python/server.py
index 23951664c1..b2cd8e8ef2 100755..100644
--- a/gr-zeromq/examples/python/server.py
+++ b/gr-zeromq/examples/python/server.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+from __future__ import unicode_literals
#
# Copyright 2013 Free Software Foundation, Inc.
#
@@ -78,14 +80,14 @@ class top_block(gr.top_block):
self.rpc_manager.start_watcher()
def start_fg(self):
- print "Start Flowgraph"
+ print("Start Flowgraph")
try:
self.start()
except RuntimeError:
- print "Can't start, flowgraph already running!"
+ print("Can't start, flowgraph already running!")
def stop_fg(self):
- print "Stop Flowgraph"
+ print("Stop Flowgraph")
self.stop()
self.wait()
@@ -119,7 +121,7 @@ if __name__ == "__main__":
time.sleep(1)
except KeyboardInterrupt:
pass
- print "Shutting down flowgraph."
+ print("Shutting down flowgraph.")
tb.rpc_manager.stop_watcher()
tb.stop()
tb.wait()
diff --git a/gr-zeromq/python/zeromq/CMakeLists.txt b/gr-zeromq/python/zeromq/CMakeLists.txt
index 66fc65a4b5..100d1028fe 100644
--- a/gr-zeromq/python/zeromq/CMakeLists.txt
+++ b/gr-zeromq/python/zeromq/CMakeLists.txt
@@ -51,6 +51,6 @@ if(ENABLE_TESTING)
file(GLOB py_qa_test_files "qa_*.py")
foreach(py_qa_test_file ${py_qa_test_files})
get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE)
- GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file})
+ GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file})
endforeach(py_qa_test_file)
endif(ENABLE_TESTING)
diff --git a/gr-zeromq/python/zeromq/__init__.py b/gr-zeromq/python/zeromq/__init__.py
index cab4b67640..3b3e3869bd 100644
--- a/gr-zeromq/python/zeromq/__init__.py
+++ b/gr-zeromq/python/zeromq/__init__.py
@@ -22,15 +22,17 @@
'''
Blocks for interfacing with ZeroMQ endpoints.
'''
+from __future__ import absolute_import
+from __future__ import unicode_literals
import os
try:
- from zeromq_swig import *
+ from .zeromq_swig import *
except ImportError:
dirname, filename = os.path.split(os.path.abspath(__file__))
__path__.append(os.path.join(dirname, "..", "..", "swig"))
- from zeromq_swig import *
+ from .zeromq_swig import *
-from probe_manager import probe_manager
-from rpc_manager import rpc_manager
+from .probe_manager import probe_manager
+from .rpc_manager import rpc_manager
diff --git a/gr-zeromq/python/zeromq/probe_manager.py b/gr-zeromq/python/zeromq/probe_manager.py
index c30e6eaaba..b59650cd7b 100644
--- a/gr-zeromq/python/zeromq/probe_manager.py
+++ b/gr-zeromq/python/zeromq/probe_manager.py
@@ -1,3 +1,4 @@
+from __future__ import unicode_literals
#
# Copyright 2013 Free Software Foundation, Inc.
#
@@ -20,10 +21,9 @@
#
import zmq
-import threading
import numpy
-class probe_manager():
+class probe_manager(object):
def __init__(self):
self.zmq_context = zmq.Context()
self.poller = zmq.Poller()
@@ -31,7 +31,7 @@ class probe_manager():
def add_socket(self, address, data_type, callback_func):
socket = self.zmq_context.socket(zmq.SUB)
- socket.setsockopt(zmq.SUBSCRIBE, "")
+ socket.setsockopt(zmq.SUBSCRIBE, b"")
socket.connect(address)
# use a tuple to store interface elements
self.interfaces.append((socket, data_type, callback_func))
diff --git a/gr-zeromq/python/zeromq/qa_zeromq_pub.py b/gr-zeromq/python/zeromq/qa_zeromq_pub.py
index 6f08aa544f..1bf3263747 100755..100644
--- a/gr-zeromq/python/zeromq/qa_zeromq_pub.py
+++ b/gr-zeromq/python/zeromq/qa_zeromq_pub.py
@@ -21,6 +21,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest
from gnuradio import blocks, zeromq
from gnuradio import eng_notation
@@ -36,7 +37,7 @@ class qa_zeromq_pub (gr_unittest.TestCase):
def test_001 (self):
vlen = 10
self.rx_data = None
- src_data = range(vlen)*100
+ src_data = list(range(vlen))*100
src = blocks.vector_source_f(src_data, False, vlen)
zeromq_pub_sink = zeromq.pub_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:5555")
self.tb.connect(src, zeromq_pub_sink)
diff --git a/gr-zeromq/python/zeromq/qa_zeromq_pubsub.py b/gr-zeromq/python/zeromq/qa_zeromq_pubsub.py
index 2902f9e1dc..fe28b11caf 100755..100644
--- a/gr-zeromq/python/zeromq/qa_zeromq_pubsub.py
+++ b/gr-zeromq/python/zeromq/qa_zeromq_pubsub.py
@@ -21,6 +21,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest
from gnuradio import blocks, zeromq
import time
@@ -35,7 +36,7 @@ class qa_zeromq_pubsub (gr_unittest.TestCase):
def test_001 (self):
vlen = 10
- src_data = range(vlen)*100
+ src_data = list(range(vlen))*100
src = blocks.vector_source_f(src_data, False, vlen)
zeromq_pub_sink = zeromq.pub_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:5556", 0)
zeromq_sub_source = zeromq.sub_source(gr.sizeof_float, vlen, "tcp://127.0.0.1:5556", 0)
diff --git a/gr-zeromq/python/zeromq/qa_zeromq_pushpull.py b/gr-zeromq/python/zeromq/qa_zeromq_pushpull.py
index d09b92c130..8ecd531988 100755..100644
--- a/gr-zeromq/python/zeromq/qa_zeromq_pushpull.py
+++ b/gr-zeromq/python/zeromq/qa_zeromq_pushpull.py
@@ -20,6 +20,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest, blocks, zeromq
import time
@@ -33,7 +34,7 @@ class qa_zeromq_pushpull (gr_unittest.TestCase):
def test_001 (self):
vlen = 10
- src_data = range(vlen)*100
+ src_data = list(range(vlen))*100
src = blocks.vector_source_f(src_data, False, vlen)
zeromq_push_sink = zeromq.push_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:5557")
zeromq_pull_source = zeromq.pull_source(gr.sizeof_float, vlen, "tcp://127.0.0.1:5557", 0)
diff --git a/gr-zeromq/python/zeromq/qa_zeromq_reqrep.py b/gr-zeromq/python/zeromq/qa_zeromq_reqrep.py
index a50e684ea8..664e156528 100755..100644
--- a/gr-zeromq/python/zeromq/qa_zeromq_reqrep.py
+++ b/gr-zeromq/python/zeromq/qa_zeromq_reqrep.py
@@ -21,6 +21,7 @@
# Boston, MA 02110-1301, USA.
#
+
from gnuradio import gr, gr_unittest
from gnuradio import blocks, zeromq
from gnuradio import eng_notation
@@ -36,7 +37,7 @@ class qa_zeromq_reqrep (gr_unittest.TestCase):
def test_001 (self):
vlen = 10
- src_data = range(vlen)*100
+ src_data = list(range(vlen))*100
src = blocks.vector_source_f(src_data, False, vlen)
zeromq_rep_sink = zeromq.rep_sink(gr.sizeof_float, vlen, "tcp://127.0.0.1:5558", 0)
zeromq_req_source = zeromq.req_source(gr.sizeof_float, vlen, "tcp://127.0.0.1:5558", 0)
diff --git a/gr-zeromq/python/zeromq/rpc_manager.py b/gr-zeromq/python/zeromq/rpc_manager.py
index 2dce997bd4..f7c972b752 100644
--- a/gr-zeromq/python/zeromq/rpc_manager.py
+++ b/gr-zeromq/python/zeromq/rpc_manager.py
@@ -19,12 +19,15 @@
# Boston, MA 02110-1301, USA.
#
+from __future__ import print_function
+from __future__ import unicode_literals
+
import zmq
import pmt
import threading
-class rpc_manager():
+class rpc_manager(object):
def __init__(self):
self.zmq_context = zmq.Context()
self.poller_rep = zmq.Poller()
@@ -39,22 +42,22 @@ class rpc_manager():
def set_reply_socket(self, address):
self.rep_socket = self.zmq_context.socket(zmq.REP)
self.rep_socket.bind(address)
- print "[RPC] reply socket bound to: ", address
+ print("[RPC] reply socket bound to: ", address)
self.poller_rep.register(self.rep_socket, zmq.POLLIN)
def set_request_socket(self, address):
self.req_socket = self.zmq_context.socket(zmq.REQ)
self.req_socket.connect(address)
- print "[RPC] request socket connected to: ", address
+ print("[RPC] request socket connected to: ", address)
self.poller_req_out.register(self.req_socket, zmq.POLLOUT)
self.poller_req_in.register(self.req_socket, zmq.POLLIN)
def add_interface(self, id_str, callback_func):
- if not self.interfaces.has_key(id_str):
+ if id_str not in self.interfaces:
self.interfaces[id_str] = callback_func
- print "[RPC] added reply interface:", id_str
+ print("[RPC] added reply interface:", id_str)
else:
- print "[RPC] ERROR: duplicate id_str:", id_str
+ print("[RPC] ERROR: duplicate id_str:", id_str)
def watcher(self):
self.keep_running = True
@@ -65,7 +68,7 @@ class rpc_manager():
# receive call
msg = self.rep_socket.recv()
(id_str, args) = pmt.to_python(pmt.deserialize_str(msg))
- print "[RPC] request:", id_str, ", args:", args
+ print("[RPC] request:", id_str, ", args:", args)
reply = self.callback(id_str, args)
self.rep_socket.send(pmt.serialize_str(pmt.to_pmt(reply)))
@@ -85,11 +88,11 @@ class rpc_manager():
socks = dict(self.poller_req_in.poll(10))
if socks.get(self.req_socket) == zmq.POLLIN:
reply = pmt.to_python(pmt.deserialize_str(self.req_socket.recv()))
- print "[RPC] reply:", reply
+ print("[RPC] reply:", reply)
return reply
def callback(self, id_str, args):
- if self.interfaces.has_key(id_str):
+ if id_str in self.interfaces:
callback_func = self.interfaces.get(id_str)
if not args == None:
# use unpacking or splat operator * to unpack argument list
@@ -97,5 +100,5 @@ class rpc_manager():
else:
return(callback_func())
else:
- print "[RPC] ERROR: id_str not found:", id_str
+ print("[RPC] ERROR: id_str not found:", id_str)
return None