File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed
Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 22import zmq
33
44if 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
88pub_spec = sys .argv [1 ]
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 )
Original file line number Diff line number Diff line change 33import zmq
44
55if 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
99pub_spec = sys .argv [1 ]
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 )
You can’t perform that action at this time.
0 commit comments