Skip to content

Commit 7b74317

Browse files
authored
sourcebroker.py, edgebroker.py: port to python3 (#48220)
1 parent 874e3b7 commit 7b74317

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

tools/edgebroker.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import zmq
33

44
if len(sys.argv) < 3:
5-
print("usage: %s [pub_spec] [sub_spec,sub_spec,...]" % sys.argv[0])
5+
print(f"usage: {sys.argv[0]} [pub_spec] [sub_spec,sub_spec,...]")
66
sys.exit(1)
77

88
pub_spec = sys.argv[1]
@@ -30,9 +30,10 @@
3030
m = pub_sock.recv()
3131
mtype = m[0]
3232
topic = m[1:]
33-
if mtype == "\x01":
34-
print("subscribing [%s]" % topic)
33+
topicstr = topic.decode("utf-8")
34+
if mtype == 1:
35+
print(f"subscribing [{topic}]")
3536
sub_sock.setsockopt(zmq.SUBSCRIBE, topic)
36-
elif mtype == "\x00":
37-
print("unsubscribing [%s]" % topic)
37+
elif mtype == 0:
38+
print(f"unsubscribing [{topic}]")
3839
sub_sock.setsockopt(zmq.UNSUBSCRIBE, topic)

tools/sourcebroker.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import zmq
44

55
if len(sys.argv) < 3:
6-
print("usage: %s [pub_spec] [pull_spec]" % sys.argv[0])
6+
print(f"usage: {sys.argv[0]} [pub_spec] [pull_spec]")
77
sys.exit(1)
88

99
pub_spec = sys.argv[1]
@@ -27,19 +27,20 @@
2727
socks = dict(poller.poll())
2828
if socks.get(pull_sock) == zmq.POLLIN:
2929
m = tnetstring.loads(pull_sock.recv())
30-
channel = m["channel"]
30+
channel = m[b"channel"]
3131
if channel in subs:
32-
del m["channel"]
32+
del m[b"channel"]
3333
pub_sock.send_multipart([channel, tnetstring.dumps(m)])
3434
elif socks.get(pub_sock) == zmq.POLLIN:
3535
m = pub_sock.recv()
3636
mtype = m[0]
3737
topic = m[1:]
38-
if mtype == "\x01":
38+
topicstr = topic.decode("utf-8")
39+
if mtype == 1:
3940
assert topic not in subs
40-
print("subscribing [%s]" % topic)
41+
print(f"subscribing [{topicstr}]")
4142
subs.add(topic)
42-
elif mtype == "\x00":
43+
elif mtype == 0:
4344
assert topic in subs
44-
print("unsubscribing [%s]" % topic)
45+
print(f"unsubscribing [{topicstr}]")
4546
subs.remove(topic)

0 commit comments

Comments
 (0)