Commit 093a0a1a authored by Tom Niget's avatar Tom Niget

run modernize

parent 3f7c5715
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
......@@ -24,6 +24,7 @@ and run and test programs in them.
"""
# pylint: disable=W0401,R0903
from __future__ import absolute_import
import os, pwd
from nemu.node import *
from nemu.interface import *
......
......@@ -17,8 +17,10 @@
# You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import errno, os, os.path, socket, subprocess, sys, syslog
from syslog import LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG
from six.moves import range
__all__ = ["IP_PATH", "TC_PATH", "BRCTL_PATH", "SYSCTL_PATH", "HZ"]
......@@ -110,11 +112,11 @@ def eintr_wrapper(func, *args):
while True:
try:
return func(*args)
except OSError, ex: # pragma: no cover
except OSError as ex: # pragma: no cover
if ex.errno == errno.EINTR:
continue
raise
except IOError, ex: # pragma: no cover
except IOError as ex: # pragma: no cover
if ex.errno == errno.EINTR:
continue
raise
......
......@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import os, weakref
import nemu.iproute
from nemu.environ import *
......@@ -505,6 +506,6 @@ class Switch(ExternalInterface):
self._parameters = parameters
def _apply_parameters(self, parameters, port = None):
for i in [port] if port else self._ports.values():
for i in [port] if port else list(self._ports.values()):
nemu.iproute.set_tc(i.index, **parameters)
......@@ -17,8 +17,10 @@
# You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import copy, fcntl, os, re, socket, struct, subprocess, sys
from nemu.environ import *
import six
# helpers
def _any_to_bool(any):
......@@ -361,7 +363,7 @@ def create_if_pair(if1, if2):
del_if(if2)
except:
pass
raise t, v, bt
six.reraise(t, v, bt)
interfaces = get_if_data()[1]
return interfaces[if1.name], interfaces[if2.name]
......@@ -511,7 +513,7 @@ def set_addr(iface, addresses, recover = True):
# Bridge handling
def _sysfs_read_br(brname):
def readval(fname):
f = file(fname)
f = open(fname)
return f.readline().strip()
p = "/sys/class/net/%s/bridge/" % brname
......@@ -565,7 +567,7 @@ def create_bridge(br):
del_bridge(br)
except:
pass
raise t, v, bt
six.reraise(t, v, bt)
return get_if_data()[1][br.name]
def del_bridge(br):
......@@ -574,7 +576,7 @@ def del_bridge(br):
def set_bridge(br, recover = True):
def saveval(fname, val):
f = file(fname, "w")
f = open(fname, "w")
f.write(str(val))
f.close()
def do_cmds(basename, cmds, orig_br):
......
......@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import os, socket, sys, traceback, unshare, weakref
from nemu.environ import *
import nemu.interface, nemu.protocol, nemu.subprocess_
......@@ -28,7 +29,7 @@ class Node(object):
_nextnode = 0
@staticmethod
def get_nodes():
s = sorted(Node._nodes.items(), key = lambda x: x[0])
s = sorted(list(Node._nodes.items()), key = lambda x: x[0])
return [x[1] for x in s]
def __init__(self, nonetns = False, forward_X11 = False):
......@@ -157,7 +158,7 @@ class Node(object):
self._interfaces[i].destroy()
del self._interfaces[i]
return sorted(self._interfaces.values(), key = lambda x: x.index)
return sorted(list(self._interfaces.values()), key = lambda x: x.index)
def route(self, tipe = 'unicast', prefix = None, prefix_len = 0,
nexthop = None, interface = None, metric = 0):
......@@ -206,7 +207,7 @@ def _start_child(nonetns):
execute([SYSCTL_PATH, '-w', 'net.ipv4.ip_forward=1'])
execute([SYSCTL_PATH, '-w', 'net.ipv6.conf.default.forwarding=1'])
srv.run()
except BaseException, e:
except BaseException as e:
s = "Slave node aborting: %s\n" % str(e)
sep = "=" * 70 + "\n"
sys.stderr.write(s + sep)
......
......@@ -17,13 +17,16 @@
# You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import base64, errno, os, passfd, re, select, signal, socket, sys, tempfile
import time, traceback, unshare
import nemu.subprocess_, nemu.iproute
from nemu.environ import *
from six.moves import map
from six.moves import range
try:
from cPickle import loads, dumps
from six.moves.cPickle import loads, dumps
except:
from pickle import loads, dumps
......@@ -121,7 +124,7 @@ class Server(object):
try:
if nemu.subprocess_.poll(pid):
self._children.remove(pid)
except OSError, e:
except OSError as e:
if e.errno == errno.ECHILD:
self._children.remove(pid)
else:
......@@ -137,7 +140,7 @@ class Server(object):
for pid in self._children:
try:
nemu.subprocess_.poll(pid)
except OSError, e:
except OSError as e:
if e.errno != errno.ECHILD:
raise
finally:
......@@ -172,7 +175,7 @@ class Server(object):
while True:
try:
line = self._rfd.readline()
except IOError, e:
except IOError as e:
line = None
if e.errno == errno.EINTR:
continue
......@@ -202,7 +205,7 @@ class Server(object):
cmd2 = None
subcommands = self._commands[cmd1]
if subcommands.keys() != [ None ]:
if list(subcommands.keys()) != [ None ]:
if len(args) < 1:
self.reply(500, "Incomplete command.")
return None
......@@ -331,7 +334,7 @@ class Server(object):
cmdname)
try:
fd, payload = passfd.recvfd(self._rfd, len(cmdname) + 1)
except (IOError, RuntimeError), e:
except (IOError, RuntimeError) as e:
self.reply(500, "Error receiving FD: %s" % str(e))
return
......@@ -374,7 +377,7 @@ class Server(object):
params['env']['DISPLAY'] = "127.0.0.1:%d" % display
params['env']['XAUTHORITY'] = xauth
except Exception, e:
except Exception as e:
warning("Cannot forward X: %s" % e)
try:
os.unlink(xauth)
......@@ -804,8 +807,8 @@ def _b64(text):
# easier this way
text = ''
text = str(text)
if len(text) == 0 or filter(lambda x: ord(x) <= ord(" ") or
ord(x) > ord("z") or x == "=", text):
if len(text) == 0 or [x for x in text if ord(x) <= ord(" ") or
ord(x) > ord("z") or x == "="]:
return "=" + base64.b64encode(text)
else:
return text
......@@ -908,7 +911,7 @@ def _x11_forwarder(server, xsock, xaddr):
chan = idx[fd]
try:
s = os.read(fd.fileno(), 4096)
except OSError, e:
except OSError as e:
if e.errno == errno.ECONNRESET:
clean(idx, toread, fd)
continue
......@@ -934,7 +937,7 @@ def _x11_forwarder(server, xsock, xaddr):
chan = idx[idx[fd]["wr"]]
try:
x = os.write(fd.fileno(), chan["buf"][0])
except OSError, e:
except OSError as e:
if e.errno == errno.EINTR:
continue
if e.errno == errno.EPIPE or e.errno == errno.ECONNRESET:
......
......@@ -17,8 +17,10 @@
# You should have received a copy of the GNU General Public License along with
# Nemu. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
import fcntl, grp, os, pickle, pwd, signal, select, sys, time, traceback
from nemu.environ import eintr_wrapper
from six.moves import range
__all__ = [ 'PIPE', 'STDOUT', 'Popen', 'Subprocess', 'spawn', 'wait', 'poll',
'get_user', 'system', 'backticks', 'backticks_raise' ]
......@@ -288,7 +290,7 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
is not supported here. Also, the original descriptors are not closed.
"""
userfd = [stdin, stdout, stderr]
filtered_userfd = filter(lambda x: x != None and x >= 0, userfd)
filtered_userfd = [x for x in userfd if x != None and x >= 0]
for i in range(3):
if userfd[i] != None and not isinstance(userfd[i], int):
userfd[i] = userfd[i].fileno() # pragma: no cover
......@@ -323,7 +325,7 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
fcntl.fcntl(w, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
if close_fds == True:
for i in xrange(3, MAXFD):
for i in range(3, MAXFD):
if i != w:
try:
os.close(i)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment