summaryrefslogtreecommitdiffstats
path: root/ipapython/dnssec/localhsm.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2015-08-11 13:51:14 +0200
committerJan Cholasta <jcholast@redhat.com>2015-09-01 11:42:01 +0200
commit3bf91eab25c602a6fad2665456f57e8629c5a6f4 (patch)
tree52f713e898a385d57a914d539a7da9a20fc20166 /ipapython/dnssec/localhsm.py
parentdd16cc98b0d67f1448bf9de25f8adce512b1431c (diff)
downloadfreeipa-3bf91eab25c602a6fad2665456f57e8629c5a6f4.tar.gz
freeipa-3bf91eab25c602a6fad2665456f57e8629c5a6f4.tar.xz
freeipa-3bf91eab25c602a6fad2665456f57e8629c5a6f4.zip
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 <cheimes@redhat.com> Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipapython/dnssec/localhsm.py')
-rwxr-xr-xipapython/dnssec/localhsm.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/ipapython/dnssec/localhsm.py b/ipapython/dnssec/localhsm.py
index 412b55df9..d3b4ae15c 100755
--- a/ipapython/dnssec/localhsm.py
+++ b/ipapython/dnssec/localhsm.py
@@ -69,7 +69,7 @@ class Key(collections.MutableMapping):
def __iter__(self):
"""generates list of ipa names of all attributes present in the object"""
- for pkcs11_id, ipa_name in attrs_id2name.iteritems():
+ for pkcs11_id, ipa_name in attrs_id2name.items():
try:
self.p11.get_attribute(self.handle, pkcs11_id)
except _ipap11helper.NotFound:
@@ -84,11 +84,7 @@ class Key(collections.MutableMapping):
return cnt
def __str__(self):
- d = {}
- for ipa_name, value in self.iteritems():
- d[ipa_name] = value
-
- return str(d)
+ return str(dict(self))
def __repr__(self):
return self.__str__()
@@ -139,7 +135,7 @@ class LocalHSM(AbstractHSM):
"""Get all usable DNSSEC master keys"""
keys = self.find_keys(objclass=_ipap11helper.KEY_CLASS_SECRET_KEY, label=u'dnssec-master', cka_unwrap=True)
- for key in keys.itervalues():
+ for key in keys.values():
prefix = 'dnssec-master'
assert key['ipk11label'] == prefix, \
'secret key ipk11id=0x%s ipk11label="%s" with ipk11UnWrap = TRUE does not have '\
@@ -198,34 +194,34 @@ if __name__ == '__main__':
print 'replica public keys: CKA_WRAP = TRUE'
print '===================================='
- for pubkey_id, pubkey in localhsm.replica_pubkeys_wrap.iteritems():
+ for pubkey_id, pubkey in localhsm.replica_pubkeys_wrap.items():
print hexlify(pubkey_id)
pprint(pubkey)
print ''
print 'replica public keys: all'
print '========================'
- for pubkey_id, pubkey in localhsm.replica_pubkeys.iteritems():
+ for pubkey_id, pubkey in localhsm.replica_pubkeys.items():
print hexlify(pubkey_id)
pprint(pubkey)
print ''
print 'master keys'
print '==========='
- for mkey_id, mkey in localhsm.master_keys.iteritems():
+ for mkey_id, mkey in localhsm.master_keys.items():
print hexlify(mkey_id)
pprint(mkey)
print ''
print 'zone public keys'
print '================'
- for key_id, key in localhsm.zone_pubkeys.iteritems():
+ for key_id, key in localhsm.zone_pubkeys.items():
print hexlify(key_id)
pprint(key)
print ''
print 'zone private keys'
print '================='
- for key_id, key in localhsm.zone_privkeys.iteritems():
+ for key_id, key in localhsm.zone_privkeys.items():
print hexlify(key_id)
pprint(key)