From b4af9a40867beff8660612fe20d3838cb375f159 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 14 Oct 2015 10:54:20 +0200 Subject: [PATCH] blind review on list-operations added by 2to3: * some calls to list() were not needed * some where linked to map() and replaced by [ for ] * some constructions like for i in range(len(myiter)): were replaced by for item in myiter (and in rare cases together with enumerate) * sometimes for k in d.keys() -> for k in d: the plan is to will leave items() and values() and keys() in the code for both py2 and py3 ultimately, so no changes there in this commit --- examples/ccn_emu_live/dce.py | 2 +- examples/ccn_emu_live/dce_4_nodes_linear.py | 4 +- examples/ccn_emu_live/planetlab.py | 2 +- .../ccn_emu_live/planetlab_4_nodes_linear.py | 2 +- .../testing/ccncat_extended_ring_topo.py | 2 +- .../omf/testing/nepi_omf5_nitos_ccnring.py | 22 ++++---- .../testing/nepi_omf5_plexus_ccncat_linear.py | 50 +++++++++---------- examples/openvswitch/ovs_ping_3_switches.py | 4 +- examples/planetlab/update_fedora_repo.py | 2 +- src/nepi/data/processing/ccn/parser.py | 4 +- src/nepi/resources/linux/application.py | 2 +- src/nepi/resources/linux/node.py | 12 +++-- .../resources/linux/scripts/tunchannel.py | 3 +- src/nepi/resources/netns/netnswrapper.py | 1 + .../resources/netns/netnswrapper_debug.py | 5 +- src/nepi/resources/ns3/ns3base.py | 2 +- src/nepi/resources/ns3/ns3server.py | 2 +- src/nepi/resources/ns3/ns3wifimac.py | 1 + src/nepi/resources/ns3/ns3wrapper.py | 1 + src/nepi/resources/ns3/ns3wrapper_debug.py | 5 +- src/nepi/resources/omf/messages_6.py | 10 ++-- src/nepi/resources/omf/omf6_parser.py | 2 +- src/nepi/resources/omf/wilabt_node.py | 2 +- src/nepi/resources/planetlab/plcapi.py | 2 +- src/nepi/resources/planetlab/sfa_node.py | 4 +- src/nepi/util/environ.py | 2 +- src/nepi/util/execfuncs.py | 2 +- src/nepi/util/parsers/xml_parser.py | 4 +- src/nepi/util/sfaapi.py | 1 + src/nepi/util/sfarspec_proc.py | 2 +- src/nepi/util/sshfuncs.py | 2 +- 31 files changed, 83 insertions(+), 78 deletions(-) diff --git a/examples/ccn_emu_live/dce.py b/examples/ccn_emu_live/dce.py index b996ea47..326a33b0 100644 --- a/examples/ccn_emu_live/dce.py +++ b/examples/ccn_emu_live/dce.py @@ -162,7 +162,7 @@ def avg_interests(ec, run): ### Compute metric: Avg number of Interests seen per content name ### normalized by the number of nodes in the shortest path - content_name_count = len(list(content_names.values())) + content_name_count = len(content_names) nodes_in_shortest_path = len(shortest_path) - 1 metric = interest_count / (float(content_name_count) * float(nodes_in_shortest_path)) diff --git a/examples/ccn_emu_live/dce_4_nodes_linear.py b/examples/ccn_emu_live/dce_4_nodes_linear.py index 3a7221d7..799e4e40 100644 --- a/examples/ccn_emu_live/dce_4_nodes_linear.py +++ b/examples/ccn_emu_live/dce_4_nodes_linear.py @@ -46,7 +46,7 @@ def avg_interest_rtt(ec, run): # statistics on RTT rtts = [content_names[content_name]["rtt"] \ - for content_name in list(content_names.keys())] + for content_name in content_names] # sample mean and standard deviation sample = numpy.array(rtts) @@ -78,7 +78,7 @@ def post_process(ec, runs): low = numpy.array([float(m[1]) for m in metrics]) high = numpy.array([float(m[2]) for m in metrics]) error = [y - low, high - y] - x = list(range(1,runs + 1)) + x = range(1,runs + 1) # plot average RTT and confidence interval for each iteration pyplot.errorbar(x, y, yerr = error, fmt='o') diff --git a/examples/ccn_emu_live/planetlab.py b/examples/ccn_emu_live/planetlab.py index 4c8a4a3d..643f33ca 100644 --- a/examples/ccn_emu_live/planetlab.py +++ b/examples/ccn_emu_live/planetlab.py @@ -166,7 +166,7 @@ def avg_interests(ec, run): ### Compute metric: Avg number of Interests seen per content name ### normalized by the number of nodes in the shortest path - content_name_count = len(list(content_names.values())) + content_name_count = len(content_names) nodes_in_shortest_path = len(shortest_path) - 1 metric = interest_count / (float(content_name_count) * float(nodes_in_shortest_path)) diff --git a/examples/ccn_emu_live/planetlab_4_nodes_linear.py b/examples/ccn_emu_live/planetlab_4_nodes_linear.py index d2d9f4c8..12f81c1a 100644 --- a/examples/ccn_emu_live/planetlab_4_nodes_linear.py +++ b/examples/ccn_emu_live/planetlab_4_nodes_linear.py @@ -74,7 +74,7 @@ def avg_interest_rtt(ec, run): # statistics on RTT rtts = [content_names[content_name]["rtt"] \ - for content_name in list(content_names.keys())] + for content_name in content_names] # sample mean and standard deviation sample = numpy.array(rtts) diff --git a/examples/linux/testing/ccncat_extended_ring_topo.py b/examples/linux/testing/ccncat_extended_ring_topo.py index d16143a6..2e5cce81 100644 --- a/examples/linux/testing/ccncat_extended_ring_topo.py +++ b/examples/linux/testing/ccncat_extended_ring_topo.py @@ -213,7 +213,7 @@ if __name__ == '__main__': # Register a collector to automatically collect traces collector = add_collector(ec, "stderr") - for ccnd in list(ccnds.values()): + for ccnd in ccnds: ec.register_connection(collector, ccnd) # deploy all ResourceManagers diff --git a/examples/omf/testing/nepi_omf5_nitos_ccnring.py b/examples/omf/testing/nepi_omf5_nitos_ccnring.py index 7b9e09b6..680b2a70 100644 --- a/examples/omf/testing/nepi_omf5_nitos_ccnring.py +++ b/examples/omf/testing/nepi_omf5_nitos_ccnring.py @@ -176,23 +176,23 @@ if __name__ == '__main__': nodes = dict() chann = add_channel(ec, channel, xmpp_slice, xmpp_host) - for i in range(len(all_hosts)): - node = add_node(ec,all_hosts[i], xmpp_slice, xmpp_host) + for i, host in enumerate(all_hosts): + node = add_node(ec ,host, xmpp_slice, xmpp_host) iface = add_interface(ec, all_ip[i], xmpp_slice, xmpp_host) ec.register_connection(node, iface) ec.register_connection(iface, chann) - nodes[all_hosts[i]] = node + nodes[host] = node # CCN setup for the node ccnds = dict() ccnrs = dict() - for i in range(len(all_hosts)): - ccndstart = add_app(ec, nodes[all_hosts[i]], "#ccndstart", "ccndstart &", + for i, host in enumerate(all_hosts): + ccndstart = add_app(ec, nodes[host], "#ccndstart", "ccndstart &", env, xmpp_slice, xmpp_host) - ccnr = add_app(ec, nodes[all_hosts[i]], "#ccnr", "ccnr &", + ccnr = add_app(ec, nodes[host], "#ccnr", "ccnr &", env, xmpp_slice, xmpp_host) - ccnds[all_hosts[i]] = ccndstart - ccnrs[all_hosts[i]] = ccnr + ccnds[host] = ccndstart + ccnrs[host] = ccnr ec.register_condition(ccnr, ResourceAction.START, ccndstart, ResourceState.STARTED, "1s") # CCNDC setup @@ -226,9 +226,9 @@ if __name__ == '__main__': link = [l1u, l1d, l2u, l2d, l3u, l3d, l4u, l4d, l5u, l5d, b1u, b1d, b2u, b2d] # List of condition - for i in range(len(all_hosts)): - ec.register_condition(ccnrs[all_hosts[i]], ResourceAction.START, ccnds[all_hosts[i]], ResourceState.STARTED, "1s") - ec.register_condition(link, ResourceAction.START, ccnrs[all_hosts[i]], ResourceState.STARTED, "1s") + for host in all_hosts: + ec.register_condition(ccnrs[host], ResourceAction.START, ccnds[host], ResourceState.STARTED, "1s") + ec.register_condition(link, ResourceAction.START, ccnrs[host], ResourceState.STARTED, "1s") # Streaming Server pub = add_publish(ec, nodes[host5], movie, xmpp_slice, xmpp_host) diff --git a/examples/omf/testing/nepi_omf5_plexus_ccncat_linear.py b/examples/omf/testing/nepi_omf5_plexus_ccncat_linear.py index 2c2b4117..bb812ef5 100644 --- a/examples/omf/testing/nepi_omf5_plexus_ccncat_linear.py +++ b/examples/omf/testing/nepi_omf5_plexus_ccncat_linear.py @@ -166,12 +166,12 @@ if __name__ == '__main__': nodes = dict() chann = add_channel(ec, channel, xmpp_slice, xmpp_host) - for i in range(len(all_hosts)): - node = add_node(ec,all_hosts[i], xmpp_slice, xmpp_host) + for i, host in enumerate(all_hosts): + node = add_node(ec,host, xmpp_slice, xmpp_host) iface = add_interface(ec, all_ip[i], xmpp_slice, xmpp_host) ec.register_connection(node, iface) ec.register_connection(iface, chann) - nodes[all_hosts[i]] = node + nodes[host] = node #### CCN setup for the node ### ccnds = dict() @@ -213,28 +213,28 @@ if __name__ == '__main__': # Do the iperf iperfserv = dict() iperfclient = dict() - for i in range(len(all_hosts)): - perfserv = add_app(ec, nodes[all_hosts[i]], "#perfserv", "iperf -s > /opt/iperfserv.txt", + for i, host in enumerate(all_hosts): + perfserv = add_app(ec, nodes[host], "#perfserv", "iperf -s > /opt/iperfserv.txt", env, xmpp_slice, xmpp_host) - iperfclient[all_hosts[i]] = [] + iperfclient[host] = [] if i > 0: cmd = "iperf -c " + all_ip[i-1] + " > /opt/iperclient1.txt" - perfclient1 = add_app(ec, nodes[all_hosts[i]], "#perfclient1", cmd, + perfclient1 = add_app(ec, nodes[host], "#perfclient1", cmd, env, xmpp_slice, xmpp_host) - iperfclient[all_hosts[i]].append(perfclient1) + iperfclient[host].append(perfclient1) if i < (len(all_hosts)-1): cmd = "iperf -c " + all_ip[i+1] + " > /opt/iperclient2.txt" - perfclient2 = add_app(ec, nodes[all_hosts[i]], "#perfclient2", cmd, + perfclient2 = add_app(ec, nodes[host], "#perfclient2", cmd, env, xmpp_slice, xmpp_host) - iperfclient[all_hosts[i]].append(perfclient2) + iperfclient[host].append(perfclient2) - iperfserv[all_hosts[i]] = perfserv + iperfserv[host] = perfserv - for i in range(len(all_hosts)): - #ec.register_condition(iperfserv[all_hosts[i]], ResourceAction.START, link, ResourceState.STARTED, "2s") - for elt in iperfclient[all_hosts[i]]: - ec.register_condition(elt, ResourceAction.START, iperfserv[all_hosts[i]], ResourceState.STARTED, "3s") + for host in all_hosts: + #ec.register_condition(iperfserv[host], ResourceAction.START, link, ResourceState.STARTED, "2s") + for elt in iperfclient[host]: + ec.register_condition(elt, ResourceAction.START, iperfserv[host], ResourceState.STARTED, "3s") ## Streaming Server @@ -257,18 +257,18 @@ if __name__ == '__main__': ## ccndstop = add_app(ec, nodes[all_hosts[i]], "#ccndstop", "ccndstop", env, xmpp_slice, xmpp_host) ## ccndstops.append(ccndstop) perfkill = dict() - for i in range(len(all_hosts)): - kill = add_app(ec, nodes[all_hosts[i]], "#kill", "killall iperf", "", xmpp_slice, xmpp_host) - perfkill[all_hosts[i]] = kill + for host in all_hosts: + kill = add_app(ec, nodes[host], "#kill", "killall iperf", "", xmpp_slice, xmpp_host) + perfkill[host] = kill # Condition to stop and clean the experiment apps = [] - for i in range(len(all_hosts)): -# apps.append(ccnds[all_hosts[i]]) -# apps.append(ccnrs[all_hosts[i]]) - apps.append(iperfserv[all_hosts[i]]) - for elt in iperfclient[all_hosts[i]]: + for host in all_hosts: +# apps.append(ccnds[host]) +# apps.append(ccnrs[host]) + apps.append(iperfserv[host]) + for elt in iperfclient[host]: apps.append(elt) # apps += link #apps.append(pub) @@ -280,8 +280,8 @@ if __name__ == '__main__': # ec.register_condition(ccndstops + [killall], ResourceAction.STOP, ccndstops, ResourceState.STARTED, "1s") killall = [] - for i in range(len(all_hosts)): - killall.append(perfkill[all_hosts[i]]) + for host in all_hosts: + killall.append(perfkill[host]) ec.register_condition(killall, ResourceAction.START, apps, ResourceState.STOPPED, "1s") ec.register_condition(killall, ResourceAction.STOP, killall, ResourceState.STARTED, "1s") diff --git a/examples/openvswitch/ovs_ping_3_switches.py b/examples/openvswitch/ovs_ping_3_switches.py index ee22e1c4..510c9e66 100644 --- a/examples/openvswitch/ovs_ping_3_switches.py +++ b/examples/openvswitch/ovs_ping_3_switches.py @@ -236,7 +236,9 @@ for r1, (n1, ip1) in r2ip.items(): ec.deploy() -ec.wait_finished(list(apps.values())) +# py3: no need to transform into a list +# as wait_finished (wait in fact) will do it anyway +ec.wait_finished(apps.values()) # collect results for key, app in apps.items(): diff --git a/examples/planetlab/update_fedora_repo.py b/examples/planetlab/update_fedora_repo.py index 6bd99863..f4929fbc 100644 --- a/examples/planetlab/update_fedora_repo.py +++ b/examples/planetlab/update_fedora_repo.py @@ -67,7 +67,7 @@ pl_user = options.pl_user pl_password = options.pl_password hosts = options.hosts -hosts = list(map(str.strip, hosts.split(","))) +hosts = [host.strip() for host in hosts.split(",")] apps = [] ## Create the experiment controller diff --git a/src/nepi/data/processing/ccn/parser.py b/src/nepi/data/processing/ccn/parser.py index 582b8dda..ae2e18ce 100644 --- a/src/nepi/data/processing/ccn/parser.py +++ b/src/nepi/data/processing/ccn/parser.py @@ -281,7 +281,7 @@ def process_content_history(graph): fname = graph.node[nid]["history"] history = load_content_history(fname) - for content_name in list(history.keys()): + for content_name in history: hist = history[content_name] for (timestamp, message_type, nid1, nid2, nonce, size, line) in hist: @@ -334,7 +334,7 @@ def process_content_history(graph): # Compute the time elapsed between the time an interest is sent # in the consumer node and when the content is received back - for content_name in list(content_names.keys()): + for content_name in content_names: # order content and interest messages by timestamp content_names[content_name]["content"] = sorted( content_names[content_name]["content"]) diff --git a/src/nepi/resources/linux/application.py b/src/nepi/resources/linux/application.py index 2dcde66b..a496159e 100644 --- a/src/nepi/resources/linux/application.py +++ b/src/nepi/resources/linux/application.py @@ -398,7 +398,7 @@ class LinuxApplication(ResourceManager): if sources: self.info("Uploading sources ") - sources = list(map(str.strip, sources.split(";"))) + sources = [str.strip(source) for source in sources.split(";")] # Separate sources that should be downloaded from # the web, from sources that should be uploaded from diff --git a/src/nepi/resources/linux/node.py b/src/nepi/resources/linux/node.py index 7558475c..c10bc584 100644 --- a/src/nepi/resources/linux/node.py +++ b/src/nepi/resources/linux/node.py @@ -489,7 +489,8 @@ class LinuxNode(ResourceManager): # adding the avoided pids filtered above (avoid_kill) to allow users keep process # alive when using besides ssh connections kill_pids = set(pids_temp.items()) - set(pids.items()) - kill_pids = ' '.join(list(dict(kill_pids).keys())) + # py2/py3 : keep it simple + kill_pids = ' '.join(kill_pids) # removing pids from beside connections and its process kill_pids = kill_pids.split(' ') @@ -773,9 +774,9 @@ class LinuxNode(ResourceManager): src = f.name # If dst files should not be overwritten, check that the files do not - # exits already + # exist already if isinstance(src, str): - src = list(map(str.strip, src.split(";"))) + src = [s.strip() for s in src.split(";")] if overwrite == False: src = self.filter_existing_files(src, dst) @@ -1178,19 +1179,20 @@ class LinuxNode(ResourceManager): if len(src) > 1 else {dst: src[0]} command = [] - for d in list(dests.keys()): + for d in dests: command.append(" [ -f {dst} ] && echo '{dst}' ".format(dst=d) ) command = ";".join(command) (out, err), proc = self.execute(command, retry = 1, with_lock = True) - for d in list(dests.keys()): + for d in dests: if out.find(d) > -1: del dests[d] if not dests: return [] + # list(..) here added by 2to3 - leaving for safety return list(dests.values()) diff --git a/src/nepi/resources/linux/scripts/tunchannel.py b/src/nepi/resources/linux/scripts/tunchannel.py index 11c68afa..cca52059 100644 --- a/src/nepi/resources/linux/scripts/tunchannel.py +++ b/src/nepi/resources/linux/scripts/tunchannel.py @@ -37,8 +37,7 @@ import ctypes import time def ipfmt(ip): - ipbytes = list(map(ord,ip.decode("hex"))) - return '.'.join(map(str,ipbytes)) + return '.'.join(str(ord(x)) for x in ip.decode("hex")) tagtype = { '0806' : 'arp', diff --git a/src/nepi/resources/netns/netnswrapper.py b/src/nepi/resources/netns/netnswrapper.py index b7847ef4..f1fe4cd6 100644 --- a/src/nepi/resources/netns/netnswrapper.py +++ b/src/nepi/resources/netns/netnswrapper.py @@ -112,6 +112,7 @@ class NetNSWrapper(object): # If the result is an object (not a base value), # then keep track of the object a return the object # reference (newuuid) + # xxx the two instances of `int` are from 2to3 if not (result is None or type(result) in [ bool, float, int, str, int]): self._objects[newuuid] = result diff --git a/src/nepi/resources/netns/netnswrapper_debug.py b/src/nepi/resources/netns/netnswrapper_debug.py index 83a33cdb..4ebdc0fa 100644 --- a/src/nepi/resources/netns/netnswrapper_debug.py +++ b/src/nepi/resources/netns/netnswrapper_debug.py @@ -147,11 +147,10 @@ wrapper = NS3Wrapper() return pprint.pformat(value) def format_args(self, args): - fargs = list(map(self.format_value, args)) - return "[%s]" % ",".join(fargs) + return "[%s]" % ",".join(self.format_value(arg) for arg in args) def format_kwargs(self, kwargs): - fkwargs = ["%s: %s" % (self.format_value(k_w[0]), self.format_value(k_w[1])) for k_w in iter(kwargs.items())] + fkwargs = ["%s: %s" % (self.format_value(k), self.format_value(v)) for (k, v) in kwargs.items()] return "dict({%s})" % ",".join(fkwargs) diff --git a/src/nepi/resources/ns3/ns3base.py b/src/nepi/resources/ns3/ns3base.py index 47948490..26632e0b 100644 --- a/src/nepi/resources/ns3/ns3base.py +++ b/src/nepi/resources/ns3/ns3base.py @@ -81,7 +81,7 @@ class NS3Base(ResourceManager): return kwargs = dict() - for attr in list(self._attrs.values()): + for attr in self._attrs.values(): if not ( attr.has_flag(Flags.Construct) and attr.has_changed ): continue diff --git a/src/nepi/resources/ns3/ns3server.py b/src/nepi/resources/ns3/ns3server.py index ce6c8957..589e3d41 100644 --- a/src/nepi/resources/ns3/ns3server.py +++ b/src/nepi/resources/ns3/ns3server.py @@ -138,7 +138,7 @@ def recv_msg(conn): item = base64.b64decode(item).rstrip() return pickle.loads(item) - decoded = list(map(decode, msg.split("|"))) + decoded = [ decode(x) for x in msg.split("|") ] # decoded message dmsg_type = decoded.pop(0) diff --git a/src/nepi/resources/ns3/ns3wifimac.py b/src/nepi/resources/ns3/ns3wifimac.py index 04bd83a2..f3dd5cd1 100644 --- a/src/nepi/resources/ns3/ns3wifimac.py +++ b/src/nepi/resources/ns3/ns3wifimac.py @@ -29,6 +29,7 @@ class NS3BaseWifiMac(NS3Base): def _register_attributes(cls): standard = Attribute("Standard", "Wireless standard", default = "WIFI_PHY_STANDARD_80211a", + # staying safe with 2to3's generated list allowed = list(WIFI_STANDARDS.keys()), type = Types.Enumerate, flags = Flags.Design) diff --git a/src/nepi/resources/ns3/ns3wrapper.py b/src/nepi/resources/ns3/ns3wrapper.py index cea3afbd..dcaadeb5 100644 --- a/src/nepi/resources/ns3/ns3wrapper.py +++ b/src/nepi/resources/ns3/ns3wrapper.py @@ -326,6 +326,7 @@ class NS3Wrapper(object): # If the result is an object (not a base value), # then keep track of the object a return the object # reference (newuuid) + # xxx the two instances of `int` are from 2to3 if not (result is None or type(result) in [ bool, float, int, str, int]): self._objects[newuuid] = result diff --git a/src/nepi/resources/ns3/ns3wrapper_debug.py b/src/nepi/resources/ns3/ns3wrapper_debug.py index 75df9bc7..51f1fc7c 100644 --- a/src/nepi/resources/ns3/ns3wrapper_debug.py +++ b/src/nepi/resources/ns3/ns3wrapper_debug.py @@ -167,11 +167,10 @@ wrapper = NS3Wrapper() return pprint.pformat(value) def format_args(self, args): - fargs = list(map(self.format_value, args)) - return "[%s]" % ",".join(fargs) + return "[%s]" % ",".join(self.format_value(arg) for arg in args) def format_kwargs(self, kwargs): - fkwargs = ["%s: %s" % (self.format_value(k_w[0]), self.format_value(k_w[1])) for k_w in iter(kwargs.items())] + fkwargs = ["%s: %s" % (self.format_value(k), self.format_value(v)) for (k, v) in kwargs.items()] return "dict({%s})" % ",".join(fkwargs) diff --git a/src/nepi/resources/omf/messages_6.py b/src/nepi/resources/omf/messages_6.py index 49c9e9c3..b7f3044e 100644 --- a/src/nepi/resources/omf/messages_6.py +++ b/src/nepi/resources/omf/messages_6.py @@ -114,17 +114,17 @@ class MessageHandler(): else: properties = self._attr_element(payload,"props","") - for prop in list(props.keys()): + for prop in props: if isinstance(props[prop],str): self._attr_element(properties,prop,props[prop],type_key="type", type_value = "string") elif isinstance(props[prop],dict): key = self._attr_element(properties,prop,"",type_key="type", type_value = "hash") - for comp in list(props[prop].keys()): + for comp in props[prop]: self._attr_element(key,comp,props[prop][comp],type_key="type", type_value = "string") if guards : guardians = self._attr_element(payload,"guard","") - for guard in list(guards.keys()): + for guard in guards: self._attr_element(guardians,guard,guards[guard],type_key="type", type_value = "string") return payload @@ -149,12 +149,12 @@ class MessageHandler(): if props : properties = self._attr_element(payload,"props","") - for prop in list(props.keys()): + for prop in props: self._attr_element(properties,prop,props[prop],type_key="type", type_value = "symbol") if guards : guardians = self._attr_element(payload,"guard","") - for guard in list(guards.keys()): + for guard in guards: self._attr_element(guardians,guard,guards[guard],type_key="type", type_value = "string") return payload diff --git a/src/nepi/resources/omf/omf6_parser.py b/src/nepi/resources/omf/omf6_parser.py index 4ddd60ee..85aa394b 100644 --- a/src/nepi/resources/omf/omf6_parser.py +++ b/src/nepi/resources/omf/omf6_parser.py @@ -175,7 +175,7 @@ class OMF6Parser(Logger): event = self._check_for_tag(root, namespaces, "event") log = "STATUS -- " - for elt in list(props.keys()): + for elt in props: ns, tag = elt.split('}') if tag == "it": log = log + "membership : " + props[elt]+" -- " diff --git a/src/nepi/resources/omf/wilabt_node.py b/src/nepi/resources/omf/wilabt_node.py index 4513949e..8ce3e21e 100644 --- a/src/nepi/resources/omf/wilabt_node.py +++ b/src/nepi/resources/omf/wilabt_node.py @@ -407,7 +407,7 @@ class WilabtSfaNode(OMFNode): slice_nodes = self.sfaapi.get_slice_resources(slicename)['resource'] if slice_nodes: if len(slice_nodes[0]['services']) != 0: - slice_nodes_hrn = list(self.sfaapi.get_resources_hrn(slice_nodes).values()) + slice_nodes_hrn = self.sfaapi.get_resources_hrn(slice_nodes).values() else: slice_nodes_hrn = [] nodes_inslice = list(set(hosts_hrn) & set(slice_nodes_hrn)) return nodes_inslice diff --git a/src/nepi/resources/planetlab/plcapi.py b/src/nepi/resources/planetlab/plcapi.py index 23a898fb..61889670 100644 --- a/src/nepi/resources/planetlab/plcapi.py +++ b/src/nepi/resources/planetlab/plcapi.py @@ -343,7 +343,7 @@ class PLCAPI(object): filters = filters, peer=None, **kw) ) else: - peer_filter = list(map(name_to_id, peer)) + peer_filter = [name_to_id(x) for x in peer] elif peer is None or peer == self._local_peer: peer_filter = None diff --git a/src/nepi/resources/planetlab/sfa_node.py b/src/nepi/resources/planetlab/sfa_node.py index 9ca31811..4a8659d3 100644 --- a/src/nepi/resources/planetlab/sfa_node.py +++ b/src/nepi/resources/planetlab/sfa_node.py @@ -260,7 +260,7 @@ class PlanetlabSfaNode(LinuxNode): super(PlanetlabSfaNode, self).do_discover() else: - hosts_hrn = list(nodes.values()) + hosts_hrn = nodes.values() nodes_inslice = self._check_if_in_slice(hosts_hrn) nodes_not_inslice = list(set(hosts_hrn) - set(nodes_inslice)) host_hrn = None @@ -597,7 +597,7 @@ class PlanetlabSfaNode(LinuxNode): slicename = 'ple.' + slicename slice_nodes = self.sfaapi.get_slice_resources(slicename)['resource'] if slice_nodes: - slice_nodes_hrn = list(self.sfaapi.get_resources_hrn(slice_nodes).values()) + slice_nodes_hrn = self.sfaapi.get_resources_hrn(slice_nodes).values() else: slice_nodes_hrn = [] nodes_inslice = list(set(hosts_hrn) & set(slice_nodes_hrn)) return nodes_inslice diff --git a/src/nepi/util/environ.py b/src/nepi/util/environ.py index 101ad195..f8ec9cd4 100644 --- a/src/nepi/util/environ.py +++ b/src/nepi/util/environ.py @@ -164,7 +164,7 @@ def gen_sshd_config(filename, port, server_key, auth_keys): def gen_auth_keys(pubkey, output, environ): #opts = ['from="127.0.0.1/32"'] # fails in stupid yans setup opts = [] - for k, v in list(environ.items()): + for k, v in environ.items(): opts.append('environment="%s=%s"' % (k, v)) lines = file(pubkey).readlines() diff --git a/src/nepi/util/execfuncs.py b/src/nepi/util/execfuncs.py index 1cc4e05c..1f7b6b9b 100644 --- a/src/nepi/util/execfuncs.py +++ b/src/nepi/util/execfuncs.py @@ -179,7 +179,7 @@ def lgetpid(pidfile): if out: try: - return list(map(int,out.strip().split(' ',1))) + return [ int(x) for x in out.strip().split(' ',1))] except: # Ignore, many ways to fail that don't matter that much return None diff --git a/src/nepi/util/parsers/xml_parser.py b/src/nepi/util/parsers/xml_parser.py index 7a237366..b42d39ba 100644 --- a/src/nepi/util/parsers/xml_parser.py +++ b/src/nepi/util/parsers/xml_parser.py @@ -198,7 +198,7 @@ class ECXMLParser(object): anode = doc.createElement("attributes") attributes = False - for attr in list(rm._attrs.values()): + for attr in rm._attrs.values(): if attr.has_changed: attributes = True aanode = doc.createElement("attribute") @@ -241,7 +241,7 @@ class ECXMLParser(object): tnode = doc.createElement("traces") traces = False - for trace in list(rm._trcs.values()): + for trace in rm._trcs.values(): if trace.enabled: traces = True ttnode = doc.createElement("trace") diff --git a/src/nepi/util/sfaapi.py b/src/nepi/util/sfaapi.py index 345e9f17..2f81c100 100644 --- a/src/nepi/util/sfaapi.py +++ b/src/nepi/util/sfaapi.py @@ -303,6 +303,7 @@ class SFAAPI(object): slice_res = self.get_slice_resources(slicename)['resource'] if slice_res: if len(slice_res[0]['services']) != 0: + # 2to3 added list() and it is useful slice_res_hrn = list(self.get_resources_hrn(slice_res).values()) if self._compare_lists(slice_res_hrn, resources_hrn): return True diff --git a/src/nepi/util/sfarspec_proc.py b/src/nepi/util/sfarspec_proc.py index d5e07359..27dbbc0b 100644 --- a/src/nepi/util/sfarspec_proc.py +++ b/src/nepi/util/sfarspec_proc.py @@ -43,7 +43,7 @@ class SfaRSpecProcessing(object): return objcopy # We thus suppose we have a child of dict objcopy = {} - for k, v in list(obj.items()): + for k, v in obj.items(): objcopy[k] = self.make_dict_rec(v) return objcopy diff --git a/src/nepi/util/sshfuncs.py b/src/nepi/util/sshfuncs.py index 34d19a24..f33b9c6b 100644 --- a/src/nepi/util/sshfuncs.py +++ b/src/nepi/util/sshfuncs.py @@ -556,7 +556,7 @@ def rgetpid(pidfile, if out: try: - return list(map(int,out.strip().split(' ',1))) + return [ int(x) for x in out.strip().split(' ',1)) ] except: # Ignore, many ways to fail that don't matter that much return None -- 2.47.0