From 813379fea933d2794d47b0cddf3bdcca35ff2c1c Mon Sep 17 00:00:00 2001 From: Satoshi Kobayashi Date: Fri, 10 Apr 2015 15:43:39 +0900 Subject: [PATCH] '+' operator can't combine no-string object I don't know what it is not a really a string but use '%' for safety. Signed-off-by: FUJITA Tomonori --- ryu/app/simple_switch_snort.py | 4 +-- ryu/cmd/of_config_cli.py | 22 ++++++------ ryu/cmd/rpc_cli.py | 12 +++---- ryu/lib/stringify.py | 6 ++-- ryu/tests/integrated/vrrp_common.py | 34 +++++++++---------- ryu/tests/unit/lib/test_ip.py | 2 +- ryu/tests/unit/lib/test_stringify.py | 2 +- ryu/tests/unit/ofproto/test_parser.py | 2 +- ryu/tests/unit/ofproto/test_parser_compat.py | 2 +- .../unit/ofproto/test_parser_ofpmatch.py | 2 +- ryu/tests/unit/packet/test_bgp.py | 2 +- 11 files changed, 45 insertions(+), 45 deletions(-) diff --git a/ryu/app/simple_switch_snort.py b/ryu/app/simple_switch_snort.py index 70aa0735..71fce04e 100644 --- a/ryu/app/simple_switch_snort.py +++ b/ryu/app/simple_switch_snort.py @@ -62,13 +62,13 @@ class SimpleSwitchSnort(app_manager.RyuApp): # for p in pkt.protocols: # if hasattr(p, 'protocol_name') is False: # break - # print('p: ' + p.protocol_name) + # print('p: %s' % p.protocol_name) @set_ev_cls(snortlib.EventAlert, MAIN_DISPATCHER) def _dump_alert(self, ev): msg = ev.msg - print('alertmsg: ' + ''.join(msg.alertmsg)) + print('alertmsg: %s' % ''.join(msg.alertmsg)) self.packet_print(msg.pkt) diff --git a/ryu/cmd/of_config_cli.py b/ryu/cmd/of_config_cli.py index b040027b..6a6e49aa 100755 --- a/ryu/cmd/of_config_cli.py +++ b/ryu/cmd/of_config_cli.py @@ -87,12 +87,12 @@ class Cmd(cmd.Cmd): try: p = peers[peer] except KeyError: - print("unknown peer " + peer) + print("unknown peer %s" % peer) return try: f(p, args[1:]) except RPCError as e: - print("RPC Error " + e) + print("RPC Error %s" % e) except EOFError: print("disconnected") @@ -222,7 +222,7 @@ class Cmd(cmd.Cmd): def f(p, args): o = p.get() for p in o.resources.port: - print(p.resource_id + " " + p.name + " " + p.number) + print('%s %s %s' % (p.resource_id, p.name, p.number)) self._request(line, f) @@ -255,7 +255,7 @@ class Cmd(cmd.Cmd): v = getattr(conf, k) except AttributeError: continue - print(k + " " + v) + print('%s %s' % (k, v)) self._request(line, f) @@ -307,7 +307,7 @@ class Cmd(cmd.Cmd): o = p.get() if o.resources.queue: for q in o.resources.queue: - print(q.resource_id + " " + q.port) + print('%s %s' % (q.resource_id, q.port)) self._request(line, f) @@ -339,7 +339,7 @@ class Cmd(cmd.Cmd): v = getattr(conf, k) except AttributeError: continue - print(k + " " + v) + print('%s %s' % (k, v)) self._request(line, f) @@ -433,7 +433,7 @@ max-rate 100 def f(p, args): o = p.get() for s in o.logical_switches.switch: - print(s.id + " " + s.datapath_id) + print('%s %s' % (s.id, s.datapath_id)) self._request(line, f) @@ -452,15 +452,15 @@ max-rate 100 if s.id != lsw: continue print(s.id) - print('datapath-id ' + s.datapath_id) + print('datapath-id %s' % s.datapath_id) if s.resources.queue: print('queues:') for q in s.resources.queue: - print('\t ' + q) + print('\t %s' % q) if s.resources.port: print('ports:') for p in s.resources.port: - print('\t ' + p) + print('\t %s' % p) self._request(line, f) @@ -488,7 +488,7 @@ max-rate 100 v = getattr(l, k) except AttributeError: continue - print(k + " " + v) + print('%s %s' % (k, v)) self._request(line, f) diff --git a/ryu/cmd/rpc_cli.py b/ryu/cmd/rpc_cli.py index ee9ae0bc..a2af9cb6 100755 --- a/ryu/cmd/rpc_cli.py +++ b/ryu/cmd/rpc_cli.py @@ -72,11 +72,11 @@ class Peer(object): assert self.client except Exception as e: if verbose: - print("connection failure " + e) + print("connection failure %s" % e) raise EOFError def notification(self, n): - print("NOTIFICATION from " + self._name + " " + n) + print("NOTIFICATION from %s %s" % (self._name, n)) def call(self, method, params): return self._do(lambda: self.client.call(method, params)) @@ -128,12 +128,12 @@ class Cmd(cmd.Cmd): try: p = peers[peer] except KeyError: - print("unknown peer " + peer) + print("unknown peer %s" % peer) return try: f(p, method, params) except rpc.RPCError as e: - print("RPC ERROR " + e) + print("RPC ERROR %s" % e) except EOFError: print("disconnected") @@ -150,7 +150,7 @@ class Cmd(cmd.Cmd): def f(p, method, params): result = p.call(method, params) - print("RESULT " + result) + print("RESULT %s" % result) self._request(line, f) @@ -187,7 +187,7 @@ class Cmd(cmd.Cmd): p.client.peek_notification() except EOFError: p.client = None - print("disconnected " + k) + print("disconnected %s" % k) @staticmethod def _save_termios(): diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py index 8038632f..451c4b7b 100644 --- a/ryu/lib/stringify.py +++ b/ryu/lib/stringify.py @@ -303,9 +303,9 @@ class StringifyMixin(object): return cls(**dict(kwargs, **additional_args)) except TypeError: # debug - print("CLS " + cls) - print("ARG " + dict_) - print("KWARG " + kwargs) + print("CLS %s" % cls) + print("ARG %s" % dict_) + print("KWARG %s" % kwargs) raise @classmethod diff --git a/ryu/tests/integrated/vrrp_common.py b/ryu/tests/integrated/vrrp_common.py index fc1d40cc..0f06806a 100644 --- a/ryu/tests/integrated/vrrp_common.py +++ b/ryu/tests/integrated/vrrp_common.py @@ -65,15 +65,15 @@ class VRRPCommon(app_manager.RyuApp): for i in rep.instance_list): continue break - print(len(rep.instance_list) + ' / ' + len(instances) * 2) + print('%s / %s' % (len(rep.instance_list), len(instances) * 2)) time.sleep(1) # for i in rep.instance_list: -# print(i.instance_name + " " + \ -# i.monitor_name + " " + \ -# i.config + " " + \ -# i.interface + " " + \ -# i.state) +# print('%s %s %s %s %s' % (i.instance_name, +# i.monitor_name, +# i.config, +# i.interface, +# i.state)) assert len(rep.instance_list) == len(instances) * 2 num_of_master = 0 d = dict(((i.instance_name, i) for i in rep.instance_list)) @@ -91,21 +91,21 @@ class VRRPCommon(app_manager.RyuApp): i.instance_name == vr[0].instance_name): if i.state == vrrp_event.VRRP_STATE_MASTER: print("bad master:") - print(d[vr[0].instance_name].state + " " + - d[vr[0].instance_name].config.priority) - print(d[vr[1].instance_name].state + " " + - d[vr[1].instance_name].config.priority) + print('%s %s' % (d[vr[0].instance_name].state, + d[vr[0].instance_name].config.priority)) + print('%s %s' % (d[vr[1].instance_name].state, + d[vr[1].instance_name].config.priority)) bad += 1 # assert i.state != vrrp_event.VRRP_STATE_MASTER if bad > 0: # this could be a transient state - print(bad + " bad masters") + print("%s bad masters" % bad) time.sleep(1) continue if num_of_master >= len(instances): assert num_of_master == len(instances) break - print(num_of_master + ' / ' + len(instances)) + print('%s / %s' % (num_of_master, len(instances))) time.sleep(1) continue @@ -119,7 +119,7 @@ class VRRPCommon(app_manager.RyuApp): for vrid in xrange(1, 256, step): if vrid == _VRID: continue - print("vrid " + vrid) + print("vrid %s" % vrid) l = {} prio = max(vrrp.VRRP_PRIORITY_BACKUP_MIN, min(vrrp.VRRP_PRIORITY_BACKUP_MAX, vrid)) @@ -141,7 +141,7 @@ class VRRPCommon(app_manager.RyuApp): l[1] = rep1 instances[vrid] = l - print("vrid " + _VRID) + print("vrid %s" % _VRID) l = {} rep0 = self._configure_vrrp_router(vrrp_version, priority, _PRIMARY_IP_ADDRESS0, @@ -158,7 +158,7 @@ class VRRPCommon(app_manager.RyuApp): self.logger.debug('%s', vrrp_mgr._instances) if do_sleep: - print("priority " + priority) + print("priority %s" % priority) print("waiting for instances starting") self._check(vrrp_api, instances) @@ -192,7 +192,7 @@ class VRRPCommon(app_manager.RyuApp): rep = vrrp_api.vrrp_list(self) if len(rep.instance_list) <= len(instances): break - print("left " + len(rep.instance_list)) + print("left %s" % len(rep.instance_list)) time.sleep(1) assert len(rep.instance_list) == len(instances) print("waiting for the rest becoming master") @@ -215,5 +215,5 @@ class VRRPCommon(app_manager.RyuApp): rep = vrrp_api.vrrp_list(self) if not rep.instance_list: break - print("left " + len(rep.instance_list)) + print("left %s" % len(rep.instance_list)) time.sleep(1) diff --git a/ryu/tests/unit/lib/test_ip.py b/ryu/tests/unit/lib/test_ip.py index d8c3245d..f23f98c8 100644 --- a/ryu/tests/unit/lib/test_ip.py +++ b/ryu/tests/unit/lib/test_ip.py @@ -55,5 +55,5 @@ class Test_ip(unittest.TestCase): val = '2013:da8:215:8f2:aa20:66ff:fe4c:9c3c' res = ip.ipv6_to_str(ipv6_bin) - print(val + ' ' + res) + print('%s %s' % (val, res)) eq_(val, res) diff --git a/ryu/tests/unit/lib/test_stringify.py b/ryu/tests/unit/lib/test_stringify.py index 33d118d9..4b47fd22 100644 --- a/ryu/tests/unit/lib/test_stringify.py +++ b/ryu/tests/unit/lib/test_stringify.py @@ -25,7 +25,7 @@ from ryu.lib import stringify class C1(stringify.StringifyMixin): def __init__(self, a, c): - print("init " + a + " " + c) + print("init %s %s" % (a, c)) self.a = a self._b = 'B' self.c = c diff --git a/ryu/tests/unit/ofproto/test_parser.py b/ryu/tests/unit/ofproto/test_parser.py index 3da5cd72..76fb9e86 100644 --- a/ryu/tests/unit/ofproto/test_parser.py +++ b/ryu/tests/unit/ofproto/test_parser.py @@ -156,7 +156,7 @@ class Test_Parser(unittest.TestCase): """ def __init__(self, methodName): - print('init ' + methodName) + print('init %s' % methodName) super(Test_Parser, self).__init__(methodName) def setUp(self): diff --git a/ryu/tests/unit/ofproto/test_parser_compat.py b/ryu/tests/unit/ofproto/test_parser_compat.py index 5a032557..4d1de32c 100644 --- a/ryu/tests/unit/ofproto/test_parser_compat.py +++ b/ryu/tests/unit/ofproto/test_parser_compat.py @@ -30,7 +30,7 @@ from struct import unpack class Test_Parser_Compat(unittest.TestCase): def __init__(self, methodName): - print('init ' + methodName) + print('init %s' % methodName) super(Test_Parser_Compat, self).__init__(methodName) def setUp(self): diff --git a/ryu/tests/unit/ofproto/test_parser_ofpmatch.py b/ryu/tests/unit/ofproto/test_parser_ofpmatch.py index c3fd42a9..3ae60fcd 100644 --- a/ryu/tests/unit/ofproto/test_parser_ofpmatch.py +++ b/ryu/tests/unit/ofproto/test_parser_ofpmatch.py @@ -30,7 +30,7 @@ class Test_Parser_OFPMatch(unittest.TestCase): ofproto_v1_3_parser: ofproto_v1_3} def __init__(self, methodName): - print('init ' + methodName) + print('init %s' % methodName) super(Test_Parser_OFPMatch, self).__init__(methodName) def setUp(self): diff --git a/ryu/tests/unit/packet/test_bgp.py b/ryu/tests/unit/packet/test_bgp.py index 8234378a..a795562a 100644 --- a/ryu/tests/unit/packet/test_bgp.py +++ b/ryu/tests/unit/packet/test_bgp.py @@ -200,7 +200,7 @@ class Test_bgp(unittest.TestCase): dir = '../packet_data/bgp4/' for f in files: - print('testing ' + f) + print('testing %s' % f) binmsg = open(dir + f).read() msg, rest = bgp.BGPMessage.parser(binmsg) binmsg2 = msg.serialize()