From 3bf91eab25c602a6fad2665456f57e8629c5a6f4 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 11 Aug 2015 13:51:14 +0200 Subject: Use Python3-compatible dict method names Python 2 has keys()/values()/items(), which return lists, iterkeys()/itervalues()/iteritems(), which return iterators, and viewkeys()/viewvalues()/viewitems() which return views. Python 3 has only keys()/values()/items(), which return views. To get iterators, one can use iter() or a for loop/comprehension; for lists there's the list() constructor. When iterating through the entire dict, without modifying the dict, the difference between Python 2's items() and iteritems() is negligible, especially on small dicts (the main overhead is extra memory, not CPU time). In the interest of simpler code, this patch changes many instances of iteritems() to items(), iterkeys() to keys() etc. In other cases, helpers like six.itervalues are used. Reviewed-By: Christian Heimes Reviewed-By: Jan Cholasta --- ipapython/dnssec/ldapkeydb.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ipapython/dnssec/ldapkeydb.py') diff --git a/ipapython/dnssec/ldapkeydb.py b/ipapython/dnssec/ldapkeydb.py index 86a7d0ac1..806999375 100644 --- a/ipapython/dnssec/ldapkeydb.py +++ b/ipapython/dnssec/ldapkeydb.py @@ -128,7 +128,7 @@ class Key(collections.MutableMapping): def __iter__(self): """generates list of ipa names of all PKCS#11 attributes present in the object""" - for ipa_name in self.entry.keys(): + for ipa_name in list(self.entry.keys()): lowercase = ipa_name.lower() if lowercase in attrs_name2id: yield lowercase @@ -247,7 +247,7 @@ class LdapKeyDB(AbstractHSM): for cache in [self.cache_masterkeys, self.cache_replica_pubkeys_wrap, self.cache_zone_keypairs]: if cache: - for key in cache.itervalues(): + for key in cache.values(): self._update_key(key) def flush(self): @@ -326,7 +326,7 @@ class LdapKeyDB(AbstractHSM): keys = self._get_key_dict(MasterKey, '(&(objectClass=ipk11SecretKey)(|(ipk11UnWrap=TRUE)(!(ipk11UnWrap=*)))(ipk11Label=dnssec-master))') - for key in keys.itervalues(): + for key in keys.values(): prefix = 'dnssec-master' assert key['ipk11label'] == prefix, \ 'secret key dn="%s" ipk11id=0x%s ipk11label="%s" with ipk11UnWrap = TRUE does not have '\ -- cgit