Revert recent py3 changes under ryu/contrib
Revert recent py3 changes under ryu/contrib, namely parts of the following commits: - commite2dfdbf580
("Treatment was not enough") and - commit325c9ae9c3
("Syntax level compatibility with Python 3") Because: - Some of them are broken (stream.py) - Changes like these should go to upstream Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
30777ea1b9
commit
d4e8026aa8
@ -144,30 +144,30 @@ def _make_pidfile():
|
||||
global file_handle
|
||||
|
||||
file_handle = open(tmpfile, "w")
|
||||
except IOError as e:
|
||||
except IOError, e:
|
||||
_fatal("%s: create failed (%s)" % (tmpfile, e.strerror))
|
||||
|
||||
try:
|
||||
s = os.fstat(file_handle.fileno())
|
||||
except IOError as e:
|
||||
except IOError, e:
|
||||
_fatal("%s: fstat failed (%s)" % (tmpfile, e.strerror))
|
||||
|
||||
try:
|
||||
file_handle.write("%s\n" % pid)
|
||||
file_handle.flush()
|
||||
except OSError as e:
|
||||
except OSError, e:
|
||||
_fatal("%s: write failed: %s" % (tmpfile, e.strerror))
|
||||
|
||||
try:
|
||||
fcntl.lockf(file_handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except IOError as e:
|
||||
except IOError, 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 as e:
|
||||
except OSError, 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 as e:
|
||||
except OSError, 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 as e:
|
||||
except OSError, 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 as e:
|
||||
except OSError, e:
|
||||
sys.stderr.write("pipe failed: %s\n" % os.strerror(e.errno))
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
pid = os.fork()
|
||||
except OSError as e:
|
||||
except OSError, 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 as e:
|
||||
except OSError, 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 as e:
|
||||
except IOError, 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 as e:
|
||||
except IOError, 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 as e:
|
||||
except IOError, 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 as e:
|
||||
except IOError, e:
|
||||
vlog.warn("%s: read: %s" % (pidfile, e.strerror))
|
||||
error = -e.errno
|
||||
except ValueError:
|
||||
|
@ -186,7 +186,7 @@ class Idl:
|
||||
self._monitor_request_id = None
|
||||
self.__clear()
|
||||
self.__parse_update(msg.result)
|
||||
except error.Error as e:
|
||||
except error.Error, 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 as e:
|
||||
except error.Error, 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 as e:
|
||||
except error.Error, 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 as e:
|
||||
except error.Error, e:
|
||||
# XXX rate-limit
|
||||
vlog.err("attempting to write bad value to column %s (%s)"
|
||||
% (column_name, e))
|
||||
|
@ -90,7 +90,7 @@ def _unlink(file_):
|
||||
try:
|
||||
os.unlink(file_)
|
||||
return 0
|
||||
except OSError as e:
|
||||
except OSError, e:
|
||||
return e.errno
|
||||
|
||||
|
||||
|
@ -143,7 +143,7 @@ def from_file(name):
|
||||
def from_string(s):
|
||||
try:
|
||||
s = unicode(s, 'utf-8')
|
||||
except UnicodeDecodeError as e:
|
||||
except UnicodeDecodeError, 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)
|
||||
|
@ -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 as e:
|
||||
except error.Error, e:
|
||||
if not symtab:
|
||||
raise e
|
||||
try:
|
||||
|
@ -171,7 +171,7 @@ class Poller(object):
|
||||
try:
|
||||
events = self.poll.poll(self.timeout)
|
||||
self.__log_wakeup(events)
|
||||
except select.error as e:
|
||||
except select.error, e:
|
||||
# XXX rate-limit
|
||||
error, msg = e
|
||||
if error != errno.EINTR:
|
||||
|
@ -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 as e:
|
||||
except socket.error, 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 as e:
|
||||
except OSError, 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(), 0o700)
|
||||
os.fchmod(sock.fileno(), 0700)
|
||||
else:
|
||||
os.chmod("/dev/fd/%d" % sock.fileno(), 0o700)
|
||||
except OSError as e:
|
||||
os.chmod("/dev/fd/%d" % sock.fileno(), 0700)
|
||||
except OSError, e:
|
||||
pass
|
||||
if connect_path is not None:
|
||||
try:
|
||||
sock.connect(connect_path)
|
||||
except socket.error as e:
|
||||
except socket.error, e:
|
||||
if get_exception_errno(e) != errno.EINPROGRESS:
|
||||
raise
|
||||
return 0, sock
|
||||
except socket.error as e:
|
||||
except socket.error, 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 as e:
|
||||
except socket.error, 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 as e:
|
||||
except socket.error, e:
|
||||
if get_exception_errno(e) != errno.EINPROGRESS:
|
||||
raise
|
||||
return 0, sock
|
||||
except socket.error as e:
|
||||
except socket.error, 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 as e:
|
||||
except OSError, 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 as e:
|
||||
except OSError, e:
|
||||
return e.errno, bytes_written
|
||||
|
||||
|
||||
def set_nonblocking(sock):
|
||||
try:
|
||||
sock.setblocking(0)
|
||||
except socket.error as e:
|
||||
except socket.error, e:
|
||||
vlog.err("could not set nonblocking mode on socket: %s"
|
||||
% os.strerror(get_socket_error(e)))
|
||||
|
||||
|
@ -119,9 +119,8 @@ class Stream(object):
|
||||
raise NotImplementedError("This method must be overrided by subclass")
|
||||
|
||||
@staticmethod
|
||||
def open_block(args):
|
||||
def open_block((error, stream)):
|
||||
"""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.
|
||||
|
||||
@ -197,7 +196,7 @@ class Stream(object):
|
||||
|
||||
try:
|
||||
return (0, self.socket.recv(n))
|
||||
except socket.error as e:
|
||||
except socket.error, e:
|
||||
return (ovs.socket_util.get_exception_errno(e), "")
|
||||
|
||||
def send(self, buf):
|
||||
@ -219,7 +218,7 @@ class Stream(object):
|
||||
|
||||
try:
|
||||
return self.socket.send(buf)
|
||||
except socket.error as e:
|
||||
except socket.error, e:
|
||||
return -ovs.socket_util.get_exception_errno(e)
|
||||
|
||||
def run(self):
|
||||
@ -290,7 +289,7 @@ class PassiveStream(object):
|
||||
|
||||
try:
|
||||
sock.listen(10)
|
||||
except socket.error as e:
|
||||
except socket.error, e:
|
||||
vlog.err("%s: listen: %s" % (name, os.strerror(e.error)))
|
||||
sock.close()
|
||||
return e.error, None
|
||||
@ -318,7 +317,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 as e:
|
||||
except socket.error, e:
|
||||
error = ovs.socket_util.get_exception_errno(e)
|
||||
if error != errno.EAGAIN:
|
||||
# XXX rate-limit
|
||||
|
Loading…
Reference in New Issue
Block a user