Unverified Commit 5360a213 authored by Georg Koppen's avatar Georg Koppen
Browse files

Bug 40014: Get lists out of .keys(), items(), and .values()

This got caught by the 2to3 tool.
parent d86ad6b9
......@@ -278,7 +278,7 @@ def main():
destination_labels = []
for authority, destination in destinations.items():
for authority, destination in list(destinations.items()):
if not destination:
destination_labels.append('%s has no contact information' % authority)
elif not destination.bcc:
......@@ -289,8 +289,8 @@ def main():
log.debug('Sending notification for issues (%s)' % ', '.join(destination_labels))
body = '\n'.join(map(str, issues))
cc = [d.address for d in destinations.values() if d and not d.bcc]
bcc = [d.address for d in destinations.values() if d and d.bcc]
cc = [d.address for d in list(destinations.values()) if d and not d.bcc]
bcc = [d.address for d in list(destinations.values()) if d and d.bcc]
util.send(EMAIL_SUBJECT, body = body, cc = cc, bcc = bcc)
......@@ -320,7 +320,7 @@ def run_checks(consensuses, votes):
latest_consensus, latest_valid_after = None, None
for consensus in consensuses.values():
for consensus in list(consensuses.values()):
if not latest_valid_after or consensus.valid_after > latest_valid_after:
latest_consensus = consensus
latest_valid_after = consensus.valid_after
......@@ -372,7 +372,7 @@ def missing_latest_consensus(latest_consensus, consensuses, votes):
stale_authorities = []
current_time = datetime.datetime.now()
for authority, consensus in consensuses.items():
for authority, consensus in list(consensuses.items()):
if (current_time - consensus.valid_after) > datetime.timedelta(hours = 1):
stale_authorities.append(authority)
......@@ -397,8 +397,8 @@ def missing_authority_descriptor(latest_consensus, consensuses, votes):
issues = []
for authority, vote in votes.items():
for peer in DIRECTORY_AUTHORITIES.values():
for authority, vote in list(votes.items()):
for peer in list(DIRECTORY_AUTHORITIES.values()):
if peer.fingerprint not in vote.routers:
issues.append(Issue(Runlevel.WARNING, 'MISSING_AUTHORITY_DESC', authority = authority, peer = peer.nickname, to = authority))
......@@ -410,7 +410,7 @@ def consensus_method_unsupported(latest_consensus, consensuses, votes):
incompatible_authorities = []
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
if not latest_consensus.consensus_method in vote.consensus_methods:
incompatible_authorities.append(authority)
......@@ -423,12 +423,12 @@ def different_recommended_client_version(latest_consensus, consensuses, votes):
differences = {}
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
if vote.client_versions and latest_consensus.client_versions != vote.client_versions:
differences[authority] = _version_difference_str(authority, latest_consensus.client_versions, vote.client_versions)
if differences:
return Issue(Runlevel.NOTICE, 'DIFFERENT_RECOMMENDED_VERSION', type = 'client', differences = ', '.join(differences.values()), to = differences.keys())
return Issue(Runlevel.NOTICE, 'DIFFERENT_RECOMMENDED_VERSION', type = 'client', differences = ', '.join(list(differences.values())), to = list(differences.keys()))
def different_recommended_server_version(latest_consensus, consensuses, votes):
......@@ -436,12 +436,12 @@ def different_recommended_server_version(latest_consensus, consensuses, votes):
differences = {}
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
if vote.server_versions and latest_consensus.server_versions != vote.server_versions:
differences[authority] = _version_difference_str(authority, latest_consensus.server_versions, vote.server_versions)
if differences:
return Issue(Runlevel.NOTICE, 'DIFFERENT_RECOMMENDED_VERSION', type = 'server', differences = ', '.join(differences.values()), to = differences.keys())
return Issue(Runlevel.NOTICE, 'DIFFERENT_RECOMMENDED_VERSION', type = 'server', differences = ', '.join(list(differences.values())), to = list(differences.keys()))
def _version_difference_str(authority, consensus_versions, vote_versions):
......@@ -471,10 +471,10 @@ def unknown_consensus_parameters(latest_consensus, consensuses, votes):
unknown_entries = {}
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
unknown_params = []
for param_key, param_value in vote.params.items():
for param_key, param_value in list(vote.params.items()):
if not param_key in CONFIG['known_params'] and not param_key.startswith('bwauth'):
unknown_params.append('%s=%s' % (param_key, param_value))
......@@ -482,7 +482,7 @@ def unknown_consensus_parameters(latest_consensus, consensuses, votes):
unknown_entries[authority] = '%s %s' % (authority, ' '.join(unknown_params))
if unknown_entries:
return Issue(Runlevel.NOTICE, 'UNKNOWN_CONSENSUS_PARAMETERS', parameters = ', '.join(unknown_entries.values()), to = unknown_entries.keys())
return Issue(Runlevel.NOTICE, 'UNKNOWN_CONSENSUS_PARAMETERS', parameters = ', '.join(list(unknown_entries.values())), to = list(unknown_entries.keys()))
def vote_parameters_mismatch_consensus(latest_consensus, consensuses, votes):
......@@ -490,10 +490,10 @@ def vote_parameters_mismatch_consensus(latest_consensus, consensuses, votes):
mismatching_entries = {}
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
mismatching_params = []
for param_key, param_value in vote.params.items():
for param_key, param_value in list(vote.params.items()):
if latest_consensus.params.get(param_key) != param_value:
mismatching_params.append('%s=%s' % (param_key, param_value))
......@@ -501,7 +501,7 @@ def vote_parameters_mismatch_consensus(latest_consensus, consensuses, votes):
mismatching_entries[authority] = '%s %s' % (authority, ' '.join(mismatching_params))
if mismatching_entries:
return Issue(Runlevel.NOTICE, 'MISMATCH_CONSENSUS_PARAMETERS', parameters = ', '.join(mismatching_entries.values()), to = mismatching_entries.keys())
return Issue(Runlevel.NOTICE, 'MISMATCH_CONSENSUS_PARAMETERS', parameters = ', '.join(list(mismatching_entries.values())), to = list(mismatching_entries.keys()))
def certificate_expiration(latest_consensus, consensuses, votes):
......@@ -510,7 +510,7 @@ def certificate_expiration(latest_consensus, consensuses, votes):
issues = []
current_time = datetime.datetime.now()
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
# votes should only have a single authority entry (the one that issued this vote)
cert_expiration = vote.directory_authorities[0].key_certificate.expires
......@@ -530,16 +530,16 @@ def consensuses_have_same_votes(latest_consensus, consensuses, votes):
"Checks that all fresh consensuses are made up of the same votes."
current_time = datetime.datetime.now()
fresh_consensuses = dict((k, v) for k, v in consensuses.items() if ((current_time - v.valid_after) < datetime.timedelta(hours = 1)))
fresh_consensuses = dict((k, v) for k, v in list(consensuses.items()) if ((current_time - v.valid_after) < datetime.timedelta(hours = 1)))
all_votes = set()
for consensus in fresh_consensuses.values():
for consensus in list(fresh_consensuses.values()):
all_votes.update(set([auth.fingerprint for auth in consensus.directory_authorities]))
authorities_missing_votes = []
for authority, consensus in fresh_consensuses.items():
for authority, consensus in list(fresh_consensuses.items()):
if set([auth.fingerprint for auth in consensus.directory_authorities]) != all_votes:
authorities_missing_votes.append(authority)
......@@ -551,9 +551,9 @@ def has_all_signatures(latest_consensus, consensuses, votes):
"Check that the consensuses have signatures for authorities that voted on it."
issues = []
voting_authorities = set([authority.v3ident for authority in DIRECTORY_AUTHORITIES.values() if authority.v3ident])
voting_authorities = set([authority.v3ident for authority in list(DIRECTORY_AUTHORITIES.values()) if authority.v3ident])
for consensus_of, consensus in consensuses.items():
for consensus_of, consensus in list(consensuses.items()):
signing_authorities = set([sig.identity for sig in consensus.signatures])
missing_authorities = set()
......@@ -563,7 +563,7 @@ def has_all_signatures(latest_consensus, consensuses, votes):
missing_authority = missing_signature
for authority in DIRECTORY_AUTHORITIES.values():
for authority in list(DIRECTORY_AUTHORITIES.values()):
if authority.v3ident == missing_signature:
missing_authority = authority.nickname
break
......@@ -581,10 +581,10 @@ def voting_bandwidth_scanners(latest_consensus, consensuses, votes):
missing_authorities, extra_authorities = [], []
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
contains_measured_bandwidth = False
for desc in vote.routers.values():
for desc in list(vote.routers.values()):
if desc.measured:
contains_measured_bandwidth = True
break
......@@ -610,13 +610,13 @@ def unmeasured_relays(latest_consensus, consensuses, votes):
"Checks that the bandwidth authorities have all formed an opinion about at least 90% of the relays."
issues = []
consensus_fingerprints = set([desc.fingerprint for desc in latest_consensus.routers.values()])
consensus_fingerprints = set([desc.fingerprint for desc in list(latest_consensus.routers.values())])
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
if DIRECTORY_AUTHORITIES[authority].nickname in BANDWIDTH_AUTHORITIES:
measured, unmeasured = 0, 0
for desc in vote.routers.values():
for desc in list(vote.routers.values()):
if desc.fingerprint in consensus_fingerprints:
if desc.measured:
measured += 1
......@@ -637,7 +637,7 @@ def has_authority_flag(latest_consensus, consensuses, votes):
seen_authorities = set()
for desc in latest_consensus.routers.values():
for desc in list(latest_consensus.routers.values()):
if Flag.AUTHORITY in desc.flags:
seen_authorities.add(desc.nickname)
......@@ -662,18 +662,18 @@ def has_similar_flag_counts(latest_consensus, consensuses, votes):
issues = []
flag_count = {} # {flag => count}
for desc in latest_consensus.routers.values():
for desc in list(latest_consensus.routers.values()):
for flag in desc.flags:
flag_count[flag] = flag_count.setdefault(flag, 0) + 1
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
authority_flag_count = {}
for desc in vote.routers.values():
for desc in list(vote.routers.values()):
for flag in desc.flags:
authority_flag_count[flag] = authority_flag_count.setdefault(flag, 0) + 1
for flag, count in flag_count.items():
for flag, count in list(flag_count.items()):
# Skipping check for the following flags because...
#
# * BadExit and StaleDesc is only voted on by a few authorities.
......@@ -696,7 +696,7 @@ def has_expected_fingerprints(latest_consensus, consensuses, votes):
issues = []
for desc in latest_consensus.routers.values():
for desc in list(latest_consensus.routers.values()):
if desc.nickname in DIRECTORY_AUTHORITIES and Flag.NAMED in desc.flags:
expected_fingerprint = DIRECTORY_AUTHORITIES[desc.nickname].fingerprint
......@@ -712,15 +712,15 @@ def is_recommended_versions(latest_consensus, consensuses, votes):
outdated_authorities = {}
min_version = min(latest_consensus.server_versions)
for authority in DIRECTORY_AUTHORITIES.values():
for authority in list(DIRECTORY_AUTHORITIES.values()):
desc = latest_consensus.routers.get(authority.fingerprint)
if desc and desc.version and desc.version < min_version:
outdated_authorities[authority.nickname] = desc.version
if outdated_authorities:
entries = ['%s (%s)' % (k, v) for k, v in outdated_authorities.items()]
return Issue(Runlevel.WARNING, 'TOR_OUT_OF_DATE', authorities = ', '.join(entries), to = outdated_authorities.keys())
entries = ['%s (%s)' % (k, v) for k, v in list(outdated_authorities.items())]
return Issue(Runlevel.WARNING, 'TOR_OUT_OF_DATE', authorities = ', '.join(entries), to = list(outdated_authorities.keys()))
def bad_exits_in_sync(latest_consensus, consensuses, votes):
......@@ -728,8 +728,8 @@ def bad_exits_in_sync(latest_consensus, consensuses, votes):
bad_exits = {} # mapping of authorities to the fingerprints with the BadExit flag
for authority, vote in votes.items():
flagged = [desc.fingerprint for desc in vote.routers.values() if Flag.BADEXIT in desc.flags]
for authority, vote in list(votes.items()):
flagged = [desc.fingerprint for desc in list(vote.routers.values()) if Flag.BADEXIT in desc.flags]
if flagged:
bad_exits[authority] = set(flagged)
......@@ -738,13 +738,13 @@ def bad_exits_in_sync(latest_consensus, consensuses, votes):
return
voting_authorities = set(bad_exits.keys())
agreed_bad_exits = set.intersection(*bad_exits.values())
disagreed_bad_exits = set.union(*bad_exits.values()).difference(agreed_bad_exits)
agreed_bad_exits = set.intersection(*list(bad_exits.values()))
disagreed_bad_exits = set.union(*list(bad_exits.values())).difference(agreed_bad_exits)
issues = []
for fingerprint in disagreed_bad_exits:
with_flag = set([authority for authority, flagged in bad_exits.items() if fingerprint in flagged])
with_flag = set([authority for authority, flagged in list(bad_exits.items()) if fingerprint in flagged])
without_flag = []
not_in_vote = []
......@@ -793,8 +793,8 @@ def bandwidth_authorities_in_sync(latest_consensus, consensuses, votes):
measurement_counts = {} # mapping of authorities to the number of fingerprints with a measurement
for authority, vote in votes.items():
measured = [desc.fingerprint for desc in vote.routers.values() if desc.measured is not None]
for authority, vote in list(votes.items()):
measured = [desc.fingerprint for desc in list(vote.routers.values()) if desc.measured is not None]
if measured:
measurement_counts[authority] = len(measured)
......@@ -804,10 +804,10 @@ def bandwidth_authorities_in_sync(latest_consensus, consensuses, votes):
average = sum(measurement_counts.values()) / len(measurement_counts)
for authority, count in measurement_counts.items():
for authority, count in list(measurement_counts.items()):
if count > (1.2 * average) or count < (0.8 * average):
entries = ['%s (%s)' % (authority, count) for authority, count in measurement_counts.items()]
return Issue(Runlevel.NOTICE, 'BANDWIDTH_AUTHORITIES_OUT_OF_SYNC', authorities = ', '.join(entries), to = measurement_counts.keys())
entries = ['%s (%s)' % (authority, count) for authority, count in list(measurement_counts.items())]
return Issue(Runlevel.NOTICE, 'BANDWIDTH_AUTHORITIES_OUT_OF_SYNC', authorities = ', '.join(entries), to = list(measurement_counts.keys()))
def is_orport_reachable(latest_consensus, consensuses, votes):
......@@ -817,7 +817,7 @@ def is_orport_reachable(latest_consensus, consensuses, votes):
issues = []
for authority in DIRECTORY_AUTHORITIES.values():
for authority in list(DIRECTORY_AUTHORITIES.values()):
desc = latest_consensus.routers.get(authority.fingerprint)
if not desc:
......@@ -873,12 +873,12 @@ def shared_random_commit_partitioning(latest_consensus, consensuses, votes):
issues = []
self_commitments = {}
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
our_v3ident = DIRECTORY_AUTHORITIES[authority].v3ident
our_commitment = [c.commit for c in vote.directory_authorities[0].shared_randomness_commitments if c.identity == our_v3ident][0]
self_commitments[our_v3ident] = our_commitment
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
for commitment in vote.directory_authorities[0].shared_randomness_commitments:
if commitment.identity not in self_commitments:
pass # we didn't get a vote for this authority so we don't know its self-reported commitment
......@@ -900,7 +900,7 @@ def shared_random_reveal_partitioning(latest_consensus, consensuses, votes):
issues = []
self_reveals = {}
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
our_v3ident = DIRECTORY_AUTHORITIES[authority].v3ident
our_reveals = [c.reveal for c in vote.directory_authorities[0].shared_randomness_commitments if c.identity == our_v3ident]
......@@ -911,10 +911,10 @@ def shared_random_reveal_partitioning(latest_consensus, consensuses, votes):
else:
self_reveals[our_v3ident] = our_reveals[0]
for authority, vote in votes.items():
for authority, vote in list(votes.items()):
commitments = vote.directory_authorities[0].shared_randomness_commitments
for v3ident, reveal in self_reveals.items():
for v3ident, reveal in list(self_reveals.items()):
matches = [c.reveal for c in commitments if c.identity == v3ident]
if len(matches) == 0:
......@@ -964,7 +964,7 @@ def get_votes():
def _get_documents(label, resource):
documents, times_taken, clock_skew, issues = {}, {}, {}, []
for authority in DIRECTORY_AUTHORITIES.values():
for authority in list(DIRECTORY_AUTHORITIES.values()):
if authority.v3ident is None:
continue # not a voting authority
......@@ -990,13 +990,13 @@ def _get_documents(label, resource):
if label == 'consensus' and times_taken:
median_time = sorted(times_taken.values())[int(len(times_taken) / 2)]
authority_times = ', '.join(['%s => %0.1fs' % (authority, time_taken) for authority, time_taken in times_taken.items()])
authority_times = ', '.join(['%s => %0.1fs' % (authority, time_taken) for authority, time_taken in list(times_taken.items())])
for nickname, time_taken in times_taken.items():
for nickname, time_taken in list(times_taken.items()):
if time_taken > median_time * 5:
issues.append(Issue(Runlevel.NOTICE, 'LATENCY', authority = nickname, time_taken = '%0.1fs' % time_taken, median_time = '%0.1fs' % median_time, authority_times = authority_times, to = [nickname]))
for nickname, difference in clock_skew.items():
for nickname, difference in list(clock_skew.items()):
if difference > 10:
issues.append(Issue(Runlevel.NOTICE, 'CLOCK_SKEW', authority = nickname, difference = int(difference), to = [nickname]))
......
......@@ -66,7 +66,7 @@ def main():
# download the consensus from each authority
for authority in stem.directory.Authority.from_cache().values():
for authority in list(stem.directory.Authority.from_cache().values()):
if authority.v3ident is None:
continue # authority doesn't vote in the consensus
elif authority.nickname in DIRAUTH_SKIP_CHECKS:
......
......@@ -26,7 +26,7 @@ downloader = stem.descriptor.remote.DescriptorDownloader(timeout = 30)
def main():
try:
fallback_directories = stem.directory.Fallback.from_remote().values()
fallback_directories = list(stem.directory.Fallback.from_remote().values())
log.info('Retrieved %i fallback directories' % len(fallback_directories))
except IOError as exc:
raise IOError("Unable to determine tor's fallback directories: %s" % exc)
......
......@@ -64,18 +64,18 @@ def main():
if len(prior_fingerprints) >= 10:
alarm_for['%s:%s' % (relay.address, relay.or_port)] = (relay.address, relay.or_port, relay.fingerprint)
if alarm_for and not is_notification_suppressed(alarm_for.values()):
if alarm_for and not is_notification_suppressed(list(alarm_for.values())):
log.debug("Sending a notification for %i relays..." % len(alarm_for))
body = EMAIL_BODY
for address, or_port, fingerprint in alarm_for.values():
for address, or_port, fingerprint in list(alarm_for.values()):
try:
desc = downloader.get_server_descriptors(fingerprint).run()[0]
except:
desc = None # might not be available, just used for extra info
fp_changes = fingerprint_changes[(address, or_port)]
log.debug("* %s:%s has had %i fingerprints: %s" % (address, or_port, len(fp_changes), ', '.join(fp_changes.keys())))
log.debug("* %s:%s has had %i fingerprints: %s" % (address, or_port, len(fp_changes), ', '.join(list(fp_changes.keys()))))
if desc:
body += "* %s:%s (platform: %s, contact: %s)\n" % (address, or_port, desc.platform.decode('utf-8', 'replace'), desc.contact)
......@@ -102,7 +102,7 @@ def main():
subject = EMAIL_SUBJECT
if len(alarm_for) == 1:
subject += ' (%s:%s)' % alarm_for.values()[0][:2]
subject += ' (%s:%s)' % list(alarm_for.values())[0][:2]
util.send(subject, body = body, to = ['tor-network-alerts@lists.torproject.org', 'gk@torproject.org'])
......@@ -110,7 +110,7 @@ def main():
current_time = str(int(time.time()))
for address, or_port, _ in alarm_for.values():
for address, or_port, _ in list(alarm_for.values()):
last_notified_config.set('%s:%s' % (address, or_port), current_time)
last_notified_config.save()
......@@ -133,7 +133,7 @@ def load_fingerprint_changes():
config.load(FINGERPRINT_CHANGES_FILE)
fingerprint_changes = {}
for key in config.keys():
for key in list(config.keys()):
address, or_port = key.split(':', 1)
for value in config.get(key, []):
......@@ -153,7 +153,7 @@ def save_fingerprint_changes(fingerprint_changes):
config.clear()
for address, or_port in fingerprint_changes:
for fingerprint, published in fingerprint_changes[(address, or_port)].items():
for fingerprint, published in list(fingerprint_changes[(address, or_port)].items()):
config.set('%s:%s' % (address, or_port), '%s:%s' % (fingerprint, published), overwrite = False)
try:
......
......@@ -86,7 +86,7 @@ def get_tracked_relays():
results, expired = [], []
for identifier in set([key.split('.')[0] for key in config.keys()]):
for identifier in set([key.split('.')[0] for key in list(config.keys())]):
relay = TrackedRelay(identifier, config)
if relay.expires > datetime.datetime.now():
......@@ -142,13 +142,13 @@ def main():
elif desc.fingerprint in tracked_fingerprints:
found_relays.setdefault(tracked_fingerprints[desc.fingerprint], []).append(desc)
else:
for addr_entry, relay in tracked_address_ranges.items():
for addr_entry, relay in list(tracked_address_ranges.items()):
if addr_entry.is_match(desc.address):
found_relays.setdefault(relay, []).append(desc)
all_descriptors = []
for relays in found_relays.values():
for relays in list(found_relays.values()):
all_descriptors += relays
if found_relays and not is_notification_suppressed(all_descriptors):
......@@ -156,7 +156,7 @@ def main():
current_time = str(int(time.time()))
body = EMAIL_BODY
for tracked_relay, relays in found_relays.items():
for tracked_relay, relays in list(found_relays.items()):
log.debug('* %s' % tracked_relay)
body += '* %s (%s)\n' % (tracked_relay.identifier, tracked_relay.description)
......
Supports Markdown
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