On Tue, Jan 12, 2016 at 02:45:47PM -0500, Russell Bryant wrote: > In Python 2, dict.items(), dict.keys(), and dict.values() returned a > list. dict.iteritems(), dict.iterkeys(), and dict.itervalues() returned > an iterator. > > As of Python 3, dict.iteritems(), dict.itervalues(), and dict.iterkeys() > are gone. items(), keys(), and values() now return an iterator. > > In the case where we want an iterator, we now use the six.iter*() > helpers. If we want a list, we explicitly create a list from the > iterator. > > Signed-off-by: Russell Bryant <russ...@ovn.org>
Here, I wonder whether it's safe (before or after the patch) to iterate through 'interfaces' while we're modifying it; some hash tables wouldn't respond well to that: > def update_ipsec(ipsec, interfaces, new_interfaces): > - for name, vals in interfaces.iteritems(): > + for name, vals in six.iteritems(interfaces): > if name not in new_interfaces: > ipsec.del_entry(vals["local_ip"], vals["remote_ip"]) > > - for name, vals in new_interfaces.iteritems(): > + for name, vals in six.iteritems(new_interfaces): > orig_vals = interfaces.get(name) > if orig_vals: > # Configuration for this host already exists. Check if it's Here, we might as well just use plain values() since there can be at most one record in this table: > def get_ssl_cert(data): > - for ovs_rec in data["Open_vSwitch"].rows.itervalues(): > + for ovs_rec in six.itervalues(data["Open_vSwitch"].rows): > if ovs_rec.ssl: > ssl = ovs_rec.ssl[0] > if ssl.certificate and ssl.private_key: Here, it seems like there ought to be better ways to get the first value out of an iterator than to convert the whole thing to a list and then take the first element: > @@ -398,10 +400,10 @@ class Datum(object): > def as_scalar(self): > if len(self.values) == 1: > if self.type.is_map(): > - k, v = self.values.iteritems()[0] > + k, v = list(six.iteritems(self.values))[0] > return [k.value, v.value] > else: > - return self.values.keys()[0].value > + return list(self.values.keys())[0].value > else: > return None Same here, in xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync: > @@ -84,7 +85,7 @@ def get_network_by_bridge(br_name): > recs = session.xenapi.network.get_all_records_where( > 'field "bridge"="%s"' % br_name) > if len(recs) > 0: > - return recs.values()[0] > + return list(recs.values())[0] > > return None > Thanks, Ben. _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev