Projet

Général

Profil

0001-python3-remove-deprecated-unicode-builtin-31151.patch

Paul Marillonnet, 14 mars 2019 12:51

Télécharger (45 ko)

Voir les différences:

Subject: [PATCH] python3: remove deprecated unicode builtin (#31151)

 src/authentic2/a2_rbac/admin.py                 |  3 ++-
 src/authentic2/a2_rbac/management.py            |  7 ++++---
 src/authentic2/a2_rbac/models.py                |  5 +++--
 src/authentic2/api_views.py                     |  1 +
 src/authentic2/attribute_kinds.py               |  3 ++-
 .../sources/computed_targeted_id.py             |  3 ++-
 .../attributes_ng/sources/django_user.py        |  3 ++-
 src/authentic2/backends/ldap_backend.py         |  3 ++-
 src/authentic2/custom_user/models.py            |  3 ++-
 src/authentic2/decorators.py                    |  5 +++--
 src/authentic2/exponential_retry_timeout.py     |  3 ++-
 src/authentic2/idp/saml/saml2_endpoints.py      |  5 +++--
 src/authentic2/log_filters.py                   |  3 ++-
 .../management/commands/slapd-shell.py          |  3 ++-
 src/authentic2/manager/forms.py                 |  5 +++--
 src/authentic2/manager/ou_views.py              |  3 ++-
 src/authentic2/manager/resources.py             |  5 +++--
 src/authentic2/manager/service_views.py         |  3 ++-
 src/authentic2/manager/views.py                 |  9 +++++----
 src/authentic2/manager/widgets.py               |  3 ++-
 src/authentic2/models.py                        |  5 +++--
 src/authentic2/saml/admin.py                    |  3 ++-
 src/authentic2/saml/common.py                   |  3 ++-
 src/authentic2/saml/models.py                   |  3 ++-
 src/authentic2/utils.py                         |  9 +++++----
 src/authentic2/views.py                         |  5 +++--
 src/authentic2_auth_oidc/backends.py            |  3 ++-
 .../management/commands/oidc-register-issuer.py |  1 +
 src/authentic2_auth_oidc/utils.py               | 17 +++++++++--------
 src/authentic2_idp_cas/views.py                 |  9 +++++----
 src/authentic2_idp_oidc/models.py               | 15 ++++++++-------
 src/authentic2_idp_oidc/utils.py                |  5 +++--
 src/authentic2_idp_oidc/views.py                |  5 +++--
 .../management/commands/provision.py            |  3 ++-
 src/django_rbac/models.py                       |  5 +++--
 src/django_rbac/utils.py                        |  5 +++--
 tests/test_all.py                               |  3 ++-
 tests/test_user_manager.py                      |  9 +++++----
 38 files changed, 112 insertions(+), 74 deletions(-)
src/authentic2/a2_rbac/admin.py
1 1
from django.contrib import admin
2 2
from django.utils.translation import ugettext_lazy as _
3
from django.utils.six import text_type
3 4

  
4 5
from . import models
5 6

  
......
56 57
    list_select_related = True
57 58

  
58 59
    def name(self, obj):
59
        return unicode(obj)
60
        return text_type(obj)
60 61
    name.short_description = _('name')
61 62

  
62 63
admin.site.register(models.Role, RoleAdmin)
src/authentic2/a2_rbac/management.py
1
from django.utils.six import text_type
1 2
from django.utils.translation import ugettext_lazy as _
2 3
from django.utils.text import slugify
3 4
from django.contrib.contenttypes.models import ContentType
......
27 28
        # do not create scoped admin roles if the model is not scopable
28 29
        if not ou_model:
29 30
            continue
30
        name = unicode(MANAGED_CT[key]['name'])
31
        name = text_type(MANAGED_CT[key]['name'])
31 32
        slug = '_a2-' + slugify(name)
32
        scoped_name = unicode(MANAGED_CT[key]['scoped_name'])
33
        scoped_name = text_type(MANAGED_CT[key]['scoped_name'])
33 34
        name = scoped_name.format(ou=ou)
34 35
        ou_slug = slug + '-' + ou.slug
35 36
        if app_settings.MANAGED_CONTENT_TYPES == ():
......
112 113
        if ct_tuple not in MANAGED_CT:
113 114
            continue
114 115
        # General admin role
115
        name = unicode(MANAGED_CT[ct_tuple]['name'])
116
        name = text_type(MANAGED_CT[ct_tuple]['name'])
116 117
        slug = '_a2-' + slugify(name)
117 118
        if app_settings.MANAGED_CONTENT_TYPES is not None and ct_tuple not in \
118 119
                app_settings.MANAGED_CONTENT_TYPES:
src/authentic2/a2_rbac/models.py
1 1
from collections import namedtuple
2 2
from django.core.exceptions import ValidationError
3
from django.utils.six import text_type
3 4
from django.utils.translation import ugettext_lazy as _
4 5
from django.utils.text import slugify
5 6
from django.db import models
......
186 187
        admin_role = self.__class__.objects.get_admin_role(
187 188
            self, ou=self.ou,
188 189
            name=_('Managers of role "{role}"').format(
189
                role=unicode(self)),
190
                role=text_type(self)),
190 191
            slug='_a2-managers-of-role-{role}'.format(
191
                role=slugify(unicode(self))),
192
                role=slugify(text_type(self))),
192 193
            permissions=(utils.get_view_user_perm(),),
193 194
            self_administered=True)
194 195
        return admin_role
src/authentic2/api_views.py
20 20
from django.db import models
21 21
from django.contrib.auth import get_user_model
22 22
from django.core.exceptions import MultipleObjectsReturned
23
from django.utils.six import text_type
23 24
from django.utils.translation import ugettext as _
24 25
from django.utils.encoding import force_text
25 26
from django.views.decorators.vary import vary_on_headers
src/authentic2/attribute_kinds.py
10 10
from django import forms
11 11
from django.core.exceptions import ValidationError
12 12
from django.core.validators import RegexValidator
13
from django.utils.six import text_type
13 14
from django.utils.translation import ugettext_lazy as _, pgettext_lazy
14 15
from django.utils.functional import allow_lazy
15 16
from django.utils import html
......
24 25
from . import app_settings
25 26
from .forms import widgets, fields
26 27

  
27
capfirst = allow_lazy(capfirst, unicode)
28
capfirst = allow_lazy(capfirst, text_type)
28 29

  
29 30
DEFAULT_TITLE_CHOICES = (
30 31
    (pgettext_lazy('title', 'Mrs'), pgettext_lazy('title', 'Mrs')),
src/authentic2/attributes_ng/sources/computed_targeted_id.py
16 16
import base64
17 17

  
18 18
from django.core.exceptions import ImproperlyConfigured
19
from django.utils.six import text_type
19 20

  
20 21
from ...decorators import to_list
21 22

  
......
80 81
    source_attributes_values.append(instance['salt'])
81 82
    hash_algo = instance.get('hash', 'sha1')
82 83
    hasher = getattr(hashlib, hash_algo)
83
    source_attributes_values = map(unicode, source_attributes_values)
84
    source_attributes_values = map(text_type, source_attributes_values)
84 85
    value = u'!'.join(source_attributes_values)
85 86
    value = value.encode('utf-8')
86 87
    value = hasher(value).digest()
src/authentic2/attributes_ng/sources/django_user.py
1
from django.utils.six import text_type
1 2
from django.utils.translation import ugettext_lazy as _
2 3

  
3 4
from django_rbac.utils import get_role_model
......
75 76
        ctx['django_user_' + str(av.attribute.name)] = serialized
76 77
        ctx['django_user_' + str(av.attribute.name) + ':verified'] = av.verified
77 78
    ctx['django_user_groups'] = [group for group in user.groups.all()]
78
    ctx['django_user_group_names'] = [unicode(group) for group in user.groups.all()]
79
    ctx['django_user_group_names'] = [text_type(group) for group in user.groups.all()]
79 80
    if user.username:
80 81
        splitted = user.username.rsplit('@', 1)
81 82
        ctx['django_user_domain'] = splitted[1] if '@' in user.username else ''
src/authentic2/backends/ldap_backend.py
26 26
from django.conf import settings
27 27
from django.contrib.auth.models import Group
28 28
from django.utils.encoding import force_bytes, force_text
29
from django.utils.six import text_type
29 30
from django.utils.six.moves.urllib import parse as urlparse
30 31

  
31 32
from authentic2.a2_rbac.models import Role
......
1142 1143

  
1143 1144
    @classmethod
1144 1145
    def ad_encoding(cls, s):
1145
        '''Encode an unicode string for AD consumption as a password'''
1146
        '''Encode a string for AD consumption as a password'''
1146 1147
        return (u'"{0}"'.format(s)).encode('utf-16-le')
1147 1148

  
1148 1149
    @classmethod
src/authentic2/custom_user/models.py
1 1
from django.db import models
2 2
from django.utils import timezone
3 3
from django.core.mail import send_mail
4
from django.utils.six import text_type
4 5
from django.utils.translation import ugettext_lazy as _
5 6
from django.core.exceptions import ValidationError, MultipleObjectsReturned
6 7
try:
......
185 186
        return u'%s (%s)' % (human_name, short_id)
186 187

  
187 188
    def __repr__(self):
188
        return '<User: %r>' % unicode(self)
189
        return '<User: %r>' % text_type(self)
189 190

  
190 191
    def clean(self):
191 192
        pass
src/authentic2/decorators.py
10 10
from django.http import Http404, HttpResponseForbidden, HttpResponse, HttpResponseBadRequest
11 11
from django.core.cache import cache as django_cache
12 12
from django.core.exceptions import ValidationError
13
from django.utils.six import text_type
13 14

  
14 15
from . import utils, app_settings, middleware
15 16
from .utils import to_list, to_iter
......
164 165
        for i, arg in enumerate(args):
165 166
            if self.args and i not in self.args:
166 167
                continue
167
            parts.append(unicode(arg))
168
            parts.append(text_type(arg))
168 169

  
169 170
        for kw, arg in sorted(kwargs.iteritems(), key=lambda x: x[0]):
170 171
            if kw not in self.kwargs:
171 172
                continue
172
            parts.append(u'%s-%s' % (unicode(kw), unicode(arg)))
173
            parts.append(u'%s-%s' % (text_type(kw), text_type(arg)))
173 174
        return u'|'.join(parts)
174 175

  
175 176

  
src/authentic2/exponential_retry_timeout.py
2 2
import logging
3 3
import hashlib
4 4

  
5
from django.utils.six import text_type
5 6
from django.core.cache import cache
6 7

  
7 8

  
......
26 27
        self.key_prefix = key_prefix
27 28

  
28 29
    def key(self, keys):
29
        key = u'-'.join(map(unicode, keys))
30
        key = u'-'.join(map(text_type, keys))
30 31
        key = key.encode('utf-8')
31 32
        return '%s%s' % (self.key_prefix or self.KEY_PREFIX, hashlib.md5(key).hexdigest())
32 33

  
src/authentic2/idp/saml/saml2_endpoints.py
30 30
from django.core.exceptions import ObjectDoesNotExist
31 31
from django.http import HttpResponse, HttpResponseRedirect, \
32 32
    HttpResponseForbidden, HttpResponseBadRequest
33
from django.utils.six import text_type
33 34
from django.utils.translation import ugettext as _, ugettext_noop as N_
34 35
from django.views.decorators.csrf import csrf_exempt
35 36
from django.views.decorators.cache import never_cache
......
706 707
        if dic and 'authz' in dic:
707 708
	    logger.info('decision is %s', dic['authz'])
708 709
            if 'message' in dic:
709
		logger.info(u'with message %s', unicode(dic['message']))
710
		logger.info(u'with message %s', text_type(dic['message']))
710 711
            if not dic['authz']:
711 712
                logger.info('access denied by an external function')
712 713
                access_granted = False
......
718 719
            'to the requester')
719 720
        set_saml2_response_responder_status_code(login.response,
720 721
                lasso.SAML2_STATUS_CODE_REQUEST_DENIED,
721
                msg=unicode(dic['message']))
722
                msg=text_type(dic['message']))
722 723
        return finish_sso(request, login)
723 724

  
724 725
    provider = load_provider(request, login.remoteProviderId,
src/authentic2/log_filters.py
1 1
import logging
2
from django.utils.six import text_type
2 3

  
3 4
class RequestContextFilter(logging.Filter):
4 5
    DEFAULT_USERNAME = '-'
......
17 18
        request_id = self.DEFAULT_REQUEST_ID
18 19
        if not request is None:
19 20
            if hasattr(request, 'user') and request.user.is_authenticated():
20
                user = unicode(request.user)
21
                user = text_type(request.user)
21 22
            ip = request.META.get('REMOTE_ADDR', self.DEFAULT_IP)
22 23
            request_id = request.request_id
23 24
        record.user = user
src/authentic2/management/commands/slapd-shell.py
11 11

  
12 12
from django.contrib.auth import get_user_model
13 13
from django.core.management.base import BaseCommand
14
from django.utils.six import text_type
14 15
from optparse import make_option
15 16

  
16 17
COMMAND = 1
......
71 72
            for user in qs:
72 73
                o = {}
73 74
                for user_attribute, ldap_attribute in MAPPING.iteritems():
74
                    o[ldap_attribute] = [unicode(getattr(user, user_attribute)).encode('utf-8')]
75
                    o[ldap_attribute] = [text_type(getattr(user, user_attribute)).encode('utf-8')]
75 76
                o['objectClass'] = ['inetOrgPerson']
76 77
                dn = 'uid=%s,%s' % (escape_dn_chars(o['uid'][0]), attrs['suffix'])
77 78
                self.logger.debug(u'sending entry %s %s', dn, o)
src/authentic2/manager/forms.py
6 6
from django import forms
7 7
from django.contrib.contenttypes.models import ContentType
8 8
from django.db.models.query import Q
9
from django.utils.six import text_type
9 10
from django.utils.text import slugify
10 11
from django.core.exceptions import ValidationError
11 12

  
......
48 49
    def save(self, commit=True):
49 50
        instance = self.instance
50 51
        if not instance.slug:
51
            instance.slug = slugify(unicode(instance.name)).lstrip('_')
52
            instance.slug = slugify(text_type(instance.name)).lstrip('_')
52 53
            qs = instance.__class__.objects.all()
53 54
            if instance.pk:
54 55
                qs = qs.exclude(pk=instance.pk)
......
477 478
            if self.show_all_ou and (len(self.ou_qs) > 1 or self.search_all_ous):
478 479
                choices.append(('all', all_ou_label))
479 480
            for ou in self.ou_qs:
480
                choices.append((str(ou.pk), unicode(ou)))
481
                choices.append((str(ou.pk), text_type(ou)))
481 482
            if self.search_all_ous:
482 483
                choices.append(('none', pgettext('organizational unit', 'None')))
483 484

  
src/authentic2/manager/ou_views.py
3 3
from django_rbac.utils import get_ou_model
4 4
from django.http import HttpResponseRedirect
5 5
from django.contrib import messages
6
from django.utils.six import text_type
6 7
from django.utils.translation import ugettext as _
7 8

  
8 9
from authentic2 import data_transfer
......
42 43

  
43 44
    @property
44 45
    def title(self):
45
        return unicode(self.object)
46
        return text_type(self.object)
46 47

  
47 48
    def authorize(self, request, *args, **kwargs):
48 49
        super(OrganizationalUnitDetailView, self).authorize(request, *args, **kwargs)
src/authentic2/manager/resources.py
1
from django.utils.six import text_type
1 2
from import_export.resources import ModelResource
2 3
from import_export.fields import Field
3 4
from import_export.widgets import Widget
......
11 12
        raise NotImplementedError
12 13

  
13 14
    def render(self, value):
14
        return u', '.join(map(unicode, value.all()))
15
        return u', '.join(map(text_type, value.all()))
15 16

  
16 17

  
17 18
class UserResource(ModelResource):
......
23 24
            result.add(role)
24 25
            for pr in role.parent_relation.all():
25 26
                result.add(pr.parent)
26
        return ', '.join(map(unicode, result))
27
        return ', '.join(map(text_type, result))
27 28

  
28 29
    class Meta:
29 30
        model = get_user_model()
src/authentic2/manager/service_views.py
1
from django.utils.six import text_type
1 2
from django.utils.translation import ugettext as _
2 3
from django.contrib import messages
3 4
from django.shortcuts import get_object_or_404
......
30 31

  
31 32
    @property
32 33
    def title(self):
33
        return unicode(self.object)
34
        return text_type(self.object)
34 35

  
35 36
    def get_table_queryset(self):
36 37
        return self.object.authorized_roles.all()
src/authentic2/manager/views.py
9 9
from django.views.generic.detail import SingleObjectMixin
10 10
from django.http import HttpResponse, Http404
11 11
from django.utils.encoding import force_text
12
from django.utils.six import text_type
12 13
from django.utils.translation import ugettext_lazy as _
13 14
from django.utils.timezone import now
14 15
from django.core.urlresolvers import reverse, reverse_lazy
......
382 383

  
383 384
    def get_instance_name(self):
384 385
        if hasattr(self, 'get_object'):
385
            return unicode(self.get_object())
386
            return text_type(self.get_object())
386 387
        return u''
387 388

  
388 389
    def get_context_data(self, **kwargs):
......
628 629
        menu_entries = []
629 630
        for entry in self.get_homepage_entries():
630 631
            menu_entries.append({
631
                'label': unicode(entry['label']),
632
                'label': text_type(entry['label']),
632 633
                'slug': entry.get('slug', ''),
633
                'url': request.build_absolute_uri(unicode(entry['href'])),
634
                'url': request.build_absolute_uri(text_type(entry['href'])),
634 635
            })
635 636
        return menu_entries
636 637

  
......
696 697
            with transaction.atomic():
697 698
                import_site(json_site, ImportContext())
698 699
        except DataImportError as e:
699
            form.add_error('site_json', unicode(e))
700
            form.add_error('site_json', text_type(e))
700 701
            return self.form_invalid(form)
701 702

  
702 703
        return super(SiteImportView, self).form_valid(form)
src/authentic2/manager/widgets.py
4 4
from django_select2.forms import ModelSelect2Widget, ModelSelect2MultipleWidget
5 5

  
6 6
from django.contrib.auth import get_user_model
7
from django.utils.six import text_type
7 8

  
8 9
from django_rbac.backends import DjangoRBACBackend
9 10
from django_rbac.utils import get_role_model, get_ou_model
......
57 58

  
58 59
class RoleLabelMixin(object):
59 60
    def label_from_instance(self, obj):
60
        label = unicode(obj)
61
        label = text_type(obj)
61 62
        if obj.ou and utils.get_ou_count() > 1:
62 63
            label = u'{ou} - {obj}'.format(
63 64
                ou=obj.ou, obj=obj)
src/authentic2/models.py
4 4
from django.conf import settings
5 5
from django.db import models
6 6
from django.db.models.query import Q
7
from django.utils.six import text_type
7 8
from django.utils.translation import ugettext_lazy as _
8 9
from django.utils.six.moves.urllib import parse as urlparse
9 10
from django.core.exceptions import ValidationError, FieldDoesNotExist
......
317 318
        verbose_name_plural = _('password reset')
318 319

  
319 320
    def __unicode__(self):
320
        return unicode(self.user)
321
        return text_type(self.user)
321 322

  
322 323

  
323 324
class Service(models.Model):
......
373 374
        return self.name
374 375

  
375 376
    def __repr__(self):
376
        return '<%s %r>' % (self.__class__.__name__, unicode(self))
377
        return '<%s %r>' % (self.__class__.__name__, text_type(self))
377 378

  
378 379
    def authorize(self, user):
379 380
        if not self.authorized_roles.exists():
src/authentic2/saml/admin.py
1 1
import logging
2 2

  
3 3
from django.contrib import admin
4
from django.utils.six import text_type
4 5
from django.utils.translation import ugettext as _
5 6
from django.conf.urls import url
6 7
from django.conf import settings
......
50 51
    def render(self, name, value, attrs=None):
51 52
        if attrs is None:
52 53
            attrs = {}
53
        if isinstance(value, (str, unicode)):
54
        if isinstance(value, (str, text_type)):
54 55
            attrs['rows'] = value.count('\n') + 5
55 56
            attrs['cols'] = min(max((len(x) for x in value.split('\n'))), 150)
56 57
        return super(TextAndFileWidget, self).render(name, value, attrs)
src/authentic2/saml/common.py
10 10
from django.conf import settings
11 11
from django.http import HttpResponseRedirect, Http404, HttpResponse
12 12
from django.shortcuts import render
13
from django.utils.six import text_type
13 14
from django.utils.six.moves.urllib import parse as urlparse
14 15
from django.core.exceptions import ValidationError
15 16

  
......
318 319
        return None
319 320
    logger.debug('loaded %d bytes', len(metadata))
320 321
    try:
321
        metadata = unicode(metadata, 'utf8')
322
        metadata = text_type(metadata, 'utf8')
322 323
    except:
323 324
        logging.error('SAML metadata autoload: retrieved metadata for entity '
324 325
                      'id %s is not UTF-8', provider_id)
src/authentic2/saml/models.py
12 12
from django.db.models import Q
13 13
from django.conf import settings
14 14
from django.core.exceptions import ValidationError
15
from django.utils.six import text_type
15 16
from django.utils.translation import ugettext_lazy as _
16 17
from django.core.exceptions import ObjectDoesNotExist
17 18
from django.contrib.contenttypes.models import ContentType
......
411 412
        return (self.liberty_provider.slug,)
412 413

  
413 414
    def __unicode__(self):
414
        return unicode(self.liberty_provider)
415
        return text_type(self.liberty_provider)
415 416

  
416 417
    class Meta:
417 418
        verbose_name = _('SAML service provider')
src/authentic2/utils.py
34 34
from django.utils.functional import empty, allow_lazy
35 35
from django.utils.http import urlsafe_base64_encode
36 36
from django.utils.encoding import iri_to_uri, force_bytes, uri_to_iri
37
from django.utils.six import text_type
37 38
from django.shortcuts import render
38 39

  
39 40

  
......
357 358
    # explicitly state that the session has been modified
358 359
    request.session.modified = True
359 360
    event = {
360
        'who': unicode(request.user),
361
        'who': text_type(request.user),
361 362
        'who_id': getattr(request.user, 'pk', None),
362 363
        'how': how,
363 364
        'when': int(time.time()),
364 365

  
365 366
    }
366 367
    kwargs = {
367
        'who': unicode(request.user)[:80],
368
        'who': text_type(request.user)[:80],
368 369
        'how': how,
369 370
    }
370 371
    nonce = nonce or get_nonce(request)
......
540 541
    for value in values:
541 542
        if isinstance(value, bool):
542 543
            value = str(value).lower()
543
        values_set.add(unicode(value))
544
        values_set.add(text_type(value))
544 545
    return values_set
545 546

  
546 547

  
......
846 847
        return dict((utf8_encode(a), utf8_encode(b)) for a, b in v.iteritems())
847 848
    if isinstance(v, (list, tuple)):
848 849
        return type(v)(utf8_encode(a) for a in v)
849
    if isinstance(v, unicode):
850
    if isinstance(v, text_type):
850 851
        return v.encode('utf-8')
851 852
    return v
852 853

  
src/authentic2/views.py
18 18
from django.core.urlresolvers import reverse
19 19
from django.core.exceptions import ValidationError
20 20
from django.contrib import messages
21
from django.utils.six import text_type
21 22
from django.utils.translation import ugettext as _
22 23
from django.contrib.auth import logout as auth_logout
23 24
from django.contrib.auth import REDIRECT_FIELD_NAME
......
452 453
                value = filter(None, value)
453 454
                value = [html_value(attribute, at_value) for at_value in value]
454 455
                if not title:
455
                    title = unicode(attribute)
456
                    title = text_type(attribute)
456 457
            else:
457 458
                # fallback to model attributes
458 459
                try:
......
471 472
                if not isinstance(value, (list, tuple)):
472 473
                    value = (value,)
473 474
                raw_value = value
474
                value = map(unicode, value)
475
                value = map(text_type, value)
475 476
            if value or app_settings.A2_PROFILE_DISPLAY_EMPTY_FIELDS:
476 477
                profile.append((title, value))
477 478
                attributes.append({'attribute': attribute, 'values': raw_value})
src/authentic2_auth_oidc/backends.py
6 6
from jwcrypto.jwt import JWT
7 7
from jwcrypto.jwk import JWK
8 8

  
9
from django.utils.six import text_type
9 10
from django.utils.timezone import now
10 11
from django.contrib.auth import get_user_model
11 12
from django.contrib.auth.backends import ModelBackend
......
61 62
                      check_claims={}, algs=algs)
62 63
            jwt.claims
63 64

  
64
        if isinstance(id_token.aud, unicode) and provider.client_id != id_token.aud:
65
        if isinstance(id_token.aud, text_type) and provider.client_id != id_token.aud:
65 66
            logger.warning(u'auth_oidc: invalid id_token audience %s != provider client_id %s',
66 67
                           id_token.aud, provider.client_id)
67 68
            return None
src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py
6 6

  
7 7
from django.core.management.base import BaseCommand, CommandError
8 8
from django.core.exceptions import ValidationError
9
from django.utils.six import text_type
9 10

  
10 11
from authentic2.compat import atomic
11 12

  
src/authentic2_auth_oidc/utils.py
4 4

  
5 5
import requests
6 6

  
7
from django.utils.six import text_type
7 8
from django.utils.timezone import utc
8 9
from django.shortcuts import get_object_or_404
9 10
from django.utils.translation import ugettext as _
......
96 97

  
97 98
REQUIRED_ID_TOKEN_KEYS = set(['iss', 'sub', 'aud', 'exp', 'iat'])
98 99
KEY_TYPES = {
99
    'iss': unicode,
100
    'sub': unicode,
100
    'iss': text_type,
101
    'sub': text_type,
101 102
    'exp': int,
102 103
    'iat': int,
103 104
    'auth_time': int,
104
    'nonce': unicode,
105
    'acr': unicode,
106
    'azp': unicode,
105
    'nonce': text_type,
106
    'acr': text_type,
107
    'azp': text_type,
107 108
    # aud and amr havec specific checks
108 109
}
109 110

  
......
131 132
            raise ValueError('missing field: %s' % (REQUIRED_ID_TOKEN_KEYS - keys))
132 133
        for key in keys:
133 134
            if key == 'aud':
134
                if not isinstance(decoded['aud'], (unicode, list)):
135
                if not isinstance(decoded['aud'], (text_type, list)):
135 136
                    raise ValueError('invalid aud value: %r' % decoded['aud'])
136
                if isinstance(decoded['aud'], list) and not all(isinstance(v, unicode) for v in
137
                if isinstance(decoded['aud'], list) and not all(isinstance(v, text_type) for v in
137 138
                                                                decoded['aud']):
138 139
                    raise ValueError('invalid aud value: %r' % decoded['aud'])
139 140
            elif key == 'amr':
140 141
                if not isinstance(decoded['amr'], list):
141 142
                    raise ValueError('invalid amr value: %s' % decoded['amr'])
142
                if not all(isinstance(v, unicode) for v in decoded['amr']):
143
                if not all(isinstance(v, text_type) for v in decoded['amr']):
143 144
                    raise ValueError('invalid amr value: %s' % decoded['amr'])
144 145
            elif key in KEY_TYPES:
145 146
                if not isinstance(decoded[key], KEY_TYPES[key]):
src/authentic2_idp_cas/views.py
7 7

  
8 8
from django.http import HttpResponseBadRequest, HttpResponse
9 9
from django.views.generic.base import View
10
from django.utils.six import text_type
10 11
from django.utils.timezone import now
11 12

  
12 13
from authentic2.utils import (get_user_from_session_key, make_url,
......
213 214
            attributes = self.get_attributes(request, st)
214 215
            if st.service.identifier_attribute not in attributes:
215 216
                self.logger.error('unable to compute an identifier for user %r and service %s',
216
                        unicode(st.user), st.service_url)
217
                        text_type(st.user), st.service_url)
217 218
                return self.validation_failure(request, service, INTERNAL_ERROR)
218 219
            # Compute user identifier
219 220
            identifier = attribute_values_to_identifier(
......
245 246

  
246 247
    def validation_success(self, request, st, identifier):
247 248
        self.logger.info('validation success service: %r ticket: %s '
248
                'user: %r identifier: %r', st.service_url, st.ticket_id, unicode(st.user), identifier)
249
                'user: %r identifier: %r', st.service_url, st.ticket_id, text_type(st.user), identifier)
249 250
        return self.real_validation_success(request, st, identifier)
250 251

  
251 252

  
......
274 275
        root = ET.Element(SERVICE_RESPONSE_ELT)
275 276
        success = ET.SubElement(root, AUTHENTICATION_SUCCESS_ELT)
276 277
        user = ET.SubElement(success, USER_ELT)
277
        user.text = unicode(identifier)
278
        user.text = text_type(identifier)
278 279
        self.provision_pgt(request, st, success)
279 280
        self.provision_attributes(request, st, success)
280 281
        return HttpResponse(ET.tostring(root, encoding='utf-8'),
......
297 298
        for key, values in values.iteritems():
298 299
            for value in values:
299 300
                attribute_elt = ET.SubElement(attributes_elt, '{%s}%s' % (CAS_NAMESPACE, key))
300
                attribute_elt.text = unicode(value)
301
                attribute_elt.text = text_type(value)
301 302

  
302 303

  
303 304
    def provision_pgt(self, request, st, success):
src/authentic2_idp_oidc/models.py
7 7
from django.core.exceptions import ValidationError, ImproperlyConfigured
8 8
from django.utils.translation import ugettext_lazy as _
9 9
from django.conf import settings
10
from django.utils.six import text_type
10 11
from django.utils.timezone import now
11 12
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
12 13

  
......
18 19

  
19 20

  
20 21
def generate_uuid():
21
    return unicode(uuid.uuid4())
22
    return text_type(uuid.uuid4())
22 23

  
23 24

  
24 25
def validate_https_url(data):
......
188 189

  
189 190
    def __repr__(self):
190 191
        return '<OIDCAuthorization client:%r user:%r scopes:%r>' % (
191
            self.client_id and unicode(self.client),
192
            self.user_id and unicode(self.user),
192
            self.client_id and text_type(self.client),
193
            self.user_id and text_type(self.user),
193 194
            self.scopes)
194 195

  
195 196

  
......
248 249
    def __repr__(self):
249 250
        return '<OIDCCode uuid:%s client:%s user:%s expired:%s scopes:%s>' % (
250 251
            self.uuid,
251
            self.client_id and unicode(self.client),
252
            self.user_id and unicode(self.user),
252
            self.client_id and text_type(self.client),
253
            self.user_id and text_type(self.user),
253 254
            self.expired,
254 255
            self.scopes)
255 256

  
......
298 299
    def __repr__(self):
299 300
        return '<OIDCAccessToken uuid:%s client:%s user:%s expired:%s scopes:%s>' % (
300 301
            self.uuid,
301
            self.client_id and unicode(self.client),
302
            self.user_id and unicode(self.user),
302
            self.client_id and text_type(self.client),
303
            self.user_id and text_type(self.user),
303 304
            self.expired,
304 305
            self.scopes)
305 306

  
src/authentic2_idp_oidc/utils.py
9 9
from django.core.exceptions import ImproperlyConfigured
10 10
from django.conf import settings
11 11
from django.utils.encoding import smart_bytes
12
from django.utils.six import text_type
12 13
from django.utils.six.moves.urllib import parse as urlparse
13 14

  
14 15
from authentic2 import hooks, crypto
......
70 71

  
71 72
def clean_words(data):
72 73
    '''Clean and order a list of words'''
73
    return u' '.join(sorted(map(unicode.strip, data.split())))
74
    return u' '.join(sorted(map(text_type.strip, data.split())))
74 75

  
75 76

  
76 77
def url_domain(url):
......
81 82
    if client.identifier_policy in (client.POLICY_PAIRWISE, client.POLICY_PAIRWISE_REVERSIBLE):
82 83
        return make_pairwise_sub(client, user)
83 84
    elif client.identifier_policy == client.POLICY_UUID:
84
        return unicode(user.uuid)
85
        return text_type(user.uuid)
85 86
    elif client.identifier_policy == client.POLICY_EMAIL:
86 87
        return user.email
87 88
    else:
src/authentic2_idp_oidc/views.py
5 5
import time
6 6

  
7 7
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed
8
from django.utils.six import text_type
8 9
from django.utils.timezone import now, utc
9 10
from django.utils.http import urlencode
10 11
from django.shortcuts import render
......
265 266
                    code.uuid, ' '.join(scopes),
266 267
                    client.name)
267 268
        params = {
268
            'code': unicode(code.uuid),
269
            'code': text_type(code.uuid),
269 270
        }
270 271
        if state is not None:
271 272
            params['state'] = state
......
413 414
    if oidc_code.nonce is not None:
414 415
        id_token['nonce'] = oidc_code.nonce
415 416
    response = HttpResponse(json.dumps({
416
        'access_token': unicode(access_token.uuid),
417
        'access_token': text_type(access_token.uuid),
417 418
        'token_type': 'Bearer',
418 419
        'expires_in': expires_in,
419 420
        'id_token': utils.make_idtoken(client, id_token),
src/authentic2_provisionning_ldap/management/commands/provision.py
9 9
from ldaptools import paged
10 10

  
11 11
from django.core.management.base import BaseCommand
12
from django.utils.six import text_type
12 13

  
13 14
from authentic2.attributes_ng.engine import get_attributes
14 15
from authentic2 import compat, utils
......
52 53
            values = [values]
53 54
        ldap_values = ldap_attributes.setdefault(ldap_attribute, [])
54 55
        for value in values:
55
            if isinstance(value, unicode):
56
            if isinstance(value, text_type):
56 57
                value = value.encode('utf-8')
57 58
            elif isinstance(value, str):
58 59
                pass # must be well encoded
src/django_rbac/models.py
1 1
import operator
2 2
import hashlib
3 3

  
4
from django.utils.six import text_type
4 5
from django.utils.text import slugify
5 6
from django.utils.translation import ugettext_lazy as _
6 7
from django.db import models
......
53 54
    def save(self, *args, **kwargs):
54 55
        # truncate slug and add a hash if it's too long
55 56
        if not self.slug:
56
            self.slug = slugify(unicode(self.name)).lstrip('_')
57
            self.slug = slugify(text_type(self.name)).lstrip('_')
57 58
        if len(self.slug) > 256:
58 59
            self.slug = self.slug[:252] + \
59 60
                hashlib.md5(self.slug).hexdigest()[:4]
......
112 113
        return [self.slug]
113 114

  
114 115
    def __unicode__(self):
115
        return unicode(_(self.name))
116
        return text_type(_(self.name))
116 117

  
117 118
    def export_json(self):
118 119
        return {'slug': self.slug, 'name': self.name}
src/django_rbac/utils.py
2 2
from authentic2.decorators import GlobalCache
3 3
from django.conf import settings
4 4
from django.apps import apps
5
from django.utils.six import text_type
5 6

  
6 7
from . import constants
7 8

  
......
64 65
def get_operation(operation_tpl):
65 66
    from . import models
66 67
    operation, created = models.Operation.objects.get_or_create(
67
        slug=unicode(operation_tpl.slug),
68
        defaults={'name': unicode(operation_tpl.name)})
68
        slug=text_type(operation_tpl.slug),
69
        defaults={'name': text_type(operation_tpl.name)})
69 70
    return operation
tests/test_all.py
13 13
from django.contrib.auth import get_user_model
14 14
from django.contrib.contenttypes.models import ContentType
15 15
from django.utils.translation import ugettext as _
16
from django.utils.six import text_type
16 17
from django.utils.six.moves.urllib import parse as urlparse
17 18

  
18 19
from rest_framework import test
......
403 404
        for i, name in enumerate(attribute_kinds.get_attribute_kinds()):
404 405
            fields['field_%d' % i] = attribute_kinds.get_form_field(name)
405 406
        AttributeKindForm = type('AttributeKindForm', (forms.Form,), fields)
406
        unicode(AttributeKindForm().as_p())
407
        text_type(AttributeKindForm().as_p())
407 408

  
408 409

  
409 410
class APITest(TestCase):
tests/test_user_manager.py
3 3
from django.core.urlresolvers import reverse
4 4

  
5 5
from django.contrib.contenttypes.models import ContentType
6
from django.utils.six import text_type
6 7

  
7 8
from authentic2.custom_user.models import User
8 9
from authentic2.models import Attribute, AttributeValue
......
27 28

  
28 29
    response = login(app, superuser_or_admin,
29 30
                     reverse('a2-manager-user-by-uuid-detail',
30
                             kwargs={'slug': unicode(simple_user.uuid)}))
31
                             kwargs={'slug': text_type(simple_user.uuid)}))
31 32
    assert 'Change user email' in response.content
32 33
    # cannot click it's a submit button :/
33 34
    response = app.get(reverse('a2-manager-user-by-uuid-change-email',
34
                               kwargs={'slug': unicode(simple_user.uuid)}))
35
                               kwargs={'slug': text_type(simple_user.uuid)}))
35 36
    assert response.form['new_email'].value == simple_user.email
36 37
    response.form.set('new_email', NEW_EMAIL)
37 38
    assert len(mailoutbox) == 0
......
66 67

  
67 68
    response = login(app, superuser_or_admin,
68 69
                     reverse('a2-manager-user-by-uuid-detail',
69
                             kwargs={'slug': unicode(simple_user.uuid)}))
70
                             kwargs={'slug': text_type(simple_user.uuid)}))
70 71
    assert 'Change user email' in response.content
71 72
    # cannot click it's a submit button :/
72 73
    response = app.get(reverse('a2-manager-user-by-uuid-change-email',
73
                               kwargs={'slug': unicode(simple_user.uuid)}))
74
                               kwargs={'slug': text_type(simple_user.uuid)}))
74 75
    assert response.form['new_email'].value == simple_user.email
75 76
    assert len(mailoutbox) == 0
76 77
    response = response.form.submit().follow()
77
-