From 8008e389b432295330170da54e5cd7421c13eefd Mon Sep 17 00:00:00 2001
From: Christian Heimes <cheimes@redhat.com>
Date: Mon, 20 Jul 2015 10:17:00 +0200
Subject: [PATCH 14/18] Use dict.iteritems() instead of dict.items()

iteritems() is the preferred way to iterate over key, value pairs.
Python-modernize can convert iteritems() to efficient code on Python 2
and 3.
---
 base/common/python/pki/cert.py    | 42 +++++++++++++++++++--------------------
 base/common/python/pki/encoder.py |  4 ++--
 base/common/python/pki/key.py     |  6 +++---
 base/common/python/pki/profile.py | 14 ++++++-------
 4 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/base/common/python/pki/cert.py b/base/common/python/pki/cert.py
index 01d2a616b8f6063acb6a38ef0587e49966493100..61b04377eeef119b6a256410d5f4530d563a6547 100644
--- a/base/common/python/pki/cert.py
+++ b/base/common/python/pki/cert.py
@@ -74,7 +74,7 @@ class CertData(object):
         """ Return CertData object from JSON dict """
         cert_data = cls()
 
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['Link']:
                 if k in CertData.json_attribute_names:
                     setattr(cert_data, CertData.json_attribute_names[k], v)
@@ -130,7 +130,7 @@ class CertDataInfo(object):
     def from_json(cls, attr_list):
         """ Return CertDataInfo object from JSON dict """
         cert_data_info = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['Link']:
                 if k in CertDataInfo.json_attribute_names:
                     setattr(cert_data_info,
@@ -220,7 +220,7 @@ class CertRequestInfo(object):
     def from_json(cls, attr_list):
         cert_request_info = cls()
 
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['Link']:
                 if k in CertRequestInfo.json_attribute_names:
                     setattr(cert_request_info,
@@ -497,7 +497,7 @@ class CertEnrollmentRequest(object):
 
         enroll_request = cls()
 
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['Input', 'Output']:
                 if k in CertEnrollmentRequest.json_attribute_names:
                     setattr(enroll_request,
@@ -531,23 +531,21 @@ class CertReviewResponse(CertEnrollmentRequest):
     reviewing a certificate enrollment request.
     It contains a nonce required to perform action on the request.
     """
-
-    json_attribute_names = dict(
-        CertEnrollmentRequest.json_attribute_names.items() + {
-            'requestId': 'request_id', 'requestType': 'request_type',
-            'requestStatus': 'request_status', 'requestOwner': 'request_owner',
-            'requestCreationTime': 'request_creation_time',
-            'requestNotes': 'request_notes',
-            'requestModificationTime': 'request_modification_time',
-            'profileApprovedBy': 'profile_approved_by',
-            'profileSetId': 'profile_set_id', 'profileName': 'profile_name',
-            'profileIsVisible': 'profile_is_visible',
-            'profileDescription': 'profile_description',
-            'profileRemoteHost': 'profile_remote_host',
-            'profileRemoteAddr': 'profile_remote_address',
-            'ProfilePolicySet': 'policy_sets'
-        }.items()
-    )
+    json_attribute_names = CertEnrollmentRequest.json_attribute_names.copy()
+    json_attribute_names.update({
+        'requestId': 'request_id', 'requestType': 'request_type',
+        'requestStatus': 'request_status', 'requestOwner': 'request_owner',
+        'requestCreationTime': 'request_creation_time',
+        'requestNotes': 'request_notes',
+        'requestModificationTime': 'request_modification_time',
+        'profileApprovedBy': 'profile_approved_by',
+        'profileSetId': 'profile_set_id', 'profileName': 'profile_name',
+        'profileIsVisible': 'profile_is_visible',
+        'profileDescription': 'profile_description',
+        'profileRemoteHost': 'profile_remote_host',
+        'profileRemoteAddr': 'profile_remote_address',
+        'ProfilePolicySet': 'policy_sets'
+    })
 
     def __init__(self, profile_id=None, renewal=False, serial_number=None,
                  remote_host=None, remote_address=None, inputs=None,
@@ -591,7 +589,7 @@ class CertReviewResponse(CertEnrollmentRequest):
         #First read the values for attributes defined in CertEnrollmentRequest
         review_response = super(CertReviewResponse, cls).from_json(attr_list)
 
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['ProfilePolicySet'] and k not in \
                     CertEnrollmentRequest.json_attribute_names:
                 if k in CertReviewResponse.json_attribute_names:
diff --git a/base/common/python/pki/encoder.py b/base/common/python/pki/encoder.py
index 1af0feaadb7af51c4f31230b5038850866bc335a..84bf325065883dbe8442a35471a68853ff0b7ccc 100644
--- a/base/common/python/pki/encoder.py
+++ b/base/common/python/pki/encoder.py
@@ -33,7 +33,7 @@ class CustomTypeEncoder(json.JSONEncoder):
     """
     # pylint: disable=E0202
     def default(self, obj):
-        for k, v in TYPES.items():
+        for k, v in TYPES.iteritems():
             if isinstance(obj, v):
                 return {k: obj.__dict__}
         for t in NOTYPES.itervalues():
@@ -48,7 +48,7 @@ class CustomTypeEncoder(json.JSONEncoder):
         reverse_dict = {v: k for k, v in
                         object_class.json_attribute_names.iteritems()}
         new_dict = dict()
-        for k, v in attr_dict.items():
+        for k, v in attr_dict.iteritems():
             if k in reverse_dict:
                 new_dict[reverse_dict[k]] = v
             else:
diff --git a/base/common/python/pki/key.py b/base/common/python/pki/key.py
index 3ff6e3dba628181bbb72d5decf8403c8dd747881..5d6a79c245126c8ca7ae43fdf7f4ae00754f0a5d 100644
--- a/base/common/python/pki/key.py
+++ b/base/common/python/pki/key.py
@@ -69,7 +69,7 @@ class KeyData(object):
     def from_json(cls, attr_list):
         """ Return a KeyData object from a JSON dict """
         key_data = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k in KeyData.json_attribute_names:
                 setattr(key_data, KeyData.json_attribute_names[k], v)
             else:
@@ -123,7 +123,7 @@ class KeyInfo(object):
     def from_json(cls, attr_list):
         """ Return KeyInfo from JSON dict """
         key_info = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k in KeyInfo.json_attribute_names:
                 setattr(key_info, KeyInfo.json_attribute_names[k], v)
             else:
@@ -188,7 +188,7 @@ class KeyRequestInfo(object):
     def from_json(cls, attr_list):
         """ Return a KeyRequestInfo object from a JSON dict. """
         key_request_info = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k in KeyRequestInfo.json_attribute_names:
                 setattr(key_request_info,
                         KeyRequestInfo.json_attribute_names[k], v)
diff --git a/base/common/python/pki/profile.py b/base/common/python/pki/profile.py
index 050f854a4eeb9176e424ae38d8c473de0c26280a..57ff831b4276db14e38d2983044d09d9c662f1e3 100644
--- a/base/common/python/pki/profile.py
+++ b/base/common/python/pki/profile.py
@@ -59,7 +59,7 @@ class ProfileDataInfo(object):
             return None
 
         profile_data_info = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k in ProfileDataInfo.json_attribute_names:
                 setattr(profile_data_info,
                         ProfileDataInfo.json_attribute_names[k], v)
@@ -129,7 +129,7 @@ class Descriptor(object):
             return None
 
         descriptor = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k in Descriptor.json_attribute_names:
                 setattr(descriptor,
                         Descriptor.json_attribute_names[k], v)
@@ -260,7 +260,7 @@ class ProfileInput(object):
             return None
         profile_input = cls()
 
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['Attribute', 'ConfigAttribute']:
                 if k in ProfileInput.json_attribute_names:
                     setattr(profile_input,
@@ -345,7 +345,7 @@ class ProfileOutput(object):
             return None
 
         profile_output = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['attributes']:
                 if k in ProfileOutput.json_attribute_names:
                     setattr(profile_output,
@@ -467,7 +467,7 @@ class PolicyDefault(object):
             return None
 
         policy_def = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['policyAttribute', 'params']:
                 if k in PolicyDefault.json_attribute_names:
                     setattr(policy_def,
@@ -585,7 +585,7 @@ class PolicyConstraint(object):
             return None
 
         policy_constraint = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['constraint']:
                 if k in PolicyConstraint.json_attribute_names:
                     setattr(policy_constraint,
@@ -917,7 +917,7 @@ class Profile(object):
     @classmethod
     def from_json(cls, attr_list):
         profile_data = cls()
-        for k, v in attr_list.items():
+        for k, v in attr_list.iteritems():
             if k not in ['Input', 'Output', 'PolicySets']:
                 if k in Profile.json_attribute_names:
                     setattr(profile_data,
-- 
2.4.3

