Skip to content

Commit

Permalink
make_ct_known_logs_list.py: Make Python 3 compatible
Browse files Browse the repository at this point in the history
In Python 3 keys() returns an iterable instead of a list. It's necessary to explicitly convert when you want to use as a list.
Still works with Python 2.

Fixed errors:
Traceback (most recent call last):
  File "../../components/certificate_transparency/tools/make_ct_known_logs_list.py", line 204, in <module>
    sys.exit(main())
  File "../../components/certificate_transparency/tools/make_ct_known_logs_list.py", line 199, in main
    generate_cpp_file(infile, outfile)
  File "../../components/certificate_transparency/tools/make_ct_known_logs_list.py", line 174, in generate_cpp_file
    if _is_log_once_or_currently_qualified(log):
  File "../../components/certificate_transparency/tools/make_ct_known_logs_list.py", line 161, in _is_log_once_or_currently_qualified
    return log.get("state").keys()[0] not in ("pending", "rejected")
TypeError: 'dict_keys' object is not subscriptable

Traceback (most recent call last):
  File "C:\Google\chromium\src\components\certificate_transparency\tools\make_ct_known_logs_list_unittest.py", line 238, in testSortingAndFilteringDisqualifiedLogs
    disqualified_logs = make_ct_known_logs_list._sorted_disqualified_logs(logs)
  File "C:\Google\chromium\src\components\certificate_transparency\tools\make_ct_known_logs_list.py", line 147, in _sorted_disqualified_logs
    return sorted(
  File "C:\Google\chromium\src\components\certificate_transparency\tools\make_ct_known_logs_list.py", line 87, in _is_log_disqualified
    log_state = log.get("state").keys()[0]
TypeError: 'dict_keys' object is not subscriptable

Bug: 941669
Change-Id: Iff905a290c3dc2581e1a0ff7ad8a8282ce9c050e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857121
Reviewed-by: Ryan Sleevi <rsleevi@chromium.org>
Commit-Queue: Raul Tambre <raul@tambre.ee>
Auto-Submit: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#705592}
  • Loading branch information
tambry authored and Commit Bot committed Oct 14, 2019
1 parent cf07b4c commit 50cb065
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _get_log_ids_for_operator(logs_by_operator, operator_name):
def _is_log_disqualified(log):
# Disqualified logs are denoted with state="retired"
assert (len(log.get("state").keys()) == 1)
log_state = log.get("state").keys()[0]
log_state = list(log.get("state"))[0]
return log_state == "retired"


Expand Down Expand Up @@ -158,7 +158,7 @@ def _write_qualifying_logs_loginfo(f, qualifying_logs):

def _is_log_once_or_currently_qualified(log):
assert (len(log.get("state").keys()) == 1)
return log.get("state").keys()[0] not in ("pending", "rejected")
return list(log.get("state"))[0] not in ("pending", "rejected")


def generate_cpp_file(input_file, f):
Expand Down

0 comments on commit 50cb065

Please sign in to comment.