1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

python: bulk replace dict.iteritems to items for py3

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>
This commit is contained in:
Joe Guo 2018-04-11 10:32:06 +12:00 committed by Douglas Bagnall
parent 6716971ce1
commit f3b5287538
12 changed files with 38 additions and 41 deletions

View File

@ -95,7 +95,7 @@ also accepted as dictionary entries here
self.VENDOR_SUFFIX=None self.VENDOR_SUFFIX=None
self.VENDOR_PATCH=None self.VENDOR_PATCH=None
for a, b in version_dict.iteritems(): for a, b in version_dict.items():
if a.startswith("SAMBA_VERSION_"): if a.startswith("SAMBA_VERSION_"):
setattr(self, a[14:], b) setattr(self, a[14:], b)
else: else:

View File

@ -9,5 +9,5 @@ if len(sys.argv) < 2:
sys.exit(1) sys.exit(1)
db = tdb.Tdb(sys.argv[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))

View File

@ -1065,7 +1065,7 @@ def guess_server_address(conversations):
def stringify_keys(x): def stringify_keys(x):
y = {} y = {}
for k, v in x.iteritems(): for k, v in x.items():
k2 = '\t'.join(k) k2 = '\t'.join(k)
y[k2] = v y[k2] = v
return y return y
@ -1073,7 +1073,7 @@ def stringify_keys(x):
def unstringify_keys(x): def unstringify_keys(x):
y = {} y = {}
for k, v in x.iteritems(): for k, v in x.items():
t = tuple(str(k).split('\t')) t = tuple(str(k).split('\t'))
y[t] = v y[t] = v
return y return y
@ -1133,12 +1133,12 @@ class TrafficModel(object):
def save(self, f): def save(self, f):
ngrams = {} ngrams = {}
for k, v in self.ngrams.iteritems(): for k, v in self.ngrams.items():
k = '\t'.join(k) k = '\t'.join(k)
ngrams[k] = dict(Counter(v)) ngrams[k] = dict(Counter(v))
query_details = {} 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 '-' query_details[k] = dict(Counter('\t'.join(x) if x else '-'
for x in v)) 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')) k = tuple(str(k).split('\t'))
values = self.ngrams.setdefault(k, []) 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 == '-': if p == '-':
values.extend([()] * count) values.extend([()] * count)
else: else:

View File

@ -129,7 +129,7 @@ def shorten_vertex_names(edges, vertices, suffix=',...', aggressive=False):
break break
else: else:
map = dict((k, v.replace(',CN=Servers,', ',**,')) map = dict((k, v.replace(',CN=Servers,', ',**,'))
for k, v in map.iteritems()) for k, v in map.items())
replacements.append(('**', 'CN=Servers')) replacements.append(('**', 'CN=Servers'))
for v in vertices2: for v in vertices2:
@ -137,7 +137,7 @@ def shorten_vertex_names(edges, vertices, suffix=',...', aggressive=False):
break break
else: else:
map = dict((k, v.replace('CN=NTDS Settings,', '*,')) 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')) replacements.append(('*', 'CN=NTDS Settings'))
edges2 = [(map.get(a, a), map.get(b, b)) for a, b in edges2] 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): for i in range(inf):
changed = False changed = False
new_distances = {} new_distances = {}
for v, d in distances.iteritems(): for v, d in distances.items():
new_d = d.copy() new_d = d.copy()
new_distances[v] = new_d new_distances[v] = new_d
for dest, cost in d.iteritems(): for dest, cost in d.items():
for leaf, cost2 in distances[dest].iteritems(): for leaf, cost2 in distances[dest].items():
new_cost = cost + cost2 new_cost = cost + cost2
old_cost = d.get(leaf, inf) old_cost = d.get(leaf, inf)
if new_cost < old_cost: if new_cost < old_cost:

View File

@ -130,7 +130,7 @@ class Command(object):
prog=prog,epilog=epilog) prog=prog,epilog=epilog)
parser.add_options(self.takes_options) parser.add_options(self.takes_options)
optiongroups = {} optiongroups = {}
for name, optiongroup in self.takes_optiongroups.iteritems(): for name, optiongroup in self.takes_optiongroups.items():
optiongroups[name] = optiongroup(parser) optiongroups[name] = optiongroup(parser)
parser.add_option_group(optiongroups[name]) parser.add_option_group(optiongroups[name])
return parser, optiongroups return parser, optiongroups

View File

@ -42,12 +42,10 @@ class cache_loader(dict):
except KeyError: except KeyError:
return default return default
def iteritems(self): def items(self):
for key in self: for key in self:
yield (key, self[key]) yield (key, self[key])
def items(self):
return list(self.iteritems())
class cmd_sambatool(SuperCommand): class cmd_sambatool(SuperCommand):
"""Main samba administration tool.""" """Main samba administration tool."""

View 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 long_to_short[l] = s
return short_to_long, long_to_short return short_to_long, long_to_short
@ -266,18 +266,18 @@ class cmd_reps(GraphCommand):
# get_reps_tables() returns two dictionaries mapping # get_reps_tables() returns two dictionaries mapping
# dns to NCReplica objects # dns to NCReplica objects
c, n = remote_dsa.get_rep_tables() 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: if partition is None or part == partition:
nc_reps[part]['current'].append((dsa_dn, rep)) 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: if partition is None or part == partition:
nc_reps[part]['needed'].append((dsa_dn, rep)) nc_reps[part]['needed'].append((dsa_dn, rep))
all_edges = {'needed': {'to': [], 'from': []}, all_edges = {'needed': {'to': [], 'from': []},
'current': {'to': [], 'from': []}} 'current': {'to': [], 'from': []}}
for partname, part in nc_reps.iteritems(): for partname, part in nc_reps.items():
for state, edgelists in all_edges.iteritems(): for state, edgelists in all_edges.items():
for dsa_dn, rep in part[state]: for dsa_dn, rep in part[state]:
short_name = long_partitions.get(partname, partname) short_name = long_partitions.get(partname, partname)
for r in rep.rep_repsFrom: for r in rep.rep_repsFrom:
@ -302,12 +302,12 @@ class cmd_reps(GraphCommand):
'from': "RepsFrom objects for %s", 'from': "RepsFrom objects for %s",
'to': "RepsTo objects for %s", 'to': "RepsTo objects for %s",
} }
for state, edgelists in all_edges.iteritems(): for state, edgelists in all_edges.items():
for direction, items in edgelists.iteritems(): for direction, items in edgelists.items():
part_edges = defaultdict(list) part_edges = defaultdict(list)
for src, dest, part in items: for src, dest, part in items:
part_edges[part].append((src, dest)) 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, s = distance_matrix(None, edges,
utf8=utf8, utf8=utf8,
colour=color_scheme, colour=color_scheme,
@ -324,8 +324,8 @@ class cmd_reps(GraphCommand):
dot_vertices = set() dot_vertices = set()
used_colours = {} used_colours = {}
key_set = set() key_set = set()
for state, edgelist in all_edges.iteritems(): for state, edgelist in all_edges.items():
for direction, items in edgelist.iteritems(): for direction, items in edgelist.items():
for src, dest, part in items: for src, dest, part in items:
colour = used_colours.setdefault((part), colour = used_colours.setdefault((part),
colour_hash((part, colour_hash((part,
@ -472,7 +472,7 @@ class cmd_ntdsconn(GraphCommand):
source_denies = [] source_denies = []
dest_denies = [] dest_denies = []
both_deny = [] both_deny = []
for e, conn in edges.iteritems(): for e, conn in edges.items():
if conn.dest_attests: if conn.dest_attests:
graph_edges.append(e) graph_edges.append(e)
if not conn.src_attests: if not conn.src_attests:
@ -517,7 +517,7 @@ class cmd_ntdsconn(GraphCommand):
edge_styles = [] edge_styles = []
edge_labels = [] edge_labels = []
n_servers = len(dsas) n_servers = len(dsas)
for k, e in sorted(edges.iteritems()): for k, e in sorted(edges.items()):
dot_edges.append(k) dot_edges.append(k)
if e.observations == n_servers or not talk_to_remote: if e.observations == n_servers or not talk_to_remote:
edge_colours.append('#000000') edge_colours.append('#000000')
@ -573,6 +573,6 @@ class cmd_visualize(SuperCommand):
"""Produces graphical representations of Samba network state""" """Produces graphical representations of Samba network state"""
subcommands = {} subcommands = {}
for k, v in globals().iteritems(): for k, v in globals().items():
if k.startswith('cmd_'): if k.startswith('cmd_'):
subcommands[k[4:]] = v() subcommands[k[4:]] = v()

View File

@ -774,11 +774,11 @@ def make_smbconf(smbconf, hostname, domain, realm, targetdir,
f = open(smbconf, 'w') f = open(smbconf, 'w')
try: try:
f.write("[globals]\n") 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("\t%s = %s\n" % (key, val))
f.write("\n") f.write("\n")
for name, path in shares.iteritems(): for name, path in shares.items():
f.write("[%s]\n" % name) f.write("[%s]\n" % name)
f.write("\tpath = %s\n" % path) f.write("\tpath = %s\n" % path)
f.write("\tread only = no\n") f.write("\tread only = no\n")

View File

@ -36,14 +36,13 @@ class NetCmdTestCase(samba.tests.TestCase):
return cmd.outf.getvalue(), cmd.errf.getvalue() return cmd.outf.getvalue(), cmd.errf.getvalue()
def iter_all_subcommands(self): def iter_all_subcommands(self):
todo = [] todo = list(cmd_sambatool.subcommands.items())
todo.extend(cmd_sambatool.subcommands.items())
while todo: while todo:
(path, cmd) = todo.pop() (path, cmd) = todo.pop()
yield path, cmd yield path, cmd
subcmds = getattr(cmd, "subcommands", {}) subcmds = getattr(cmd, "subcommands", {})
todo.extend([(path + " " + k, v) for (k, v) in todo.extend([(path + " " + k, v) for (k, v) in
subcmds.iteritems()]) subcmds.items()])
class TestParmTests(NetCmdTestCase): class TestParmTests(NetCmdTestCase):

View 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 re.match(regex, fullname):
if reason is None: if reason is None:
return "" return ""

View File

@ -173,7 +173,7 @@ class LATests(samba.tests.TestCase):
except ldb.LdbError as e: except ldb.LdbError as e:
(num, msg) = e.args (num, msg) = e.args
if num != errcode: 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)} if k.startswith('ERR_') and isinstance(v, int)}
self.fail("%s, expected " self.fail("%s, expected "
"LdbError %s, (%d) " "LdbError %s, (%d) "
@ -181,7 +181,7 @@ class LATests(samba.tests.TestCase):
lut.get(errcode), errcode, lut.get(errcode), errcode,
lut.get(num), num)) lut.get(num), num))
else: 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)} if k.startswith('ERR_') and isinstance(v, int)}
self.fail("%s, expected " self.fail("%s, expected "
"LdbError %s, (%d) " "LdbError %s, (%d) "

View File

@ -563,7 +563,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex
py_path = list(extra_path) py_path = list(extra_path)
if py_path: if py_path:
environ["PYTHONPATH"] = ":".join(["$PYTHONPATH"] + 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 += [subunitrun, "$LISTOPT", "$LOADLIST", module]
args += extra_args args += extra_args
if name is None: if name is None: