Commit f3b52875 authored by Joe Guo's avatar Joe Guo Committed by Douglas Bagnall

python: bulk replace dict.iteritems to items for py3

In py3, iterxxx methods are removed.
Signed-off-by: default avatarJoe Guo <joeg@catalyst.net.nz>
Reviewed-by: default avatarAndrew Bartlett <abartlet@samba.org>
Reviewed-by: default avatarDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
parent 6716971c
......@@ -95,7 +95,7 @@ also accepted as dictionary entries here
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:
......
......@@ -9,5 +9,5 @@ if len(sys.argv) < 2:
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))
......@@ -1065,7 +1065,7 @@ def guess_server_address(conversations):
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
......@@ -1073,7 +1073,7 @@ def stringify_keys(x):
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
......@@ -1133,12 +1133,12 @@ class TrafficModel(object):
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 = {}
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))
......@@ -1161,15 +1161,15 @@ class TrafficModel(object):
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, [])
for p, count in v.iteritems():
for p, count in v.items():
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), [])
for p, count in v.iteritems():
for p, count in v.items():
if p == '-':
values.extend([()] * count)
else:
......
......@@ -129,7 +129,7 @@ def shorten_vertex_names(edges, vertices, suffix=',...', aggressive=False):
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:
......@@ -137,7 +137,7 @@ def shorten_vertex_names(edges, vertices, suffix=',...', aggressive=False):
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]
......@@ -463,11 +463,11 @@ def find_transitive_distance(vertices, edges):
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
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:
......
......@@ -130,7 +130,7 @@ class Command(object):
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
......
......@@ -42,12 +42,10 @@ class cache_loader(dict):
except KeyError:
return default
def iteritems(self):
def items(self):
for key in self:
yield (key, self[key])
def items(self):
return list(self.iteritems())
class cmd_sambatool(SuperCommand):
"""Main samba administration tool."""
......
......@@ -178,7 +178,7 @@ def get_partition_maps(samdb):
}
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
......@@ -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()
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))
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': []}}
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:
......@@ -302,12 +302,12 @@ class cmd_reps(GraphCommand):
'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))
for part, edges in part_edges.iteritems():
for part, edges in part_edges.items():
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()
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,
......@@ -472,7 +472,7 @@ class cmd_ntdsconn(GraphCommand):
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:
......@@ -517,7 +517,7 @@ class cmd_ntdsconn(GraphCommand):
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')
......@@ -573,6 +573,6 @@ class cmd_visualize(SuperCommand):
"""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()
......@@ -774,11 +774,11 @@ def make_smbconf(smbconf, hostname, domain, realm, targetdir,
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")
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")
......
......@@ -36,14 +36,13 @@ class NetCmdTestCase(samba.tests.TestCase):
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
subcmds.iteritems()])
subcmds.items()])
class TestParmTests(NetCmdTestCase):
......
......@@ -262,7 +262,7 @@ def read_test_regexes(*names):
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 ""
......
......@@ -173,7 +173,7 @@ class LATests(samba.tests.TestCase):
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) "
......@@ -181,7 +181,7 @@ class LATests(samba.tests.TestCase):
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) "
......
......@@ -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)
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:
......
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