python: bulk replace dict.iteritems to items for py3
authorJoe Guo <joeg@catalyst.net.nz>
Tue, 10 Apr 2018 22:32:06 +0000 (10:32 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 13 Apr 2018 05:27:12 +0000 (07:27 +0200)
In py3, iterxxx methods are removed.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
12 files changed:
buildtools/wafsamba/samba_version.py
lib/tdb/python/tdbdump.py
python/samba/emulate/traffic.py
python/samba/graph.py
python/samba/netcmd/__init__.py
python/samba/netcmd/main.py
python/samba/netcmd/visualize.py
python/samba/provision/__init__.py
python/samba/tests/netcmd.py
selftest/subunithelper.py
source4/dsdb/tests/python/linked_attributes.py
source4/selftest/tests.py

index 950a855c1efceee416a0a79fc911bbd824ded697..be26439f1a6e667e35ce671916e6e806b3db54d1 100644 (file)
@@ -95,7 +95,7 @@ also accepted as dictionary entries here
         self.VENDOR_SUFFIX=None
         self.VENDOR_PATCH=None
 
         self.VENDOR_SUFFIX=None
         self.VENDOR_PATCH=None
 
-        for a, b in version_dict.iteritems():
+        for a, b in version_dict.items():
             if a.startswith("SAMBA_VERSION_"):
                 setattr(self, a[14:], b)
             else:
             if a.startswith("SAMBA_VERSION_"):
                 setattr(self, a[14:], b)
             else:
index a16d26ed52399b7b1d113ff1df8204a4630844a6..08769eaa3e55c342832bd44883d61209e8083914 100644 (file)
@@ -9,5 +9,5 @@ if len(sys.argv) < 2:
     sys.exit(1)
 
 db = tdb.Tdb(sys.argv[1])
     sys.exit(1)
 
 db = tdb.Tdb(sys.argv[1])
-for (k, v) in db.iteritems():
+for (k, v) in db.items():
     print("{\nkey(%d) = %r\ndata(%d) = %r\n}" % (len(k), k, len(v), v))
     print("{\nkey(%d) = %r\ndata(%d) = %r\n}" % (len(k), k, len(v), v))
index 240d0ebd26098d8b91bafbe3584f20253ee88bfc..0fb60b4c87b3ed8e7710922a140cd75941512139 100644 (file)
@@ -1065,7 +1065,7 @@ def guess_server_address(conversations):
 
 def stringify_keys(x):
     y = {}
 
 def stringify_keys(x):
     y = {}
-    for k, v in x.iteritems():
+    for k, v in x.items():
         k2 = '\t'.join(k)
         y[k2] = v
     return y
         k2 = '\t'.join(k)
         y[k2] = v
     return y
@@ -1073,7 +1073,7 @@ def stringify_keys(x):
 
 def unstringify_keys(x):
     y = {}
 
 def unstringify_keys(x):
     y = {}
-    for k, v in x.iteritems():
+    for k, v in x.items():
         t = tuple(str(k).split('\t'))
         y[t] = v
     return y
         t = tuple(str(k).split('\t'))
         y[t] = v
     return y
@@ -1133,12 +1133,12 @@ class TrafficModel(object):
 
     def save(self, f):
         ngrams = {}
 
     def save(self, f):
         ngrams = {}
-        for k, v in self.ngrams.iteritems():
+        for k, v in self.ngrams.items():
             k = '\t'.join(k)
             ngrams[k] = dict(Counter(v))
 
         query_details = {}
             k = '\t'.join(k)
             ngrams[k] = dict(Counter(v))
 
         query_details = {}
-        for k, v in self.query_details.iteritems():
+        for k, v in self.query_details.items():
             query_details[k] = dict(Counter('\t'.join(x) if x else '-'
                                             for x in v))
 
             query_details[k] = dict(Counter('\t'.join(x) if x else '-'
                                             for x in v))
 
@@ -1161,15 +1161,15 @@ class TrafficModel(object):
 
         d = json.load(f)
 
 
         d = json.load(f)
 
-        for k, v in d['ngrams'].iteritems():
+        for k, v in d['ngrams'].items():
             k = tuple(str(k).split('\t'))
             values = self.ngrams.setdefault(k, [])
             k = tuple(str(k).split('\t'))
             values = self.ngrams.setdefault(k, [])
-            for p, count in v.iteritems():
+            for p, count in v.items():
                 values.extend([str(p)] * count)
 
                 values.extend([str(p)] * count)
 
-        for k, v in d['query_details'].iteritems():
+        for k, v in d['query_details'].items():
             values = self.query_details.setdefault(str(k), [])
             values = self.query_details.setdefault(str(k), [])
-            for p, count in v.iteritems():
+            for p, count in v.items():
                 if p == '-':
                     values.extend([()] * count)
                 else:
                 if p == '-':
                     values.extend([()] * count)
                 else:
index f626287800d111c943f56da9c538dc49a93c0f64..3b8f61194f4ca0d6cc7e68416b268c57b87f1833 100644 (file)
@@ -129,7 +129,7 @@ def shorten_vertex_names(edges, vertices, suffix=',...', aggressive=False):
                 break
         else:
             map = dict((k, v.replace(',CN=Servers,', ',**,'))
                 break
         else:
             map = dict((k, v.replace(',CN=Servers,', ',**,'))
-                       for k, v in map.iteritems())
+                       for k, v in map.items())
             replacements.append(('**', 'CN=Servers'))
 
         for v in vertices2:
             replacements.append(('**', 'CN=Servers'))
 
         for v in vertices2:
@@ -137,7 +137,7 @@ def shorten_vertex_names(edges, vertices, suffix=',...', aggressive=False):
                 break
         else:
             map = dict((k, v.replace('CN=NTDS Settings,', '*,'))
                 break
         else:
             map = dict((k, v.replace('CN=NTDS Settings,', '*,'))
-                       for k, v in map.iteritems())
+                       for k, v in map.items())
             replacements.append(('*', 'CN=NTDS Settings'))
 
         edges2 = [(map.get(a, a), map.get(b, b)) for a, b in edges2]
             replacements.append(('*', 'CN=NTDS Settings'))
 
         edges2 = [(map.get(a, a), map.get(b, b)) for a, b in edges2]
@@ -463,11 +463,11 @@ def find_transitive_distance(vertices, edges):
     for i in range(inf):
         changed = False
         new_distances = {}
     for i in range(inf):
         changed = False
         new_distances = {}
-        for v, d in distances.iteritems():
+        for v, d in distances.items():
             new_d = d.copy()
             new_distances[v] = new_d
             new_d = d.copy()
             new_distances[v] = new_d
-            for dest, cost in d.iteritems():
-                for leaf, cost2 in distances[dest].iteritems():
+            for dest, cost in d.items():
+                for leaf, cost2 in distances[dest].items():
                     new_cost = cost + cost2
                     old_cost = d.get(leaf, inf)
                     if new_cost < old_cost:
                     new_cost = cost + cost2
                     old_cost = d.get(leaf, inf)
                     if new_cost < old_cost:
index 9037d033190fcc364b67803ec33ba22b7050c96b..77976780150b26655678fb67cc28209563846490 100644 (file)
@@ -130,7 +130,7 @@ class Command(object):
             prog=prog,epilog=epilog)
         parser.add_options(self.takes_options)
         optiongroups = {}
             prog=prog,epilog=epilog)
         parser.add_options(self.takes_options)
         optiongroups = {}
-        for name, optiongroup in self.takes_optiongroups.iteritems():
+        for name, optiongroup in self.takes_optiongroups.items():
             optiongroups[name] = optiongroup(parser)
             parser.add_option_group(optiongroups[name])
         return parser, optiongroups
             optiongroups[name] = optiongroup(parser)
             parser.add_option_group(optiongroups[name])
         return parser, optiongroups
index 3b56f1a724ed84488bd2dab8a6201d9ff4572968..40762fabdad802fcef76d2890b192a98864cdb97 100644 (file)
@@ -42,12 +42,10 @@ class cache_loader(dict):
         except KeyError:
             return default
 
         except KeyError:
             return default
 
-    def iteritems(self):
+    def items(self):
         for key in self:
             yield (key, self[key])
 
         for key in self:
             yield (key, self[key])
 
-    def items(self):
-        return list(self.iteritems())
 
 class cmd_sambatool(SuperCommand):
     """Main samba administration tool."""
 
 class cmd_sambatool(SuperCommand):
     """Main samba administration tool."""
index 3e5b9501e3a030bf9c8dde4600ae1858be2c3685..b983e1891a94d621ab9b269450df67595ee8c5b5 100644 (file)
@@ -178,7 +178,7 @@ def get_partition_maps(samdb):
     }
 
     long_to_short = {}
     }
 
     long_to_short = {}
-    for s, l in short_to_long.iteritems():
+    for s, l in short_to_long.items():
         long_to_short[l] = s
 
     return short_to_long, long_to_short
         long_to_short[l] = s
 
     return short_to_long, long_to_short
@@ -266,18 +266,18 @@ class cmd_reps(GraphCommand):
                 # get_reps_tables() returns two dictionaries mapping
                 # dns to NCReplica objects
                 c, n = remote_dsa.get_rep_tables()
                 # get_reps_tables() returns two dictionaries mapping
                 # dns to NCReplica objects
                 c, n = remote_dsa.get_rep_tables()
-                for part, rep in c.iteritems():
+                for part, rep in c.items():
                     if partition is None or part == partition:
                         nc_reps[part]['current'].append((dsa_dn, rep))
                     if partition is None or part == partition:
                         nc_reps[part]['current'].append((dsa_dn, rep))
-                for part, rep in n.iteritems():
+                for part, rep in n.items():
                     if partition is None or part == partition:
                         nc_reps[part]['needed'].append((dsa_dn, rep))
 
         all_edges = {'needed':  {'to': [], 'from': []},
                      'current': {'to': [], 'from': []}}
 
                     if partition is None or part == partition:
                         nc_reps[part]['needed'].append((dsa_dn, rep))
 
         all_edges = {'needed':  {'to': [], 'from': []},
                      'current': {'to': [], 'from': []}}
 
-        for partname, part in nc_reps.iteritems():
-            for state, edgelists in all_edges.iteritems():
+        for partname, part in nc_reps.items():
+            for state, edgelists in all_edges.items():
                 for dsa_dn, rep in part[state]:
                     short_name = long_partitions.get(partname, partname)
                     for r in rep.rep_repsFrom:
                 for dsa_dn, rep in part[state]:
                     short_name = long_partitions.get(partname, partname)
                     for r in rep.rep_repsFrom:
@@ -302,12 +302,12 @@ class cmd_reps(GraphCommand):
                 'from': "RepsFrom objects for %s",
                 'to': "RepsTo objects for %s",
             }
                 'from': "RepsFrom objects for %s",
                 'to': "RepsTo objects for %s",
             }
-            for state, edgelists in all_edges.iteritems():
-                for direction, items in edgelists.iteritems():
+            for state, edgelists in all_edges.items():
+                for direction, items in edgelists.items():
                     part_edges = defaultdict(list)
                     for src, dest, part in items:
                         part_edges[part].append((src, dest))
                     part_edges = defaultdict(list)
                     for src, dest, part in items:
                         part_edges[part].append((src, dest))
-                    for part, edges in part_edges.iteritems():
+                    for part, edges in part_edges.items():
                         s = distance_matrix(None, edges,
                                             utf8=utf8,
                                             colour=color_scheme,
                         s = distance_matrix(None, edges,
                                             utf8=utf8,
                                             colour=color_scheme,
@@ -324,8 +324,8 @@ class cmd_reps(GraphCommand):
         dot_vertices = set()
         used_colours = {}
         key_set = set()
         dot_vertices = set()
         used_colours = {}
         key_set = set()
-        for state, edgelist in all_edges.iteritems():
-            for direction, items in edgelist.iteritems():
+        for state, edgelist in all_edges.items():
+            for direction, items in edgelist.items():
                 for src, dest, part in items:
                     colour = used_colours.setdefault((part),
                                                      colour_hash((part,
                 for src, dest, part in items:
                     colour = used_colours.setdefault((part),
                                                      colour_hash((part,
@@ -472,7 +472,7 @@ class cmd_ntdsconn(GraphCommand):
                 source_denies = []
                 dest_denies = []
                 both_deny = []
                 source_denies = []
                 dest_denies = []
                 both_deny = []
-                for e, conn in edges.iteritems():
+                for e, conn in edges.items():
                     if conn.dest_attests:
                         graph_edges.append(e)
                         if not conn.src_attests:
                     if conn.dest_attests:
                         graph_edges.append(e)
                         if not conn.src_attests:
@@ -517,7 +517,7 @@ class cmd_ntdsconn(GraphCommand):
         edge_styles = []
         edge_labels = []
         n_servers = len(dsas)
         edge_styles = []
         edge_labels = []
         n_servers = len(dsas)
-        for k, e in sorted(edges.iteritems()):
+        for k, e in sorted(edges.items()):
             dot_edges.append(k)
             if e.observations == n_servers or not talk_to_remote:
                 edge_colours.append('#000000')
             dot_edges.append(k)
             if e.observations == n_servers or not talk_to_remote:
                 edge_colours.append('#000000')
@@ -573,6 +573,6 @@ class cmd_visualize(SuperCommand):
     """Produces graphical representations of Samba network state"""
     subcommands = {}
 
     """Produces graphical representations of Samba network state"""
     subcommands = {}
 
-    for k, v in globals().iteritems():
+    for k, v in globals().items():
         if k.startswith('cmd_'):
             subcommands[k[4:]] = v()
         if k.startswith('cmd_'):
             subcommands[k[4:]] = v()
index dcdb2b7bd207d68f50514e7ffe16540fa28038ac..1709e75184e74f3e1064f249dddb5ae2138b8aa3 100644 (file)
@@ -774,11 +774,11 @@ def make_smbconf(smbconf, hostname, domain, realm, targetdir,
     f = open(smbconf, 'w')
     try:
         f.write("[globals]\n")
     f = open(smbconf, 'w')
     try:
         f.write("[globals]\n")
-        for key, val in global_settings.iteritems():
+        for key, val in global_settings.items():
             f.write("\t%s = %s\n" % (key, val))
         f.write("\n")
 
             f.write("\t%s = %s\n" % (key, val))
         f.write("\n")
 
-        for name, path in shares.iteritems():
+        for name, path in shares.items():
             f.write("[%s]\n" % name)
             f.write("\tpath = %s\n" % path)
             f.write("\tread only = no\n")
             f.write("[%s]\n" % name)
             f.write("\tpath = %s\n" % path)
             f.write("\tread only = no\n")
index 54f05da35faa5bed674eb686eca3eea93899e72e..2867c031a175d90fe5564186482ffb44776a6a5a 100644 (file)
@@ -36,14 +36,13 @@ class NetCmdTestCase(samba.tests.TestCase):
         return cmd.outf.getvalue(), cmd.errf.getvalue()
 
     def iter_all_subcommands(self):
         return cmd.outf.getvalue(), cmd.errf.getvalue()
 
     def iter_all_subcommands(self):
-        todo = []
-        todo.extend(cmd_sambatool.subcommands.items())
+        todo = list(cmd_sambatool.subcommands.items())
         while todo:
             (path, cmd) = todo.pop()
             yield path, cmd
             subcmds = getattr(cmd, "subcommands", {})
             todo.extend([(path + " " + k, v) for (k, v) in
         while todo:
             (path, cmd) = todo.pop()
             yield path, cmd
             subcmds = getattr(cmd, "subcommands", {})
             todo.extend([(path + " " + k, v) for (k, v) in
-                subcmds.iteritems()])
+                subcmds.items()])
 
 
 class TestParmTests(NetCmdTestCase):
 
 
 class TestParmTests(NetCmdTestCase):
index 9755f926d4ff1b48bf1d75fc1b29cee0029b3872..f20f3fe8ba735216171190444527223feea8a359 100644 (file)
@@ -262,7 +262,7 @@ def read_test_regexes(*names):
 
 
 def find_in_list(regexes, fullname):
 
 
 def find_in_list(regexes, fullname):
-    for regex, reason in regexes.iteritems():
+    for regex, reason in regexes.items():
         if re.match(regex, fullname):
             if reason is None:
                 return ""
         if re.match(regex, fullname):
             if reason is None:
                 return ""
index d40192badc7a427d37277376f7fc9fad2a726628..8586fb8152881d494b315d5359db659bb43c7489 100644 (file)
@@ -173,7 +173,7 @@ class LATests(samba.tests.TestCase):
         except ldb.LdbError as e:
             (num, msg) = e.args
             if num != errcode:
         except ldb.LdbError as e:
             (num, msg) = e.args
             if num != errcode:
-                lut = {v: k for k, v in vars(ldb).iteritems()
+                lut = {v: k for k, v in vars(ldb).items()
                        if k.startswith('ERR_') and isinstance(v, int)}
                 self.fail("%s, expected "
                           "LdbError %s, (%d) "
                        if k.startswith('ERR_') and isinstance(v, int)}
                 self.fail("%s, expected "
                           "LdbError %s, (%d) "
@@ -181,7 +181,7 @@ class LATests(samba.tests.TestCase):
                                            lut.get(errcode), errcode,
                                            lut.get(num), num))
         else:
                                            lut.get(errcode), errcode,
                                            lut.get(num), num))
         else:
-            lut = {v: k for k, v in vars(ldb).iteritems()
+            lut = {v: k for k, v in vars(ldb).items()
                    if k.startswith('ERR_') and isinstance(v, int)}
             self.fail("%s, expected "
                       "LdbError %s, (%d) "
                    if k.startswith('ERR_') and isinstance(v, int)}
             self.fail("%s, expected "
                       "LdbError %s, (%d) "
index 92231cbd259a671b1f8575775639b4f3398a4b46..f86623ab0b51adc3c412f4b29804a98f26ea2670 100755 (executable)
@@ -563,7 +563,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex
     py_path = list(extra_path)
     if py_path:
         environ["PYTHONPATH"] = ":".join(["$PYTHONPATH"] + py_path)
     py_path = list(extra_path)
     if py_path:
         environ["PYTHONPATH"] = ":".join(["$PYTHONPATH"] + py_path)
-    args = ["%s=%s" % item for item in environ.iteritems()]
+    args = ["%s=%s" % item for item in environ.items()]
     args += [subunitrun, "$LISTOPT", "$LOADLIST", module]
     args += extra_args
     if name is None:
     args += [subunitrun, "$LISTOPT", "$LOADLIST", module]
     args += extra_args
     if name is None: