From ae80acfb65f240526aa524fc7e4d3e77a7ce1754 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mar 02 2016 18:42:27 +0000 Subject: python3: make list out of dict view object when appropriate In py2, dict.keys() gives a list. In py3 it gives a view object, which can't be indexed. In a few cases in wikitcms we want to index the keys of a dict (or OrderedDict), so explicitly create a list from the view object when we're doing that. --- diff --git a/wikitcms/page.py b/wikitcms/page.py index c433835..b84a464 100644 --- a/wikitcms/page.py +++ b/wikitcms/page.py @@ -316,7 +316,7 @@ class ValidationPage(Page): # envs. let's see if we can make a safe guess. If # there's only one env, it's easy... if len(row.results) == 1: - env = row.results.keys()[0] + env = list(row.results.keys())[0] else: # ...if not, we'll see if the passed env is # a substring of only one of the envs, case- @@ -355,7 +355,7 @@ class ValidationPage(Page): newtext = sectext if len(resultsdict) > 3: - testtext = ', '.join(row.name for row in resultsdict.keys()[:3]) + testtext = ', '.join(row.name for row in list(resultsdict.keys())[:3]) testtext = '{0}...'.format(testtext) else: testtext = ', '.join(row.name for row in resultsdict.keys()) diff --git a/wikitcms/result.py b/wikitcms/result.py index 246aee0..b2f6344 100644 --- a/wikitcms/result.py +++ b/wikitcms/result.py @@ -386,7 +386,7 @@ class Result(object): # if there are bugs bugs = eval(result.bugs) if bugs: - bugs = bugs.keys() + bugs = list(bugs.keys()) else: bugs = None res = cls(status, user, bugs, comment) diff --git a/wikitcms/wiki.py b/wikitcms/wiki.py index 636b6dc..4b284c0 100644 --- a/wikitcms/wiki.py +++ b/wikitcms/wiki.py @@ -125,7 +125,7 @@ class Wiki(mwclient.Site): if creds: if not username: - username = creds.keys()[0] + username = list(creds.keys())[0] if not password: password = creds.get(username) except IOError: