From afcdbdb9dd9e596bd3d5536f5531a11566146c02 Mon Sep 17 00:00:00 2001
From: Paul Marillonnet <pmarillonnet@entrouvert.com>
Date: Thu, 24 Jan 2019 15:35:29 +0100
Subject: [PATCH] python3: remove dict.iteritems in py files and django
 templates (#31149)

---
 src/authentic2/api_views.py                          |  4 ++--
 src/authentic2/auth2_auth/auth2_ssl/util.py          |  2 +-
 src/authentic2/backends/ldap_backend.py              |  6 +++---
 src/authentic2/decorators.py                         |  2 +-
 src/authentic2/forms/widgets.py                      |  2 +-
 src/authentic2/idp/saml/common.py                    |  2 +-
 src/authentic2/management/commands/slapd-shell.py    |  4 ++--
 src/authentic2/manager/forms.py                      |  2 +-
 src/authentic2/saml/management/commands/mapping.py   | 10 +++++-----
 src/authentic2/saml/models.py                        |  6 +++---
 src/authentic2/saml/shibboleth/afp_parser.py         |  2 +-
 src/authentic2/templates/authentic2/accounts.html    |  2 +-
 src/authentic2/templates/authentic2/login.html       |  6 +++---
 src/authentic2/utils.py                              | 12 ++++++------
 src/authentic2_idp_cas/views.py                      |  2 +-
 src/authentic2_idp_oidc/__init__.py                  |  4 ++--
 .../management/commands/provision.py                 |  8 ++++----
 src/django_rbac/backends.py                          |  4 ++--
 tests/test_all.py                                    |  2 +-
 tests/test_idp_oidc.py                               |  4 ++--
 20 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/src/authentic2/api_views.py b/src/authentic2/api_views.py
index 54e3a626..88e1c853 100644
--- a/src/authentic2/api_views.py
+++ b/src/authentic2/api_views.py
@@ -388,7 +388,7 @@ class BaseUserSerializer(serializers.ModelSerializer):
         is_verified = validated_data.pop('is_verified', {})
         self.check_perm('custom_user.add_user', validated_data.get('ou'))
         instance = super(BaseUserSerializer, self).create(validated_data)
-        for key, value in attributes.iteritems():
+        for key, value in attributes.items():
             if is_verified.get(key):
                 setattr(instance.verified_attributes, key, value)
             else:
@@ -430,7 +430,7 @@ class BaseUserSerializer(serializers.ModelSerializer):
         if 'ou' in validated_data:
             self.check_perm('custom_user.change_user', validated_data.get('ou'))
         super(BaseUserSerializer, self).update(instance, validated_data)
-        for key, value in attributes.iteritems():
+        for key, value in attributes.items():
             if is_verified.get(key):
                 setattr(instance.verified_attributes, key, value)
             else:
diff --git a/src/authentic2/auth2_auth/auth2_ssl/util.py b/src/authentic2/auth2_auth/auth2_ssl/util.py
index 0b95c38a..d7c269ee 100644
--- a/src/authentic2/auth2_auth/auth2_ssl/util.py
+++ b/src/authentic2/auth2_auth/auth2_ssl/util.py
@@ -52,7 +52,7 @@ class SSLInfo(object):
         pass
 
     def read_env(self, env):
-        for attr, keys in X509_KEYS.iteritems():
+        for attr, keys in X509_KEYS.items():
             if isinstance(keys, six.string_types):
                 keys = [keys]
             for key in keys:
diff --git a/src/authentic2/backends/ldap_backend.py b/src/authentic2/backends/ldap_backend.py
index ae692903..edbf87c4 100644
--- a/src/authentic2/backends/ldap_backend.py
+++ b/src/authentic2/backends/ldap_backend.py
@@ -205,7 +205,7 @@ def map_text(d):
     elif isinstance(d, (list, tuple)):
         return d.__class__(map_text(x) for x in d)
     elif isinstance(d, dict):
-        return {map_text(k): map_text(v) for k, v in d.iteritems()}
+        return {map_text(k): map_text(v) for k, v in d.items()}
     raise NotImplementedError
 
 
@@ -932,7 +932,7 @@ class LDAPBackend(object):
             return None
         attribute_map = cls.normalize_ldap_results(results[0][1])
         # add mandatory attributes
-        for key, mandatory_values in mandatory_attributes_values.iteritems():
+        for key, mandatory_values in mandatory_attributes_values.items():
             key = force_text(key)
             old = attribute_map.setdefault(key, [])
             new = set(old) | set(mandatory_values)
@@ -1184,7 +1184,7 @@ class LDAPBackend(object):
         if not block['url']:
             raise ImproperlyConfigured("block['url'] must contain at least one url")
         for url in map_text(block['url']):
-            for key, value in block['global_ldap_options'].iteritems():
+            for key, value in block['global_ldap_options'].items():
                 ldap.set_option(key, value)
             conn = LDAPObject(url)
             if block['timeout'] > 0:
diff --git a/src/authentic2/decorators.py b/src/authentic2/decorators.py
index 675226d4..557f574f 100644
--- a/src/authentic2/decorators.py
+++ b/src/authentic2/decorators.py
@@ -166,7 +166,7 @@ class CacheDecoratorBase(object):
                 continue
             parts.append(unicode(arg))
 
-        for kw, arg in sorted(kwargs.iteritems(), key=lambda x: x[0]):
+        for kw, arg in sorted(kwargs.items(), key=lambda x: x[0]):
             if kw not in self.kwargs:
                 continue
             parts.append(u'%s-%s' % (unicode(kw), unicode(arg)))
diff --git a/src/authentic2/forms/widgets.py b/src/authentic2/forms/widgets.py
index 3cd27a0e..fdf1e2c0 100644
--- a/src/authentic2/forms/widgets.py
+++ b/src/authentic2/forms/widgets.py
@@ -102,7 +102,7 @@ class PickerWidgetMixin(object):
 
     def get_format(self):
         format = get_format(self.format_name)[0]
-        for py, js in DATE_FORMAT_PY_JS_MAPPING.iteritems():
+        for py, js in DATE_FORMAT_PY_JS_MAPPING.items():
             format = format.replace(py, js)
         return format
 
diff --git a/src/authentic2/idp/saml/common.py b/src/authentic2/idp/saml/common.py
index f983249b..a3d2c406 100644
--- a/src/authentic2/idp/saml/common.py
+++ b/src/authentic2/idp/saml/common.py
@@ -12,7 +12,7 @@ def redirect_to_login(next, login_url=None,
     if not login_url:
         login_url = settings.LOGIN_URL
     data = { redirect_field_name: next }
-    for k, v in other_keys.iteritems():
+    for k, v in other_keys.items():
         data[k] = v
     return HttpResponseRedirect('%s?%s' % (login_url, urlencode(data)))
 
diff --git a/src/authentic2/management/commands/slapd-shell.py b/src/authentic2/management/commands/slapd-shell.py
index 4e267530..5e33c520 100644
--- a/src/authentic2/management/commands/slapd-shell.py
+++ b/src/authentic2/management/commands/slapd-shell.py
@@ -43,7 +43,7 @@ class Command(BaseCommand):
                     print 'info: invalid filter'
                     print
                     return
-                for user_attribute, ldap_attribute in MAPPING.iteritems():
+                for user_attribute, ldap_attribute in MAPPING.items():
                     if ldap_attribute == m.group(1):
                         break
                 else:
@@ -68,7 +68,7 @@ class Command(BaseCommand):
                 qs = qs.filter(**{user_attribute: value.decode('utf-8')})
             for user in qs:
                 o = {}
-                for user_attribute, ldap_attribute in MAPPING.iteritems():
+                for user_attribute, ldap_attribute in MAPPING.items():
                     o[ldap_attribute] = [unicode(getattr(user, user_attribute)).encode('utf-8')]
                 o['objectClass'] = ['inetOrgPerson']
                 dn = 'uid=%s,%s' % (escape_dn_chars(o['uid'][0]), attrs['suffix'])
diff --git a/src/authentic2/manager/forms.py b/src/authentic2/manager/forms.py
index 7a39afde..bbd50eb4 100644
--- a/src/authentic2/manager/forms.py
+++ b/src/authentic2/manager/forms.py
@@ -77,7 +77,7 @@ class LimitQuerysetFormMixin(FormWithRequest):
     def __init__(self, *args, **kwargs):
         super(LimitQuerysetFormMixin, self).__init__(*args, **kwargs)
         if self.request and not self.request.user.is_anonymous():
-            for name, field in self.fields.iteritems():
+            for name, field in self.fields.items():
                 qs = getattr(field, 'queryset', None)
                 if not qs:
                     continue
diff --git a/src/authentic2/saml/management/commands/mapping.py b/src/authentic2/saml/management/commands/mapping.py
index d1c5cd8f..de900de0 100644
--- a/src/authentic2/saml/management/commands/mapping.py
+++ b/src/authentic2/saml/management/commands/mapping.py
@@ -21,31 +21,31 @@ from django.utils.translation import ugettext as _
 
 
 def get_def_name_from_oid(oid):
-    for key, value in ATTRIBUTE_MAPPING.iteritems():
+    for key, value in ATTRIBUTE_MAPPING.items():
         if value['oid'] == oid:
             return key
 
 
 def get_definition_from_oid(oid):
-    for key, value in ATTRIBUTE_MAPPING.iteritems():
+    for key, value in ATTRIBUTE_MAPPING.items():
         if value['oid'] == oid:
             return value
 
 
 def get_full_definition(name):
-    for key, value in ATTRIBUTE_MAPPING.iteritems():
+    for key, value in ATTRIBUTE_MAPPING.items():
         if key == name:
             return value
 
 
 def get_definition_from_alias(alias):
-    for key, value in ATTRIBUTE_MAPPING.iteritems():
+    for key, value in ATTRIBUTE_MAPPING.items():
         if 'alias' in value and alias in value['alias']:
             return value
 
 
 def get_def_name_from_alias(alias):
-    for key, value in ATTRIBUTE_MAPPING.iteritems():
+    for key, value in ATTRIBUTE_MAPPING.items():
         if 'alias' in value and alias in value['alias']:
             return key
 
diff --git a/src/authentic2/saml/models.py b/src/authentic2/saml/models.py
index f03a9ec2..eac8e711 100644
--- a/src/authentic2/saml/models.py
+++ b/src/authentic2/saml/models.py
@@ -112,14 +112,14 @@ NAME_ID_FORMATS = {
 }
 
 NAME_ID_FORMATS_CHOICES = \
-        tuple([(x, y['caption']) for x, y in NAME_ID_FORMATS.iteritems()])
+        tuple([(x, y['caption']) for x, y in NAME_ID_FORMATS.items()])
 
 ACCEPTED_NAME_ID_FORMAT_LENGTH = \
-        sum([len(x) for x, y in NAME_ID_FORMATS.iteritems()]) + \
+        sum([len(x) for x, y in NAME_ID_FORMATS.items()]) + \
         len(NAME_ID_FORMATS) - 1
 
 def saml2_urn_to_nidformat(urn, accepted=()):
-    for x, y in NAME_ID_FORMATS.iteritems():
+    for x, y in NAME_ID_FORMATS.items():
         if accepted and not x in accepted:
             continue
         if y['samlv2'] == urn:
diff --git a/src/authentic2/saml/shibboleth/afp_parser.py b/src/authentic2/saml/shibboleth/afp_parser.py
index 3fa031e5..8a41a594 100644
--- a/src/authentic2/saml/shibboleth/afp_parser.py
+++ b/src/authentic2/saml/shibboleth/afp_parser.py
@@ -64,7 +64,7 @@ def parse_attribute_filter_et(root):
 if __name__ == '__main__':
     import sys
 
-    for key, values in parse_attribute_filters_file(sys.argv[1]).iteritems():
+    for key, values in parse_attribute_filters_file(sys.argv[1]).items():
         print '-', key, ':'
         for value in values:
             print ' *', value
diff --git a/src/authentic2/templates/authentic2/accounts.html b/src/authentic2/templates/authentic2/accounts.html
index 4e9f979f..dff3645f 100644
--- a/src/authentic2/templates/authentic2/accounts.html
+++ b/src/authentic2/templates/authentic2/accounts.html
@@ -55,7 +55,7 @@
                 <form method="post" action="{{ federation.url }}">
                   {% csrf_token %}
                   <span class="name">{{ federation.name }}</span>
-                  {% for key, value in federation.hidden_inputs.iteritems %}
+                  {% for key, value in federation.hidden_inputs.items %}
                     <input type="hidden" name="{{ key }}" value="{{ value }}"/>
                   {% endfor %}
                   {% for button_name, button_label in federation.buttons %}
diff --git a/src/authentic2/templates/authentic2/login.html b/src/authentic2/templates/authentic2/login.html
index 6fadcd0d..fa741634 100644
--- a/src/authentic2/templates/authentic2/login.html
+++ b/src/authentic2/templates/authentic2/login.html
@@ -16,14 +16,14 @@
 
 {% block content %}
   <div id="a2-login-forms">
-    {% for id, login_block in blocks.iteritems %}
+    {% for id, login_block in blocks.items %}
       {% if not login_block.is_hidden %}
         <span id="css-tab{{ forloop.counter }}"></span>
       {% endif %}
     {% endfor %}
 
     {% if blocks|length != 1 %}
-      {% for id, login_block in blocks.iteritems %}
+      {% for id, login_block in blocks.items %}
         {% if not login_block.is_hidden %}
           <a class="css-tab-link css-tab{{ forloop.counter }} {% if forloop.first %}css-tab-default{% endif %}" href="#css-tab{{ forloop.counter }}">
               {{ login_block.name }}
@@ -32,7 +32,7 @@
       {% endfor %}
     {% endif %}
 
-    {% for id, login_block in blocks.iteritems %}
+    {% for id, login_block in blocks.items %}
       <div class="css-tab-content css-tab{{ forloop.counter }} {% if forloop.first %}css-tab-default{% endif %}">
         {{ login_block.content|safe }}
       </div>
diff --git a/src/authentic2/utils.py b/src/authentic2/utils.py
index 5f494844..55e0fe99 100644
--- a/src/authentic2/utils.py
+++ b/src/authentic2/utils.py
@@ -278,14 +278,14 @@ def make_url(to, args=(), kwargs={}, keep_params=False, params=None, append=None
     url_params = QueryDict(query_string=query_string, mutable=True)
     if keep_params:
         assert request is not None, 'missing request'
-        for key, value in request.GET.iteritems():
+        for key, value in request.GET.items():
             if exclude and key in exclude:
                 continue
             if include and key not in include:
                 continue
             url_params.setlist(key, request.GET.getlist(key))
     if params:
-        for key, value in params.iteritems():
+        for key, value in params.items():
             if value is None:
                 url_params.pop(key, None)
             elif isinstance(value, (tuple, list)):
@@ -293,7 +293,7 @@ def make_url(to, args=(), kwargs={}, keep_params=False, params=None, append=None
             else:
                 url_params[key] = value
     if append:
-        for key, value in append.iteritems():
+        for key, value in append.items():
             if value is None:
                 continue
             elif isinstance(value, (tuple, list)):
@@ -779,12 +779,12 @@ def batch_queryset(qs, size=1000):
 
 def lower_keys(d):
     '''Convert all keys in dictionary d to lowercase'''
-    return dict((key.lower(), value) for key, value in d.iteritems())
+    return dict((key.lower(), value) for key, value in d.items())
 
 
 def to_dict_of_set(d):
     '''Convert a dictionary of sequence into a dictionary of sets'''
-    return dict((k, set(v)) for k, v in d.iteritems())
+    return dict((k, set(v)) for k, v in d.items())
 
 
 def switch_user(request, new_user):
@@ -844,7 +844,7 @@ def datetime_to_xs_datetime(dt):
 
 def utf8_encode(v):
     if isinstance(v, dict):
-        return dict((utf8_encode(a), utf8_encode(b)) for a, b in v.iteritems())
+        return dict((utf8_encode(a), utf8_encode(b)) for a, b in v.items())
     if isinstance(v, (list, tuple)):
         return type(v)(utf8_encode(a) for a in v)
     if isinstance(v, unicode):
diff --git a/src/authentic2_idp_cas/views.py b/src/authentic2_idp_cas/views.py
index 4751840c..0b4f50fc 100644
--- a/src/authentic2_idp_cas/views.py
+++ b/src/authentic2_idp_cas/views.py
@@ -294,7 +294,7 @@ class ServiceValidateView(ValidateBaseView):
                 values[slug].update(normalized)
         if values:
             attributes_elt = ET.SubElement(success, ATTRIBUTES_ELT)
-        for key, values in values.iteritems():
+        for key, values in values.items():
             for value in values:
                 attribute_elt = ET.SubElement(attributes_elt, '{%s}%s' % (CAS_NAMESPACE, key))
                 attribute_elt.text = unicode(value)
diff --git a/src/authentic2_idp_oidc/__init__.py b/src/authentic2_idp_oidc/__init__.py
index 337b6f60..22189cfe 100644
--- a/src/authentic2_idp_oidc/__init__.py
+++ b/src/authentic2_idp_oidc/__init__.py
@@ -19,7 +19,7 @@ class Plugin(object):
         fragments = []
 
         oidc_sessions = get_oidc_sessions(request)
-        for key, value in oidc_sessions.iteritems():
+        for key, value in oidc_sessions.items():
             if 'frontchannel_logout_uri' not in value:
                 continue
             ctx = {
@@ -31,4 +31,4 @@ class Plugin(object):
                 render_to_string(
                     'authentic2_idp_oidc/logout_fragment.html',
                     ctx))
-        return fragments
\ No newline at end of file
+        return fragments
diff --git a/src/authentic2_provisionning_ldap/management/commands/provision.py b/src/authentic2_provisionning_ldap/management/commands/provision.py
index 070e8ee5..f87d4241 100644
--- a/src/authentic2_provisionning_ldap/management/commands/provision.py
+++ b/src/authentic2_provisionning_ldap/management/commands/provision.py
@@ -114,14 +114,14 @@ class Command(BaseCommand):
                 ctx['user'] = user
                 ctx = get_attributes(ctx)
                 ldap_attributes = {}
-                for ldap_attribute, a2_attributes in attribute_mapping.iteritems():
+                for ldap_attribute, a2_attributes in attribute_mapping.items():
                     if not isinstance(a2_attributes, (tuple, list)):
                         a2_attributes = [a2_attributes]
                     for a2_attribute in a2_attributes:
                         self.add_values(ldap_attributes, ldap_attribute, ctx.get(a2_attribute))
-                for ldap_attribute, values in static_attributes.iteritems():
+                for ldap_attribute, values in static_attributes.items():
                     self.add_values(ldap_attributes, ldap_attribute, values)
-                for ldap_attribute, fmt_tpls in format_mapping.iteritems():
+                for ldap_attribute, fmt_tpls in format_mapping.items():
                     for fmt_tpl in fmt_tpls:
                         self.add_values(ldap_attributes, ldap_attribute,
                                 [fmt_tpl.format(**ctx)])
@@ -146,7 +146,7 @@ class Command(BaseCommand):
                     del ldap_users[dn]
                     continue
                 existing_dn.add(dn)
-            for dn, ldap_attributes in ldap_users.iteritems():
+            for dn, ldap_attributes in ldap_users.items():
                 if dn in existing_dn:
                     modlist = []
                     for key, values in ldap_attributes:
diff --git a/src/django_rbac/backends.py b/src/django_rbac/backends.py
index aefe3069..a75c6f91 100644
--- a/src/django_rbac/backends.py
+++ b/src/django_rbac/backends.py
@@ -148,7 +148,7 @@ class DjangoRBACBackend(object):
         cache = self.get_permission_cache(user_obj)
         if perm_or_perms & cache.get('__all__', set()):
             return True
-        for key, value in cache.iteritems():
+        for key, value in cache.items():
             if isinstance(value, bool):
                 continue
             elif key == '__all__':
@@ -181,7 +181,7 @@ class DjangoRBACBackend(object):
         if perm_or_perms & cache.get('__all__', set()):
             return True
         q = []
-        for key, value in cache.iteritems():
+        for key, value in cache.items():
             if isinstance(value, bool):
                 continue
             elif key == '__all__':
diff --git a/tests/test_all.py b/tests/test_all.py
index 98ad6d16..492cbe45 100644
--- a/tests/test_all.py
+++ b/tests/test_all.py
@@ -247,7 +247,7 @@ class UserProfileTests(TestCase):
                   'national_number': 'xx20153566342yy'}
         if form.prefix:
             kwargs = dict(('%s-%s' % (form.prefix, k), v)
-                          for k, v in kwargs.iteritems())
+                          for k, v in kwargs.items())
 
         response = self.client.post(reverse('profile_edit'), kwargs)
 
diff --git a/tests/test_idp_oidc.py b/tests/test_idp_oidc.py
index 82635eb0..7a9a496a 100644
--- a/tests/test_idp_oidc.py
+++ b/tests/test_idp_oidc.py
@@ -118,7 +118,7 @@ def oidc_client(request, superuser, app, simple_user, media):
     response.form.set('ou', get_default_ou().pk)
     response.form.set('unauthorized_url', 'https://example.com/southpark/')
     response.form.set('redirect_uris', 'https://example.com/callbac%C3%A9')
-    for key, value in request.param.iteritems():
+    for key, value in request.param.items():
         response.form.set(key, value)
     response = response.form.submit().follow()
     assert OIDCClient.objects.count() == 1
@@ -324,7 +324,7 @@ def assert_authorization_response(response, fragment=False, **kwargs):
     location = urlparse.urlparse(response['Location'])
     query = location.fragment if fragment else location.query
     query = urlparse.parse_qs(query)
-    for key, value in kwargs.iteritems():
+    for key, value in kwargs.items():
         if value is None:
             assert key in query
         elif isinstance(value, list):
-- 
2.20.1

