From 0282c89cc6eb6de1f1d7bc303ba023177b2bf88b Mon Sep 17 00:00:00 2001
From: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date: Thu, 14 Mar 2019 13:00:25 +0100
Subject: [PATCH 3/3] 2

---
 src/authentic2/a2_rbac/admin.py                  |  2 +-
 src/authentic2/a2_rbac/management.py             |  6 +++---
 src/authentic2/a2_rbac/models.py                 |  4 ++--
 src/authentic2/attribute_kinds.py                |  2 +-
 .../attributes_ng/sources/django_user.py         |  2 +-
 src/authentic2/custom_user/models.py             |  2 +-
 src/authentic2/decorators.py                     |  4 ++--
 src/authentic2/exponential_retry_timeout.py      |  2 +-
 src/authentic2/idp/saml/saml2_endpoints.py       |  4 ++--
 src/authentic2/log_filters.py                    |  2 +-
 .../management/commands/slapd-shell.py           |  2 +-
 src/authentic2/manager/forms.py                  |  4 ++--
 src/authentic2/manager/ou_views.py               |  2 +-
 src/authentic2/manager/resources.py              |  4 ++--
 src/authentic2/manager/service_views.py          |  2 +-
 src/authentic2/manager/views.py                  |  8 ++++----
 src/authentic2/manager/widgets.py                |  2 +-
 src/authentic2/models.py                         |  4 ++--
 src/authentic2/saml/admin.py                     |  2 +-
 src/authentic2/saml/common.py                    |  2 +-
 src/authentic2/saml/models.py                    |  2 +-
 src/authentic2/utils.py                          |  8 ++++----
 src/authentic2/views.py                          |  4 ++--
 src/authentic2_auth_oidc/backends.py             |  2 +-
 src/authentic2_auth_oidc/utils.py                | 16 ++++++++--------
 src/authentic2_idp_cas/views.py                  |  8 ++++----
 src/authentic2_idp_oidc/models.py                | 14 +++++++-------
 src/authentic2_idp_oidc/utils.py                 |  4 ++--
 src/authentic2_idp_oidc/views.py                 |  4 ++--
 src/django_rbac/models.py                        |  4 ++--
 src/django_rbac/utils.py                         |  4 ++--
 31 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/src/authentic2/a2_rbac/admin.py b/src/authentic2/a2_rbac/admin.py
index 4368b6d3..ce9d5ee2 100644
--- a/src/authentic2/a2_rbac/admin.py
+++ b/src/authentic2/a2_rbac/admin.py
@@ -57,7 +57,7 @@ class PermissionAdmin(admin.ModelAdmin):
     list_select_related = True
 
     def name(self, obj):
-        return text_type(obj)
+        return six.text_type(obj)
     name.short_description = _('name')
 
 admin.site.register(models.Role, RoleAdmin)
diff --git a/src/authentic2/a2_rbac/management.py b/src/authentic2/a2_rbac/management.py
index dcd9a125..b53bb998 100644
--- a/src/authentic2/a2_rbac/management.py
+++ b/src/authentic2/a2_rbac/management.py
@@ -28,9 +28,9 @@ def update_ou_admin_roles(ou):
         # do not create scoped admin roles if the model is not scopable
         if not ou_model:
             continue
-        name = text_type(MANAGED_CT[key]['name'])
+        name = six.text_type(MANAGED_CT[key]['name'])
         slug = '_a2-' + slugify(name)
-        scoped_name = text_type(MANAGED_CT[key]['scoped_name'])
+        scoped_name = six.text_type(MANAGED_CT[key]['scoped_name'])
         name = scoped_name.format(ou=ou)
         ou_slug = slug + '-' + ou.slug
         if app_settings.MANAGED_CONTENT_TYPES == ():
@@ -113,7 +113,7 @@ def update_content_types_roles():
         if ct_tuple not in MANAGED_CT:
             continue
         # General admin role
-        name = text_type(MANAGED_CT[ct_tuple]['name'])
+        name = six.text_type(MANAGED_CT[ct_tuple]['name'])
         slug = '_a2-' + slugify(name)
         if app_settings.MANAGED_CONTENT_TYPES is not None and ct_tuple not in \
                 app_settings.MANAGED_CONTENT_TYPES:
diff --git a/src/authentic2/a2_rbac/models.py b/src/authentic2/a2_rbac/models.py
index de318871..c6eec1ed 100644
--- a/src/authentic2/a2_rbac/models.py
+++ b/src/authentic2/a2_rbac/models.py
@@ -187,9 +187,9 @@ class Role(RoleAbstractBase):
         admin_role = self.__class__.objects.get_admin_role(
             self, ou=self.ou,
             name=_('Managers of role "{role}"').format(
-                role=text_type(self)),
+                role=six.text_type(self)),
             slug='_a2-managers-of-role-{role}'.format(
-                role=slugify(text_type(self))),
+                role=slugify(six.text_type(self))),
             permissions=(utils.get_view_user_perm(),),
             self_administered=True)
         return admin_role
diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py
index 027ae249..a8ff9cfc 100644
--- a/src/authentic2/attribute_kinds.py
+++ b/src/authentic2/attribute_kinds.py
@@ -25,7 +25,7 @@ from .plugins import collect_from_plugins
 from . import app_settings
 from .forms import widgets, fields
 
-capfirst = allow_lazy(capfirst, text_type)
+capfirst = allow_lazy(capfirst, six.text_type)
 
 DEFAULT_TITLE_CHOICES = (
     (pgettext_lazy('title', 'Mrs'), pgettext_lazy('title', 'Mrs')),
diff --git a/src/authentic2/attributes_ng/sources/django_user.py b/src/authentic2/attributes_ng/sources/django_user.py
index bdfa0c75..9ef4b083 100644
--- a/src/authentic2/attributes_ng/sources/django_user.py
+++ b/src/authentic2/attributes_ng/sources/django_user.py
@@ -76,7 +76,7 @@ def get_attributes(instance, ctx):
         ctx['django_user_' + str(av.attribute.name)] = serialized
         ctx['django_user_' + str(av.attribute.name) + ':verified'] = av.verified
     ctx['django_user_groups'] = [group for group in user.groups.all()]
-    ctx['django_user_group_names'] = [text_type(group) for group in user.groups.all()]
+    ctx['django_user_group_names'] = [six.text_type(group) for group in user.groups.all()]
     if user.username:
         splitted = user.username.rsplit('@', 1)
         ctx['django_user_domain'] = splitted[1] if '@' in user.username else ''
diff --git a/src/authentic2/custom_user/models.py b/src/authentic2/custom_user/models.py
index 61120bfe..e679a04f 100644
--- a/src/authentic2/custom_user/models.py
+++ b/src/authentic2/custom_user/models.py
@@ -186,7 +186,7 @@ class User(AbstractBaseUser, PermissionMixin):
         return u'%s (%s)' % (human_name, short_id)
 
     def __repr__(self):
-        return '<User: %r>' % text_type(self)
+        return '<User: %r>' % six.text_type(self)
 
     def clean(self):
         pass
diff --git a/src/authentic2/decorators.py b/src/authentic2/decorators.py
index d84a90b1..444bfd58 100644
--- a/src/authentic2/decorators.py
+++ b/src/authentic2/decorators.py
@@ -165,12 +165,12 @@ class CacheDecoratorBase(object):
         for i, arg in enumerate(args):
             if self.args and i not in self.args:
                 continue
-            parts.append(text_type(arg))
+            parts.append(six.text_type(arg))
 
         for kw, arg in sorted(kwargs.iteritems(), key=lambda x: x[0]):
             if kw not in self.kwargs:
                 continue
-            parts.append(u'%s-%s' % (text_type(kw), text_type(arg)))
+            parts.append(u'%s-%s' % (six.text_type(kw), six.text_type(arg)))
         return u'|'.join(parts)
 
 
diff --git a/src/authentic2/exponential_retry_timeout.py b/src/authentic2/exponential_retry_timeout.py
index c8c7523d..617b59f2 100644
--- a/src/authentic2/exponential_retry_timeout.py
+++ b/src/authentic2/exponential_retry_timeout.py
@@ -27,7 +27,7 @@ class ExponentialRetryTimeout(object):
         self.key_prefix = key_prefix
 
     def key(self, keys):
-        key = u'-'.join(map(text_type, keys))
+        key = u'-'.join(map(six.text_type, keys))
         key = key.encode('utf-8')
         return '%s%s' % (self.key_prefix or self.KEY_PREFIX, hashlib.md5(key).hexdigest())
 
diff --git a/src/authentic2/idp/saml/saml2_endpoints.py b/src/authentic2/idp/saml/saml2_endpoints.py
index eeaccbc9..1c0513b6 100644
--- a/src/authentic2/idp/saml/saml2_endpoints.py
+++ b/src/authentic2/idp/saml/saml2_endpoints.py
@@ -707,7 +707,7 @@ def sso_after_process_request(request, login, consent_obtained=False,
         if dic and 'authz' in dic:
 	    logger.info('decision is %s', dic['authz'])
             if 'message' in dic:
-		logger.info(u'with message %s', text_type(dic['message']))
+		logger.info(u'with message %s', six.text_type(dic['message']))
             if not dic['authz']:
                 logger.info('access denied by an external function')
                 access_granted = False
@@ -719,7 +719,7 @@ def sso_after_process_request(request, login, consent_obtained=False,
             'to the requester')
         set_saml2_response_responder_status_code(login.response,
                 lasso.SAML2_STATUS_CODE_REQUEST_DENIED,
-                msg=text_type(dic['message']))
+                msg=six.text_type(dic['message']))
         return finish_sso(request, login)
 
     provider = load_provider(request, login.remoteProviderId,
diff --git a/src/authentic2/log_filters.py b/src/authentic2/log_filters.py
index 92bddf80..5b533d97 100644
--- a/src/authentic2/log_filters.py
+++ b/src/authentic2/log_filters.py
@@ -18,7 +18,7 @@ class RequestContextFilter(logging.Filter):
         request_id = self.DEFAULT_REQUEST_ID
         if not request is None:
             if hasattr(request, 'user') and request.user.is_authenticated():
-                user = text_type(request.user)
+                user = six.text_type(request.user)
             ip = request.META.get('REMOTE_ADDR', self.DEFAULT_IP)
             request_id = request.request_id
         record.user = user
diff --git a/src/authentic2/management/commands/slapd-shell.py b/src/authentic2/management/commands/slapd-shell.py
index 56254c15..a47c248f 100644
--- a/src/authentic2/management/commands/slapd-shell.py
+++ b/src/authentic2/management/commands/slapd-shell.py
@@ -72,7 +72,7 @@ class Command(BaseCommand):
             for user in qs:
                 o = {}
                 for user_attribute, ldap_attribute in MAPPING.iteritems():
-                    o[ldap_attribute] = [text_type(getattr(user, user_attribute)).encode('utf-8')]
+                    o[ldap_attribute] = [six.text_type(getattr(user, user_attribute)).encode('utf-8')]
                 o['objectClass'] = ['inetOrgPerson']
                 dn = 'uid=%s,%s' % (escape_dn_chars(o['uid'][0]), attrs['suffix'])
                 self.logger.debug(u'sending entry %s %s', dn, o)
diff --git a/src/authentic2/manager/forms.py b/src/authentic2/manager/forms.py
index 12e2ef6e..89d4e90e 100644
--- a/src/authentic2/manager/forms.py
+++ b/src/authentic2/manager/forms.py
@@ -49,7 +49,7 @@ class SlugMixin(forms.ModelForm):
     def save(self, commit=True):
         instance = self.instance
         if not instance.slug:
-            instance.slug = slugify(text_type(instance.name)).lstrip('_')
+            instance.slug = slugify(six.text_type(instance.name)).lstrip('_')
             qs = instance.__class__.objects.all()
             if instance.pk:
                 qs = qs.exclude(pk=instance.pk)
@@ -478,7 +478,7 @@ class OUSearchForm(FormWithRequest):
             if self.show_all_ou and (len(self.ou_qs) > 1 or self.search_all_ous):
                 choices.append(('all', all_ou_label))
             for ou in self.ou_qs:
-                choices.append((str(ou.pk), text_type(ou)))
+                choices.append((str(ou.pk), six.text_type(ou)))
             if self.search_all_ous:
                 choices.append(('none', pgettext('organizational unit', 'None')))
 
diff --git a/src/authentic2/manager/ou_views.py b/src/authentic2/manager/ou_views.py
index 8b8fc143..096df05b 100644
--- a/src/authentic2/manager/ou_views.py
+++ b/src/authentic2/manager/ou_views.py
@@ -43,7 +43,7 @@ class OrganizationalUnitDetailView(views.BaseDetailView):
 
     @property
     def title(self):
-        return text_type(self.object)
+        return six.text_type(self.object)
 
     def authorize(self, request, *args, **kwargs):
         super(OrganizationalUnitDetailView, self).authorize(request, *args, **kwargs)
diff --git a/src/authentic2/manager/resources.py b/src/authentic2/manager/resources.py
index 7e226ddb..8d3d9b3c 100644
--- a/src/authentic2/manager/resources.py
+++ b/src/authentic2/manager/resources.py
@@ -12,7 +12,7 @@ class ListWidget(Widget):
         raise NotImplementedError
 
     def render(self, value):
-        return u', '.join(map(text_type, value.all()))
+        return u', '.join(map(six.text_type, value.all()))
 
 
 class UserResource(ModelResource):
@@ -24,7 +24,7 @@ class UserResource(ModelResource):
             result.add(role)
             for pr in role.parent_relation.all():
                 result.add(pr.parent)
-        return ', '.join(map(text_type, result))
+        return ', '.join(map(six.text_type, result))
 
     class Meta:
         model = get_user_model()
diff --git a/src/authentic2/manager/service_views.py b/src/authentic2/manager/service_views.py
index 493aec01..ea0906e2 100644
--- a/src/authentic2/manager/service_views.py
+++ b/src/authentic2/manager/service_views.py
@@ -31,7 +31,7 @@ class ServiceView(views.SimpleSubTableView, role_views.RoleViewMixin, views.Medi
 
     @property
     def title(self):
-        return text_type(self.object)
+        return six.text_type(self.object)
 
     def get_table_queryset(self):
         return self.object.authorized_roles.all()
diff --git a/src/authentic2/manager/views.py b/src/authentic2/manager/views.py
index a417d584..f350f1cf 100644
--- a/src/authentic2/manager/views.py
+++ b/src/authentic2/manager/views.py
@@ -383,7 +383,7 @@ class ModelNameMixin(MediaMixin):
 
     def get_instance_name(self):
         if hasattr(self, 'get_object'):
-            return text_type(self.get_object())
+            return six.text_type(self.get_object())
         return u''
 
     def get_context_data(self, **kwargs):
@@ -629,9 +629,9 @@ class MenuJson(HomepageView):
         menu_entries = []
         for entry in self.get_homepage_entries():
             menu_entries.append({
-                'label': text_type(entry['label']),
+                'label': six.text_type(entry['label']),
                 'slug': entry.get('slug', ''),
-                'url': request.build_absolute_uri(text_type(entry['href'])),
+                'url': request.build_absolute_uri(six.text_type(entry['href'])),
             })
         return menu_entries
 
@@ -697,7 +697,7 @@ class SiteImportView(MediaMixin, FormView):
             with transaction.atomic():
                 import_site(json_site, ImportContext())
         except DataImportError as e:
-            form.add_error('site_json', text_type(e))
+            form.add_error('site_json', six.text_type(e))
             return self.form_invalid(form)
 
         return super(SiteImportView, self).form_valid(form)
diff --git a/src/authentic2/manager/widgets.py b/src/authentic2/manager/widgets.py
index a6b3a6eb..f6b52085 100644
--- a/src/authentic2/manager/widgets.py
+++ b/src/authentic2/manager/widgets.py
@@ -58,7 +58,7 @@ class SecurityCheckMixin(SplitTermMixin):
 
 class RoleLabelMixin(object):
     def label_from_instance(self, obj):
-        label = text_type(obj)
+        label = six.text_type(obj)
         if obj.ou and utils.get_ou_count() > 1:
             label = u'{ou} - {obj}'.format(
                 ou=obj.ou, obj=obj)
diff --git a/src/authentic2/models.py b/src/authentic2/models.py
index 4c737301..f23ecf06 100644
--- a/src/authentic2/models.py
+++ b/src/authentic2/models.py
@@ -318,7 +318,7 @@ class PasswordReset(models.Model):
         verbose_name_plural = _('password reset')
 
     def __unicode__(self):
-        return text_type(self.user)
+        return six.text_type(self.user)
 
 
 class Service(models.Model):
@@ -374,7 +374,7 @@ class Service(models.Model):
         return self.name
 
     def __repr__(self):
-        return '<%s %r>' % (self.__class__.__name__, text_type(self))
+        return '<%s %r>' % (self.__class__.__name__, six.text_type(self))
 
     def authorize(self, user):
         if not self.authorized_roles.exists():
diff --git a/src/authentic2/saml/admin.py b/src/authentic2/saml/admin.py
index e71a5b92..8568f3c4 100644
--- a/src/authentic2/saml/admin.py
+++ b/src/authentic2/saml/admin.py
@@ -51,7 +51,7 @@ class TextAndFileWidget(forms.widgets.MultiWidget):
     def render(self, name, value, attrs=None):
         if attrs is None:
             attrs = {}
-        if isinstance(value, (str, text_type)):
+        if isinstance(value, (str, six.text_type)):
             attrs['rows'] = value.count('\n') + 5
             attrs['cols'] = min(max((len(x) for x in value.split('\n'))), 150)
         return super(TextAndFileWidget, self).render(name, value, attrs)
diff --git a/src/authentic2/saml/common.py b/src/authentic2/saml/common.py
index 8d26303a..5dced87b 100644
--- a/src/authentic2/saml/common.py
+++ b/src/authentic2/saml/common.py
@@ -319,7 +319,7 @@ def retrieve_metadata_and_create(request, provider_id, sp_or_idp):
         return None
     logger.debug('loaded %d bytes', len(metadata))
     try:
-        metadata = text_type(metadata, 'utf8')
+        metadata = six.text_type(metadata, 'utf8')
     except:
         logging.error('SAML metadata autoload: retrieved metadata for entity '
                       'id %s is not UTF-8', provider_id)
diff --git a/src/authentic2/saml/models.py b/src/authentic2/saml/models.py
index 02eb514d..2cd98f08 100644
--- a/src/authentic2/saml/models.py
+++ b/src/authentic2/saml/models.py
@@ -412,7 +412,7 @@ class LibertyServiceProvider(models.Model):
         return (self.liberty_provider.slug,)
 
     def __unicode__(self):
-        return text_type(self.liberty_provider)
+        return six.text_type(self.liberty_provider)
 
     class Meta:
         verbose_name = _('SAML service provider')
diff --git a/src/authentic2/utils.py b/src/authentic2/utils.py
index ca400c08..58b6e0aa 100644
--- a/src/authentic2/utils.py
+++ b/src/authentic2/utils.py
@@ -358,14 +358,14 @@ def record_authentication_event(request, how, nonce=None):
     # explicitly state that the session has been modified
     request.session.modified = True
     event = {
-        'who': text_type(request.user),
+        'who': six.text_type(request.user),
         'who_id': getattr(request.user, 'pk', None),
         'how': how,
         'when': int(time.time()),
 
     }
     kwargs = {
-        'who': text_type(request.user)[:80],
+        'who': six.text_type(request.user)[:80],
         'how': how,
     }
     nonce = nonce or get_nonce(request)
@@ -541,7 +541,7 @@ def normalize_attribute_values(values):
     for value in values:
         if isinstance(value, bool):
             value = str(value).lower()
-        values_set.add(text_type(value))
+        values_set.add(six.text_type(value))
     return values_set
 
 
@@ -847,7 +847,7 @@ def utf8_encode(v):
         return dict((utf8_encode(a), utf8_encode(b)) for a, b in v.iteritems())
     if isinstance(v, (list, tuple)):
         return type(v)(utf8_encode(a) for a in v)
-    if isinstance(v, text_type):
+    if isinstance(v, six.text_type):
         return v.encode('utf-8')
     return v
 
diff --git a/src/authentic2/views.py b/src/authentic2/views.py
index cda0382c..d12eb186 100644
--- a/src/authentic2/views.py
+++ b/src/authentic2/views.py
@@ -453,7 +453,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView):
                 value = filter(None, value)
                 value = [html_value(attribute, at_value) for at_value in value]
                 if not title:
-                    title = text_type(attribute)
+                    title = six.text_type(attribute)
             else:
                 # fallback to model attributes
                 try:
@@ -472,7 +472,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView):
                 if not isinstance(value, (list, tuple)):
                     value = (value,)
                 raw_value = value
-                value = map(text_type, value)
+                value = map(six.text_type, value)
             if value or app_settings.A2_PROFILE_DISPLAY_EMPTY_FIELDS:
                 profile.append((title, value))
                 attributes.append({'attribute': attribute, 'values': raw_value})
diff --git a/src/authentic2_auth_oidc/backends.py b/src/authentic2_auth_oidc/backends.py
index 601a0a73..a5c436e9 100644
--- a/src/authentic2_auth_oidc/backends.py
+++ b/src/authentic2_auth_oidc/backends.py
@@ -62,7 +62,7 @@ class OIDCBackend(ModelBackend):
                       check_claims={}, algs=algs)
             jwt.claims
 
-        if isinstance(id_token.aud, text_type) and provider.client_id != id_token.aud:
+        if isinstance(id_token.aud, six.text_type) and provider.client_id != id_token.aud:
             logger.warning(u'auth_oidc: invalid id_token audience %s != provider client_id %s',
                            id_token.aud, provider.client_id)
             return None
diff --git a/src/authentic2_auth_oidc/utils.py b/src/authentic2_auth_oidc/utils.py
index 15c69966..f1f05079 100644
--- a/src/authentic2_auth_oidc/utils.py
+++ b/src/authentic2_auth_oidc/utils.py
@@ -97,14 +97,14 @@ def parse_id_token(id_token):
 
 REQUIRED_ID_TOKEN_KEYS = set(['iss', 'sub', 'aud', 'exp', 'iat'])
 KEY_TYPES = {
-    'iss': text_type,
-    'sub': text_type,
+    'iss': six.text_type,
+    'sub': six.text_type,
     'exp': int,
     'iat': int,
     'auth_time': int,
-    'nonce': text_type,
-    'acr': text_type,
-    'azp': text_type,
+    'nonce': six.text_type,
+    'acr': six.text_type,
+    'azp': six.text_type,
     # aud and amr havec specific checks
 }
 
@@ -132,15 +132,15 @@ class IDToken(str):
             raise ValueError('missing field: %s' % (REQUIRED_ID_TOKEN_KEYS - keys))
         for key in keys:
             if key == 'aud':
-                if not isinstance(decoded['aud'], (text_type, list)):
+                if not isinstance(decoded['aud'], (six.text_type, list)):
                     raise ValueError('invalid aud value: %r' % decoded['aud'])
-                if isinstance(decoded['aud'], list) and not all(isinstance(v, text_type) for v in
+                if isinstance(decoded['aud'], list) and not all(isinstance(v, six.text_type) for v in
                                                                 decoded['aud']):
                     raise ValueError('invalid aud value: %r' % decoded['aud'])
             elif key == 'amr':
                 if not isinstance(decoded['amr'], list):
                     raise ValueError('invalid amr value: %s' % decoded['amr'])
-                if not all(isinstance(v, text_type) for v in decoded['amr']):
+                if not all(isinstance(v, six.text_type) for v in decoded['amr']):
                     raise ValueError('invalid amr value: %s' % decoded['amr'])
             elif key in KEY_TYPES:
                 if not isinstance(decoded[key], KEY_TYPES[key]):
diff --git a/src/authentic2_idp_cas/views.py b/src/authentic2_idp_cas/views.py
index 30f149d8..b70076a0 100644
--- a/src/authentic2_idp_cas/views.py
+++ b/src/authentic2_idp_cas/views.py
@@ -214,7 +214,7 @@ class ValidateBaseView(CasMixin, View):
             attributes = self.get_attributes(request, st)
             if st.service.identifier_attribute not in attributes:
                 self.logger.error('unable to compute an identifier for user %r and service %s',
-                        text_type(st.user), st.service_url)
+                        six.text_type(st.user), st.service_url)
                 return self.validation_failure(request, service, INTERNAL_ERROR)
             # Compute user identifier
             identifier = attribute_values_to_identifier(
@@ -246,7 +246,7 @@ class ValidateBaseView(CasMixin, View):
 
     def validation_success(self, request, st, identifier):
         self.logger.info('validation success service: %r ticket: %s '
-                'user: %r identifier: %r', st.service_url, st.ticket_id, text_type(st.user), identifier)
+                'user: %r identifier: %r', st.service_url, st.ticket_id, six.text_type(st.user), identifier)
         return self.real_validation_success(request, st, identifier)
 
 
@@ -275,7 +275,7 @@ class ServiceValidateView(ValidateBaseView):
         root = ET.Element(SERVICE_RESPONSE_ELT)
         success = ET.SubElement(root, AUTHENTICATION_SUCCESS_ELT)
         user = ET.SubElement(success, USER_ELT)
-        user.text = text_type(identifier)
+        user.text = six.text_type(identifier)
         self.provision_pgt(request, st, success)
         self.provision_attributes(request, st, success)
         return HttpResponse(ET.tostring(root, encoding='utf-8'),
@@ -298,7 +298,7 @@ class ServiceValidateView(ValidateBaseView):
         for key, values in values.iteritems():
             for value in values:
                 attribute_elt = ET.SubElement(attributes_elt, '{%s}%s' % (CAS_NAMESPACE, key))
-                attribute_elt.text = text_type(value)
+                attribute_elt.text = six.text_type(value)
 
 
     def provision_pgt(self, request, st, success):
diff --git a/src/authentic2_idp_oidc/models.py b/src/authentic2_idp_oidc/models.py
index c96a834c..b9a4e0ab 100644
--- a/src/authentic2_idp_oidc/models.py
+++ b/src/authentic2_idp_oidc/models.py
@@ -19,7 +19,7 @@ from . import utils, managers
 
 
 def generate_uuid():
-    return text_type(uuid.uuid4())
+    return six.text_type(uuid.uuid4())
 
 
 def validate_https_url(data):
@@ -189,8 +189,8 @@ class OIDCAuthorization(models.Model):
 
     def __repr__(self):
         return '<OIDCAuthorization client:%r user:%r scopes:%r>' % (
-            self.client_id and text_type(self.client),
-            self.user_id and text_type(self.user),
+            self.client_id and six.text_type(self.client),
+            self.user_id and six.text_type(self.user),
             self.scopes)
 
 
@@ -249,8 +249,8 @@ class OIDCCode(models.Model):
     def __repr__(self):
         return '<OIDCCode uuid:%s client:%s user:%s expired:%s scopes:%s>' % (
             self.uuid,
-            self.client_id and text_type(self.client),
-            self.user_id and text_type(self.user),
+            self.client_id and six.text_type(self.client),
+            self.user_id and six.text_type(self.user),
             self.expired,
             self.scopes)
 
@@ -299,8 +299,8 @@ class OIDCAccessToken(models.Model):
     def __repr__(self):
         return '<OIDCAccessToken uuid:%s client:%s user:%s expired:%s scopes:%s>' % (
             self.uuid,
-            self.client_id and text_type(self.client),
-            self.user_id and text_type(self.user),
+            self.client_id and six.text_type(self.client),
+            self.user_id and six.text_type(self.user),
             self.expired,
             self.scopes)
 
diff --git a/src/authentic2_idp_oidc/utils.py b/src/authentic2_idp_oidc/utils.py
index 75d2194e..19e1c771 100644
--- a/src/authentic2_idp_oidc/utils.py
+++ b/src/authentic2_idp_oidc/utils.py
@@ -71,7 +71,7 @@ def scope_set(data):
 
 def clean_words(data):
     '''Clean and order a list of words'''
-    return u' '.join(sorted(map(text_type.strip, data.split())))
+    return u' '.join(sorted(map(six.text_type.strip, data.split())))
 
 
 def url_domain(url):
@@ -82,7 +82,7 @@ def make_sub(client, user):
     if client.identifier_policy in (client.POLICY_PAIRWISE, client.POLICY_PAIRWISE_REVERSIBLE):
         return make_pairwise_sub(client, user)
     elif client.identifier_policy == client.POLICY_UUID:
-        return text_type(user.uuid)
+        return six.text_type(user.uuid)
     elif client.identifier_policy == client.POLICY_EMAIL:
         return user.email
     else:
diff --git a/src/authentic2_idp_oidc/views.py b/src/authentic2_idp_oidc/views.py
index d124c4d5..af3242b3 100644
--- a/src/authentic2_idp_oidc/views.py
+++ b/src/authentic2_idp_oidc/views.py
@@ -266,7 +266,7 @@ def authorize(request, *args, **kwargs):
                     code.uuid, ' '.join(scopes),
                     client.name)
         params = {
-            'code': text_type(code.uuid),
+            'code': six.text_type(code.uuid),
         }
         if state is not None:
             params['state'] = state
@@ -414,7 +414,7 @@ def token(request, *args, **kwargs):
     if oidc_code.nonce is not None:
         id_token['nonce'] = oidc_code.nonce
     response = HttpResponse(json.dumps({
-        'access_token': text_type(access_token.uuid),
+        'access_token': six.text_type(access_token.uuid),
         'token_type': 'Bearer',
         'expires_in': expires_in,
         'id_token': utils.make_idtoken(client, id_token),
diff --git a/src/django_rbac/models.py b/src/django_rbac/models.py
index 8f9fa5d2..d00c67a8 100644
--- a/src/django_rbac/models.py
+++ b/src/django_rbac/models.py
@@ -54,7 +54,7 @@ class AbstractBase(models.Model):
     def save(self, *args, **kwargs):
         # truncate slug and add a hash if it's too long
         if not self.slug:
-            self.slug = slugify(text_type(self.name)).lstrip('_')
+            self.slug = slugify(six.text_type(self.name)).lstrip('_')
         if len(self.slug) > 256:
             self.slug = self.slug[:252] + \
                 hashlib.md5(self.slug).hexdigest()[:4]
@@ -113,7 +113,7 @@ class Operation(models.Model):
         return [self.slug]
 
     def __unicode__(self):
-        return text_type(_(self.name))
+        return six.text_type(_(self.name))
 
     def export_json(self):
         return {'slug': self.slug, 'name': self.name}
diff --git a/src/django_rbac/utils.py b/src/django_rbac/utils.py
index 2213e5ca..70e0c14c 100644
--- a/src/django_rbac/utils.py
+++ b/src/django_rbac/utils.py
@@ -65,6 +65,6 @@ def get_permission_model():
 def get_operation(operation_tpl):
     from . import models
     operation, created = models.Operation.objects.get_or_create(
-        slug=text_type(operation_tpl.slug),
-        defaults={'name': text_type(operation_tpl.name)})
+        slug=six.text_type(operation_tpl.slug),
+        defaults={'name': six.text_type(operation_tpl.name)})
     return operation
-- 
2.20.1

