diff --git a/ryu/app/bmpstation.py b/ryu/app/bmpstation.py index ce313092..781751cf 100644 --- a/ryu/app/bmpstation.py +++ b/ryu/app/bmpstation.py @@ -73,7 +73,7 @@ class BMPStation(app_manager.RyuApp): try: msg, rest = bmp.BMPMessage.parser(buf) - except Exception, e: + except Exception as e: pkt = buf[:len_] self.failed_dump_fd.write(pkt) self.failed_dump_fd.flush() diff --git a/ryu/app/rest_firewall.py b/ryu/app/rest_firewall.py index b60e62d5..322ddb1d 100644 --- a/ryu/app/rest_firewall.py +++ b/ryu/app/rest_firewall.py @@ -388,7 +388,7 @@ class FirewallController(ControllerBase): dpid_str = dpid_lib.dpid_to_str(dp.id) try: f_ofs = Firewall(dp) - except OFPUnknownVersion, message: + except OFPUnknownVersion as message: FirewallController._LOGGER.info('dpid=%s: %s', dpid_str, message) return @@ -439,7 +439,7 @@ class FirewallController(ControllerBase): def _access_module(self, switchid, func, waiters=None): try: dps = self._OFS_LIST.get_ofs(switchid) - except ValueError, message: + except ValueError as message: return Response(status=400, body=str(message)) msgs = [] @@ -479,7 +479,7 @@ class FirewallController(ControllerBase): try: dps = self._OFS_LIST.get_ofs(switchid) vid = FirewallController._conv_toint_vlanid(vlan_id) - except ValueError, message: + except ValueError as message: return Response(status=400, body=str(message)) msgs = [] @@ -500,7 +500,7 @@ class FirewallController(ControllerBase): try: dps = self._OFS_LIST.get_ofs(switchid) vid = FirewallController._conv_toint_vlanid(vlan_id) - except ValueError, message: + except ValueError as message: return Response(status=400, body=str(message)) msgs = [] @@ -508,7 +508,7 @@ class FirewallController(ControllerBase): try: msg = f_ofs.set_rule(rule, self.waiters, vid) msgs.append(msg) - except ValueError, message: + except ValueError as message: return Response(status=400, body=str(message)) body = json.dumps(msgs) @@ -524,7 +524,7 @@ class FirewallController(ControllerBase): try: dps = self._OFS_LIST.get_ofs(switchid) vid = FirewallController._conv_toint_vlanid(vlan_id) - except ValueError, message: + except ValueError as message: return Response(status=400, body=str(message)) msgs = [] @@ -532,7 +532,7 @@ class FirewallController(ControllerBase): try: msg = f_ofs.delete_rule(ruleid, self.waiters, vid) msgs.append(msg) - except ValueError, message: + except ValueError as message: return Response(status=400, body=str(message)) body = json.dumps(msgs) diff --git a/ryu/app/rest_qos.py b/ryu/app/rest_qos.py index f9ab9362..1753e418 100644 --- a/ryu/app/rest_qos.py +++ b/ryu/app/rest_qos.py @@ -400,7 +400,7 @@ class QoSController(ControllerBase): try: f_ofs = QoS(dp, CONF) f_ofs.set_default_flow() - except OFPUnknownVersion, message: + except OFPUnknownVersion as message: QoSController._LOGGER.info('dpid=%s: %s', dpid_str, message) return @@ -515,7 +515,7 @@ class QoSController(ControllerBase): try: dps = self._OFS_LIST.get_ofs(switchid) vid = QoSController._conv_toint_vlanid(vlan_id) - except ValueError, message: + except ValueError as message: return Response(status=400, body=str(message)) msgs = [] @@ -526,7 +526,7 @@ class QoSController(ControllerBase): msg = function(rest, vid, waiters) else: msg = function(rest, vid) - except ValueError, message: + except ValueError as message: return Response(status=400, body=str(message)) msgs.append(msg) @@ -699,7 +699,7 @@ class QoS(object): self.ovs_bridge.set_qos(port_name, type=queue_type, max_rate=parent_max_rate, queues=queue_config) - except Exception, msg: + except Exception as msg: raise ValueError(msg) msg = {'result': 'success', diff --git a/ryu/app/simple_switch_snort.py b/ryu/app/simple_switch_snort.py index 51c3d1e0..70aa0735 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: ' + 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: ' + ''.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 61de4e45..b040027b 100755 --- a/ryu/cmd/of_config_cli.py +++ b/ryu/cmd/of_config_cli.py @@ -69,7 +69,7 @@ def et_tostring_pp(tree): def validate(tree): schema = ET.XMLSchema(file=of_config.OF_CONFIG_1_1_1_XSD) if not schema(tree): - print schema.error_log + print(schema.error_log) class Cmd(cmd.Cmd): @@ -82,19 +82,19 @@ class Cmd(cmd.Cmd): try: peer = args[0] except: - print "argument error" + print("argument error") return try: p = peers[peer] except KeyError: - print "unknown peer", peer + print("unknown peer " + peer) return try: f(p, args[1:]) - except RPCError, e: - print "RPC Error", e + except RPCError as e: + print("RPC Error " + e) except EOFError: - print "disconnected" + print("disconnected") def _complete_peer(self, text, line, _begidx, _endidx): if len((line + 'x').split()) >= 3: @@ -107,7 +107,7 @@ class Cmd(cmd.Cmd): def f(p, args): for i in p.netconf.server_capabilities: - print i + print(i) self._request(line, f) @@ -119,7 +119,7 @@ class Cmd(cmd.Cmd): result = p.raw_get() tree = ET.fromstring(result) validate(tree) - print et_tostring_pp(tree) + print(et_tostring_pp(tree)) self._request(line, f) @@ -131,12 +131,12 @@ class Cmd(cmd.Cmd): try: source = args[0] except: - print "argument error" + print("argument error") return result = p.raw_get_config(source) tree = ET.fromstring(result) validate(tree) - print et_tostring_pp(tree) + print(et_tostring_pp(tree)) self._request(line, f) @@ -146,7 +146,7 @@ class Cmd(cmd.Cmd): """ def f(p, args): - print p.get() + print(p.get()) self._request(line, f) @@ -156,7 +156,7 @@ class Cmd(cmd.Cmd): """ def f(p, args): - print p.commit() + print(p.commit()) self._request(line, f) @@ -166,7 +166,7 @@ class Cmd(cmd.Cmd): """ def f(p, args): - print p.discard_changes() + print(p.discard_changes()) self._request(line, f) @@ -179,9 +179,9 @@ class Cmd(cmd.Cmd): try: source = args[0] except: - print "argument error" + print("argument error") return - print p.get_config(source) + print(p.get_config(source)) self._request(line, f) @@ -194,9 +194,9 @@ class Cmd(cmd.Cmd): try: source = args[0] except: - print "argument error" + print("argument error") return - print p.delete_config(source) + print(p.delete_config(source)) self._request(line, f) @@ -209,9 +209,9 @@ class Cmd(cmd.Cmd): try: source, target = args except: - print "argument error" + print("argument error") return - print p.copy_config(source, target) + print(p.copy_config(source, target)) self._request(line, f) @@ -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(p.resource_id + " " + p.name + " " + p.number) self._request(line, f) @@ -242,20 +242,20 @@ class Cmd(cmd.Cmd): try: source, port = args except: - print "argument error" + print("argument error") return o = p.get_config(source) for p in o.resources.port: if p.resource_id != port: continue - print p.resource_id + print(p.resource_id) conf = p.configuration for k in self._port_settings: try: v = getattr(conf, k) except AttributeError: continue - print k, v + print(k + " " + v) self._request(line, f) @@ -269,8 +269,8 @@ class Cmd(cmd.Cmd): try: target, port, key, value = args except: - print "argument error" - print args + print("argument error") + print(args) return # get switch id @@ -290,12 +290,12 @@ class Cmd(cmd.Cmd): ) ) except TypeError: - print "argument error" + print("argument error") return try: p.edit_config(target, capable_switch) - except Exception, e: - print e + except Exception as e: + print(e) 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(q.resource_id + " " + q.port) self._request(line, f) @@ -326,20 +326,20 @@ class Cmd(cmd.Cmd): try: source, queue = args except: - print "argument error" + print("argument error") return o = p.get_config(source) for q in o.resources.queue: if q.resource_id != queue: continue - print q.resource_id + print(q.resource_id) conf = q.properties for k in self._queue_settings: try: v = getattr(conf, k) except AttributeError: continue - print k, v + print(k + " " + v) self._request(line, f) @@ -353,8 +353,8 @@ max-rate 100 try: target, queue, key, value = args except: - print "argument error" - print args + print("argument error") + print(args) return # get switch id @@ -374,12 +374,12 @@ max-rate 100 ) ) except TypeError: - print "argument error" + print("argument error") return try: p.edit_config(target, capable_switch) - except Exception, e: - print e + except Exception as e: + print(e) self._request(line, f) @@ -392,8 +392,8 @@ max-rate 100 try: target, lsw, queue = args except: - print "argument error" - print args + print("argument error") + print(args) return # get switch id @@ -417,12 +417,12 @@ max-rate 100 ) ) except TypeError: - print "argument error" + print("argument error") return try: p.edit_config(target, capable_switch) - except Exception, e: - print e + except Exception as e: + print(e) 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.id + " " + s.datapath_id) self._request(line, f) @@ -445,22 +445,22 @@ max-rate 100 try: (lsw,) = args except: - print "argument error" + print("argument error") return o = p.get() for s in o.logical_switches.switch: if s.id != lsw: continue - print s.id - print 'datapath-id', s.datapath_id + print(s.id) + print('datapath-id ' + s.datapath_id) if s.resources.queue: - print 'queues:' + print('queues:') for q in s.resources.queue: - print '\t', q + print('\t ' + q) if s.resources.port: - print 'ports:' + print('ports:') for p in s.resources.port: - print '\t', p + print('\t ' + p) self._request(line, f) @@ -476,19 +476,19 @@ max-rate 100 try: source, lsw = args except: - print "argument error" + print("argument error") return o = p.get_config(source) for l in o.logical_switches.switch: if l.id != lsw: continue - print l.id + print(l.id) for k in self._lsw_settings: try: v = getattr(l, k) except AttributeError: continue - print k, v + print(k + " " + v) self._request(line, f) @@ -502,7 +502,7 @@ lost-connection-behavior failStandaloneMode try: target, lsw, key, value = args except: - print "argument error" + print("argument error") return # get switch id @@ -520,12 +520,12 @@ lost-connection-behavior failStandaloneMode ) ) except TypeError: - print "argument error" + print("argument error") return try: p.edit_config(target, capable_switch) - except Exception, e: - print e + except Exception as e: + print(e) self._request(line, f) diff --git a/ryu/cmd/rpc_cli.py b/ryu/cmd/rpc_cli.py index 691f9a2d..ee9ae0bc 100755 --- a/ryu/cmd/rpc_cli.py +++ b/ryu/cmd/rpc_cli.py @@ -70,13 +70,13 @@ class Peer(object): try: self.connect() assert self.client - except Exception, e: + except Exception as e: if verbose: - print "connection failure", e + print("connection failure " + e) raise EOFError def notification(self, n): - print "NOTIFICATION from", self._name, n + print("NOTIFICATION from " + self._name + " " + n) def call(self, method, params): return self._do(lambda: self.client.call(method, params)) @@ -96,9 +96,9 @@ class Peer(object): try: return g() except EOFError: - print "disconnected. trying to connect..." + print("disconnected. trying to connect...") self.try_to_connect(verbose=True) - print "connected. retrying the request..." + print("connected. retrying the request...") return g() @@ -123,19 +123,19 @@ class Cmd(cmd.Cmd): method = args[1] params = eval(args[2]) except: - print "argument error" + print("argument error") return try: p = peers[peer] except KeyError: - print "unknown peer", peer + print("unknown peer " + peer) return try: f(p, method, params) - except rpc.RPCError, e: - print "RPC ERROR", e + except rpc.RPCError as e: + print("RPC ERROR " + e) except EOFError: - print "disconnected" + print("disconnected") def _complete_peer(self, text, line, _begidx, _endidx): if len((line + 'x').split()) >= 3: @@ -150,7 +150,7 @@ class Cmd(cmd.Cmd): def f(p, method, params): result = p.call(method, params) - print "RESULT", result + print("RESULT " + 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 " + k) @staticmethod def _save_termios(): diff --git a/ryu/cmd/ryu_base.py b/ryu/cmd/ryu_base.py index 9ea75c25..4a8fc417 100644 --- a/ryu/cmd/ryu_base.py +++ b/ryu/cmd/ryu_base.py @@ -61,7 +61,7 @@ class SubCommand(object): def main(): try: base_conf(project='ryu', version='ryu %s' % version) - except cfg.RequiredOptError, e: + except cfg.RequiredOptError as e: base_conf.print_help() raise SystemExit(1) subcmd_name = base_conf.subcommand diff --git a/ryu/contrib/ovs/daemon.py b/ryu/contrib/ovs/daemon.py index 650d2504..a35946ff 100644 --- a/ryu/contrib/ovs/daemon.py +++ b/ryu/contrib/ovs/daemon.py @@ -144,30 +144,30 @@ def _make_pidfile(): global file_handle file_handle = open(tmpfile, "w") - except IOError, e: + except IOError as e: _fatal("%s: create failed (%s)" % (tmpfile, e.strerror)) try: s = os.fstat(file_handle.fileno()) - except IOError, e: + except IOError as e: _fatal("%s: fstat failed (%s)" % (tmpfile, e.strerror)) try: file_handle.write("%s\n" % pid) file_handle.flush() - except OSError, e: + except OSError as e: _fatal("%s: write failed: %s" % (tmpfile, e.strerror)) try: fcntl.lockf(file_handle, fcntl.LOCK_EX | fcntl.LOCK_NB) - except IOError, e: + except IOError as e: _fatal("%s: fcntl failed: %s" % (tmpfile, e.strerror)) # Rename or link it to the correct name. if _overwrite_pidfile: try: os.rename(tmpfile, _pidfile) - except OSError, e: + except OSError as e: _fatal("failed to rename \"%s\" to \"%s\" (%s)" % (tmpfile, _pidfile, e.strerror)) else: @@ -175,7 +175,7 @@ def _make_pidfile(): try: os.link(tmpfile, _pidfile) error = 0 - except OSError, e: + except OSError as e: error = e.errno if error == errno.EEXIST: _check_already_running() @@ -211,7 +211,7 @@ def _waitpid(pid, options): while True: try: return os.waitpid(pid, options) - except OSError, e: + except OSError as e: if e.errno == errno.EINTR: pass return -e.errno, 0 @@ -220,13 +220,13 @@ def _waitpid(pid, options): def _fork_and_wait_for_startup(): try: rfd, wfd = os.pipe() - except OSError, e: + except OSError as e: sys.stderr.write("pipe failed: %s\n" % os.strerror(e.errno)) sys.exit(1) try: pid = os.fork() - except OSError, e: + except OSError as e: sys.stderr.write("could not fork: %s\n" % os.strerror(e.errno)) sys.exit(1) @@ -238,7 +238,7 @@ def _fork_and_wait_for_startup(): try: s = os.read(rfd, 1) error = 0 - except OSError, e: + except OSError as e: s = "" error = e.errno if error != errno.EINTR: @@ -326,7 +326,7 @@ def _monitor_daemon(daemon_pid): wakeup = last_restart + 10000 if now > wakeup: break - print "sleep %f" % ((wakeup - now) / 1000.0) + print("sleep %f" % ((wakeup - now) / 1000.0)) time.sleep((wakeup - now) / 1000.0) last_restart = ovs.timeval.msec() @@ -416,7 +416,7 @@ def __read_pidfile(pidfile, delete_if_stale): try: file_handle = open(pidfile, "r+") - except IOError, e: + except IOError as e: if e.errno == errno.ENOENT and delete_if_stale: return 0 vlog.warn("%s: open: %s" % (pidfile, e.strerror)) @@ -449,7 +449,7 @@ def __read_pidfile(pidfile, delete_if_stale): # We won the right to delete the stale pidfile. try: os.unlink(pidfile) - except IOError, e: + except IOError as e: vlog.warn("%s: failed to delete stale pidfile (%s)" % (pidfile, e.strerror)) return -e.errno @@ -457,7 +457,7 @@ def __read_pidfile(pidfile, delete_if_stale): vlog.dbg("%s: deleted stale pidfile" % pidfile) file_handle.close() return 0 - except IOError, e: + except IOError as e: if e.errno not in [errno.EACCES, errno.EAGAIN]: vlog.warn("%s: fcntl: %s" % (pidfile, e.strerror)) return -e.errno @@ -466,7 +466,7 @@ def __read_pidfile(pidfile, delete_if_stale): try: try: error = int(file_handle.readline()) - except IOError, e: + except IOError as e: vlog.warn("%s: read: %s" % (pidfile, e.strerror)) error = -e.errno except ValueError: diff --git a/ryu/contrib/ovs/db/idl.py b/ryu/contrib/ovs/db/idl.py index 9e9bf0f5..27d478b7 100644 --- a/ryu/contrib/ovs/db/idl.py +++ b/ryu/contrib/ovs/db/idl.py @@ -186,7 +186,7 @@ class Idl: self._monitor_request_id = None self.__clear() self.__parse_update(msg.result) - except error.Error, e: + except error.Error as e: vlog.err("%s: parse error in received schema: %s" % (self._session.get_name(), e)) self.__error() @@ -332,7 +332,7 @@ class Idl: def __parse_update(self, update): try: self.__do_parse_update(update) - except error.Error, e: + except error.Error as e: vlog.err("%s: error parsing update: %s" % (self._session.get_name(), e)) @@ -424,7 +424,7 @@ class Idl: try: datum = ovs.db.data.Datum.from_json(column.type, datum_json) - except error.Error, e: + except error.Error as e: # XXX rate-limit vlog.warn("error parsing column %s in table %s: %s" % (column_name, table.name, e)) @@ -563,7 +563,7 @@ class Row(object): try: datum = ovs.db.data.Datum.from_python(column.type, value, _row_to_uuid) - except error.Error, e: + except error.Error as e: # XXX rate-limit vlog.err("attempting to write bad value to column %s (%s)" % (column_name, e)) diff --git a/ryu/contrib/ovs/fatal_signal.py b/ryu/contrib/ovs/fatal_signal.py index e6fe7838..73080392 100644 --- a/ryu/contrib/ovs/fatal_signal.py +++ b/ryu/contrib/ovs/fatal_signal.py @@ -90,7 +90,7 @@ def _unlink(file_): try: os.unlink(file_) return 0 - except OSError, e: + except OSError as e: return e.errno diff --git a/ryu/contrib/ovs/json.py b/ryu/contrib/ovs/json.py index d329ee41..bfa9f5a9 100644 --- a/ryu/contrib/ovs/json.py +++ b/ryu/contrib/ovs/json.py @@ -143,7 +143,7 @@ def from_file(name): def from_string(s): try: s = unicode(s, 'utf-8') - except UnicodeDecodeError, e: + except UnicodeDecodeError as e: seq = ' '.join(["0x%2x" % ord(c) for c in e.object[e.start:e.end] if ord(c) >= 0x80]) return ("not a valid UTF-8 string: invalid UTF-8 sequence %s" % seq) diff --git a/ryu/contrib/ovs/ovsuuid.py b/ryu/contrib/ovs/ovsuuid.py index 56fdad05..5cc0e1d7 100644 --- a/ryu/contrib/ovs/ovsuuid.py +++ b/ryu/contrib/ovs/ovsuuid.py @@ -42,7 +42,7 @@ def from_json(json, symtab=None): if not uuidRE.match(s): raise error.Error("\"%s\" is not a valid UUID" % s, json) return uuid.UUID(s) - except error.Error, e: + except error.Error as e: if not symtab: raise e try: diff --git a/ryu/contrib/ovs/poller.py b/ryu/contrib/ovs/poller.py index ffd6a399..51d78297 100644 --- a/ryu/contrib/ovs/poller.py +++ b/ryu/contrib/ovs/poller.py @@ -171,7 +171,7 @@ class Poller(object): try: events = self.poll.poll(self.timeout) self.__log_wakeup(events) - except select.error, e: + except select.error as e: # XXX rate-limit error, msg = e if error != errno.EINTR: diff --git a/ryu/contrib/ovs/socket_util.py b/ryu/contrib/ovs/socket_util.py index 1fc80fd3..843a5a99 100644 --- a/ryu/contrib/ovs/socket_util.py +++ b/ryu/contrib/ovs/socket_util.py @@ -37,7 +37,7 @@ def make_unix_socket(style, nonblock, bind_path, connect_path): try: sock = socket.socket(socket.AF_UNIX, style) - except socket.error, e: + except socket.error as e: return get_exception_errno(e), None try: @@ -47,7 +47,7 @@ def make_unix_socket(style, nonblock, bind_path, connect_path): # Delete bind_path but ignore ENOENT. try: os.unlink(bind_path) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: return e.errno, None @@ -56,19 +56,19 @@ def make_unix_socket(style, nonblock, bind_path, connect_path): try: if sys.hexversion >= 0x02060000: - os.fchmod(sock.fileno(), 0700) + os.fchmod(sock.fileno(), 0o700) else: os.chmod("/dev/fd/%d" % sock.fileno(), 0700) - except OSError, e: + except OSError as e: pass if connect_path is not None: try: sock.connect(connect_path) - except socket.error, e: + except socket.error as e: if get_exception_errno(e) != errno.EINPROGRESS: raise return 0, sock - except socket.error, e: + except socket.error as e: sock.close() if bind_path is not None: ovs.fatal_signal.unlink_file_now(bind_path) @@ -102,7 +102,7 @@ def inet_open_active(style, target, default_port, dscp): address = inet_parse_active(target, default_port) try: sock = socket.socket(socket.AF_INET, style, 0) - except socket.error, e: + except socket.error as e: return get_exception_errno(e), None try: @@ -110,11 +110,11 @@ def inet_open_active(style, target, default_port, dscp): set_dscp(sock, dscp) try: sock.connect(address) - except socket.error, e: + except socket.error as e: if get_exception_errno(e) != errno.EINPROGRESS: raise return 0, sock - except socket.error, e: + except socket.error as e: sock.close() return get_exception_errno(e), None @@ -147,7 +147,7 @@ def get_null_fd(): if null_fd < 0: try: null_fd = os.open("/dev/null", os.O_RDWR) - except OSError, e: + except OSError as e: vlog.err("could not open /dev/null: %s" % os.strerror(e.errno)) return -e.errno return null_fd @@ -173,14 +173,14 @@ def write_fully(fd, buf): else: bytes_written += retval buf = buf[:retval] - except OSError, e: + except OSError as e: return e.errno, bytes_written def set_nonblocking(sock): try: sock.setblocking(0) - except socket.error, e: + except socket.error as e: vlog.err("could not set nonblocking mode on socket: %s" % os.strerror(get_socket_error(e))) diff --git a/ryu/contrib/ovs/stream.py b/ryu/contrib/ovs/stream.py index c640ebf5..b584398a 100644 --- a/ryu/contrib/ovs/stream.py +++ b/ryu/contrib/ovs/stream.py @@ -119,8 +119,9 @@ class Stream(object): raise NotImplementedError("This method must be overrided by subclass") @staticmethod - def open_block((error, stream)): + def open_block(args): """Blocks until a Stream completes its connection attempt, either + (error, stream) = args succeeding or failing. (error, stream) should be the tuple returned by Stream.open(). Returns a tuple of the same form. @@ -196,7 +197,7 @@ class Stream(object): try: return (0, self.socket.recv(n)) - except socket.error, e: + except socket.error as e: return (ovs.socket_util.get_exception_errno(e), "") def send(self, buf): @@ -218,7 +219,7 @@ class Stream(object): try: return self.socket.send(buf) - except socket.error, e: + except socket.error as e: return -ovs.socket_util.get_exception_errno(e) def run(self): @@ -289,7 +290,7 @@ class PassiveStream(object): try: sock.listen(10) - except socket.error, e: + except socket.error as e: vlog.err("%s: listen: %s" % (name, os.strerror(e.error))) sock.close() return e.error, None @@ -317,7 +318,7 @@ class PassiveStream(object): sock, addr = self.socket.accept() ovs.socket_util.set_nonblocking(sock) return 0, Stream(sock, "unix:%s" % addr, 0) - except socket.error, e: + except socket.error as e: error = ovs.socket_util.get_exception_errno(e) if error != errno.EAGAIN: # XXX rate-limit diff --git a/ryu/controller/conf_switch.py b/ryu/controller/conf_switch.py index 812a3a52..9668b8ef 100644 --- a/ryu/controller/conf_switch.py +++ b/ryu/controller/conf_switch.py @@ -84,8 +84,9 @@ class ConfSwitchSet(app_manager.RyuApp): self.send_event_to_observers(EventConfSwitchDel(dpid, key)) # methods for TunnelUpdater - def __contains__(self, (dpid, key)): + def __contains__(self, item): """(dpid, key) in """ + (dpid, key) = item return dpid in self.confs and key in self.confs[dpid] def find_dpid(self, key, value): diff --git a/ryu/lib/ovs/vsctl.py b/ryu/lib/ovs/vsctl.py index 8d121f52..9d8d8486 100644 --- a/ryu/lib/ovs/vsctl.py +++ b/ryu/lib/ovs/vsctl.py @@ -1876,27 +1876,27 @@ def schema_print(schema_location, prefix): json = ovs.json.from_file(schema_location) schema = ovs.db.schema.DbSchema.from_json(json) - print '# Do NOT edit.' - print '# This is automatically generated.' - print '# created based on version %s' % (schema.version or 'unknown') - print '' - print '' - print '%s_DB_NAME = \'%s\'' % (prefix, schema.name) + print('# Do NOT edit.') + print('# This is automatically generated.') + print('# created based on version %s' % (schema.version or 'unknown')) + print('') + print('') + print('%s_DB_NAME = \'%s\'' % (prefix, schema.name)) for table in sorted(schema.tables.values(), key=operator.attrgetter('name')): - print '' - print '%s_TABLE_%s = \'%s\'' % (prefix, - table.name.upper(), table.name) + print('') + print('%s_TABLE_%s = \'%s\'' % (prefix, + table.name.upper(), table.name)) for column in sorted(table.columns.values(), key=operator.attrgetter('name')): - print '%s_%s_COL_%s = \'%s\'' % (prefix, table.name.upper(), + print('%s_%s_COL_%s = \'%s\'' % (prefix, table.name.upper(), column.name.upper(), - column.name) + column.name)) def main(): if len(sys.argv) <= 2: - print 'Usage: %s ' % sys.argv[0] + print('Usage: %s ' % sys.argv[0]) location = sys.argv[1] prefix = sys.argv[2] diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py index 1561ca35..8038632f 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 " + cls) + print("ARG " + dict_) + print("KWARG " + kwargs) raise @classmethod diff --git a/ryu/services/protocols/bgp/operator/commands/show/rib.py b/ryu/services/protocols/bgp/operator/commands/show/rib.py index d5077d05..a865a08f 100644 --- a/ryu/services/protocols/bgp/operator/commands/show/rib.py +++ b/ryu/services/protocols/bgp/operator/commands/show/rib.py @@ -55,7 +55,7 @@ class Rib(RibBase): for family in self.supported_families: ret[family] = self.api.get_single_rib_routes(family) return CommandsResponse(STATUS_OK, ret) - except ActivityException, e: + except ActivityException as e: return CommandsResponse(STATUS_ERROR, e) @classmethod diff --git a/ryu/services/protocols/bgp/utils/dictconfig.py b/ryu/services/protocols/bgp/utils/dictconfig.py index c430d881..9eb4cd22 100644 --- a/ryu/services/protocols/bgp/utils/dictconfig.py +++ b/ryu/services/protocols/bgp/utils/dictconfig.py @@ -302,21 +302,21 @@ class DictConfigurator(BaseConfigurator): level = handler_config.get('level', None) if level: handler.setLevel(_checkLevel(level)) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure handler ' '%r: %s' % (name, e)) loggers = config.get('loggers', EMPTY_DICT) for name in loggers: try: self.configure_logger(name, loggers[name], True) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure logger ' '%r: %s' % (name, e)) root = config.get('root', None) if root: try: self.configure_root(root, True) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure root ' 'logger: %s' % e) else: @@ -331,7 +331,7 @@ class DictConfigurator(BaseConfigurator): try: formatters[name] = self.configure_formatter( formatters[name]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure ' 'formatter %r: %s' % (name, e)) # Next, do filters - they don't refer to anything else, either @@ -339,7 +339,7 @@ class DictConfigurator(BaseConfigurator): for name in filters: try: filters[name] = self.configure_filter(filters[name]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure ' 'filter %r: %s' % (name, e)) @@ -352,7 +352,7 @@ class DictConfigurator(BaseConfigurator): handler = self.configure_handler(handlers[name]) handler.name = name handlers[name] = handler - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure handler ' '%r: %s' % (name, e)) # Next, do loggers - they refer to handlers and filters @@ -391,7 +391,7 @@ class DictConfigurator(BaseConfigurator): existing.remove(name) try: self.configure_logger(name, loggers[name]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure logger ' '%r: %s' % (name, e)) @@ -414,7 +414,7 @@ class DictConfigurator(BaseConfigurator): if root: try: self.configure_root(root) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to configure root ' 'logger: %s' % e) finally: @@ -426,7 +426,7 @@ class DictConfigurator(BaseConfigurator): factory = config['()'] # for use in exception handler try: result = self.configure_custom(config) - except TypeError, te: + except TypeError as te: if "'format'" not in str(te): raise # Name of parameter changed from fmt to format. @@ -456,7 +456,7 @@ class DictConfigurator(BaseConfigurator): for f in filters: try: filterer.addFilter(self.config['filters'][f]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to add filter %r: %s' % (f, e)) def configure_handler(self, config): @@ -465,7 +465,7 @@ class DictConfigurator(BaseConfigurator): if formatter: try: formatter = self.config['formatters'][formatter] - except StandardError, e: + except StandardError as e: raise ValueError('Unable to set formatter ' '%r: %s' % (formatter, e)) level = config.pop('level', None) @@ -485,7 +485,7 @@ class DictConfigurator(BaseConfigurator): try: trgt = self.config['handlers'][config['target']] config['target'] = trgt - except StandardError, e: + except StandardError as e: raise ValueError('Unable to set target handler ' '%r: %s' % (config['target'], e)) elif issubclass(klass, logging.handlers.SMTPHandler) and\ @@ -498,7 +498,7 @@ class DictConfigurator(BaseConfigurator): kwargs = dict([(k, config[k]) for k in config if valid_ident(k)]) try: result = factory(**kwargs) - except TypeError, te: + except TypeError as te: if "'stream'" not in str(te): raise # The argument name changed from strm to stream @@ -520,7 +520,7 @@ class DictConfigurator(BaseConfigurator): for h in handlers: try: logger.addHandler(self.config['handlers'][h]) - except StandardError, e: + except StandardError as e: raise ValueError('Unable to add handler %r: %s' % (h, e)) def common_logger_config(self, logger, config, incremental=False): diff --git a/ryu/tests/integrated/run_tests_with_ovs12.py b/ryu/tests/integrated/run_tests_with_ovs12.py index 6926964d..dc194c58 100755 --- a/ryu/tests/integrated/run_tests_with_ovs12.py +++ b/ryu/tests/integrated/run_tests_with_ovs12.py @@ -96,7 +96,7 @@ class TestWithOVS12(unittest.TestCase): time.sleep(1) continue - print "ryu-manager: %s" % line + print("ryu-manager: %s" % line) if line.find('TEST_FINISHED') != -1: ok_(line.find('Completed=[True]') != -1) p.terminate() diff --git a/ryu/tests/integrated/test_of_config.py b/ryu/tests/integrated/test_of_config.py index ad0aeca2..5a927655 100644 --- a/ryu/tests/integrated/test_of_config.py +++ b/ryu/tests/integrated/test_of_config.py @@ -262,7 +262,7 @@ class OFConfigClient(app_manager.RyuApp): def _set_ports_down(self): """try to set all ports down with etree operation""" tree = self._do_get() - print lxml.etree.tostring(tree, pretty_print=True) + print(lxml.etree.tostring(tree, pretty_print=True)) qname = lxml.etree.QName(tree.tag) ns = qname.namespace diff --git a/ryu/tests/integrated/vrrp_common.py b/ryu/tests/integrated/vrrp_common.py index 9650c339..fc1d40cc 100644 --- a/ryu/tests/integrated/vrrp_common.py +++ b/ryu/tests/integrated/vrrp_common.py @@ -40,7 +40,7 @@ class VRRPCommon(app_manager.RyuApp): def _main(self): self._main_version(vrrp.VRRP_VERSION_V3) self._main_version(vrrp.VRRP_VERSION_V2) - print "done!" + print("done!") def _main_version(self, vrrp_version): self._main_version_priority(vrrp_version, @@ -65,12 +65,15 @@ class VRRPCommon(app_manager.RyuApp): for i in rep.instance_list): continue break - print len(rep.instance_list), '/', len(instances) * 2 + print(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(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)) @@ -87,22 +90,22 @@ class VRRPCommon(app_manager.RyuApp): (vr[0].config.priority < vr[1].config.priority and 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("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) bad += 1 # assert i.state != vrrp_event.VRRP_STATE_MASTER if bad > 0: # this could be a transient state - print bad, "bad masters" + print(bad + " bad masters") time.sleep(1) continue if num_of_master >= len(instances): assert num_of_master == len(instances) break - print num_of_master, '/', len(instances) + print(num_of_master + ' / ' + len(instances)) time.sleep(1) continue @@ -116,7 +119,7 @@ class VRRPCommon(app_manager.RyuApp): for vrid in xrange(1, 256, step): if vrid == _VRID: continue - print "vrid", vrid + print("vrid " + vrid) l = {} prio = max(vrrp.VRRP_PRIORITY_BACKUP_MIN, min(vrrp.VRRP_PRIORITY_BACKUP_MAX, vrid)) @@ -138,7 +141,7 @@ class VRRPCommon(app_manager.RyuApp): l[1] = rep1 instances[vrid] = l - print "vrid", _VRID + print("vrid " + _VRID) l = {} rep0 = self._configure_vrrp_router(vrrp_version, priority, _PRIMARY_IP_ADDRESS0, @@ -155,8 +158,8 @@ class VRRPCommon(app_manager.RyuApp): self.logger.debug('%s', vrrp_mgr._instances) if do_sleep: - print "priority", priority - print "waiting for instances starting" + print("priority " + priority) + print("waiting for instances starting") self._check(vrrp_api, instances) @@ -172,7 +175,7 @@ class VRRPCommon(app_manager.RyuApp): i.config.priority = new_priority if do_sleep: - print "priority shuffled" + print("priority shuffled") self._check(vrrp_api, instances) @@ -184,15 +187,15 @@ class VRRPCommon(app_manager.RyuApp): vrrp_api.vrrp_shutdown(self, instances[_VRID][0].instance_name) if do_sleep: - print "shutting down instances" + print("shutting down instances") while True: rep = vrrp_api.vrrp_list(self) if len(rep.instance_list) <= len(instances): break - print "left", len(rep.instance_list) + print("left " + len(rep.instance_list)) time.sleep(1) assert len(rep.instance_list) == len(instances) - print "waiting for the rest becoming master" + print("waiting for the rest becoming master") while True: rep = vrrp_api.vrrp_list(self) if all(i.state == vrrp_event.VRRP_STATE_MASTER @@ -207,10 +210,10 @@ class VRRPCommon(app_manager.RyuApp): which = 1 - (vrid & 1) vrrp_api.vrrp_shutdown(self, instances[vrid][which].instance_name) - print "waiting for instances shutting down" + print("waiting for instances shutting down") while True: rep = vrrp_api.vrrp_list(self) if not rep.instance_list: break - print "left", len(rep.instance_list) + print("left " + len(rep.instance_list)) time.sleep(1) diff --git a/ryu/tests/switch/tester.py b/ryu/tests/switch/tester.py index 7ce4277f..ba52e52d 100644 --- a/ryu/tests/switch/tester.py +++ b/ryu/tests/switch/tester.py @@ -36,7 +36,7 @@ for modname, moddef in sys.modules.iteritems(): for (clsname, clsdef, ) in inspect.getmembers(moddef): if not inspect.isclass(clsdef): continue - exec 'from %s import %s' % (modname, clsname) + exec('from %s import %s' % (modname, clsname)) from ryu.base import app_manager from ryu.controller import handler diff --git a/ryu/tests/unit/app/test_tester.py b/ryu/tests/unit/app/test_tester.py index 0b80eb12..1248fa7a 100644 --- a/ryu/tests/unit/app/test_tester.py +++ b/ryu/tests/unit/app/test_tester.py @@ -41,7 +41,7 @@ for modname, moddef in sys.modules.iteritems(): for (clsname, clsdef, ) in inspect.getmembers(moddef): if not inspect.isclass(clsdef): continue - exec 'from %s import %s' % (modname, clsname) + exec('from %s import %s' % (modname, clsname)) from ryu.base import app_manager from ryu.controller import handler diff --git a/ryu/tests/unit/lib/test_ip.py b/ryu/tests/unit/lib/test_ip.py index 0b7b75f9..d8c3245d 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(val + ' ' + res) eq_(val, res) diff --git a/ryu/tests/unit/lib/test_rpc.py b/ryu/tests/unit/lib/test_rpc.py index 1c9bf711..2c435215 100644 --- a/ryu/tests/unit/lib/test_rpc.py +++ b/ryu/tests/unit/lib/test_rpc.py @@ -277,7 +277,7 @@ class Test_rpc(unittest.TestCase): try: c.call("err", [obj]) raise Exception("unexpected") - except rpc.RPCError, e: + except rpc.RPCError as e: assert e.get_value() == obj def test_0_call_error_notification(self): @@ -292,7 +292,7 @@ class Test_rpc(unittest.TestCase): try: c.call("err", [obj]) raise Exception("unexpected") - except rpc.RPCError, e: + except rpc.RPCError as e: assert e.get_value() == obj assert len(l) == 1 n = l.pop(0) diff --git a/ryu/tests/unit/lib/test_stringify.py b/ryu/tests/unit/lib/test_stringify.py index a0e87e18..33d118d9 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 " + 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 7cd461f1..76d023f1 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 ' + 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 cfa8da47..5a032557 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 ' + 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 67a568a2..c3fd42a9 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 ' + 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 b5f21dc6..8234378a 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 ' + f) binmsg = open(dir + f).read() msg, rest = bgp.BGPMessage.parser(binmsg) binmsg2 = msg.serialize()