python3: replace unicode references (#40911)
This commit is contained in:
parent
a15b4cddbb
commit
921a3f27e1
|
@ -16,6 +16,8 @@
|
|||
|
||||
import unicodedata
|
||||
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from rest_framework.views import exception_handler
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
@ -31,8 +33,8 @@ def rest_exception_handler(exc, context):
|
|||
raise
|
||||
response = Response({
|
||||
'err': 1,
|
||||
'exc_class': unicode(exc.__class__),
|
||||
'exc_value': unicode(exc),
|
||||
'exc_class': force_text(exc.__class__),
|
||||
'exc_value': force_text(exc),
|
||||
})
|
||||
response.status = 400
|
||||
return response
|
||||
|
|
|
@ -27,6 +27,7 @@ from django.db.models import F, Value
|
|||
from django.db.models.query import QuerySet, Q
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.timezone import now
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
|
@ -51,7 +52,7 @@ class Transaction(models.Model):
|
|||
null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.id)
|
||||
return force_text(self.id)
|
||||
|
||||
@classmethod
|
||||
def get_transaction(self):
|
||||
|
@ -99,7 +100,7 @@ class CommonData(models.Model):
|
|||
raise ValidationError({'content': e})
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.id)
|
||||
return force_text(self.id)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
@ -316,7 +317,7 @@ class Job(models.Model):
|
|||
job.state = cls.STATE_UNRECOVERABLE_ERROR
|
||||
error = job.content.setdefault('error', {})
|
||||
error['code'] = 'internal-server-error'
|
||||
error['exc_detail'] = unicode(e)
|
||||
error['exc_detail'] = force_text(e)
|
||||
error['exc_tb'] = traceback.format_exc()
|
||||
job.get_logger().exception('exception during job %s', job.admin_url)
|
||||
job.save()
|
||||
|
@ -348,7 +349,7 @@ class Job(models.Model):
|
|||
url = self.admin_url
|
||||
self.get_logger().exception('exception during job %s', url)
|
||||
self.state = self.STATE_UNRECOVERABLE_ERROR
|
||||
self.content['$exc_detail'] = unicode(e)
|
||||
self.content['$exc_detail'] = force_text(e)
|
||||
self.content['$exc_tb'] = traceback.format_exc()
|
||||
self.content['$classpath'] = self.get_classpath(action)
|
||||
self.save()
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
from __future__ import print_function
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from zoo.zoo_meta.models import EntitySchema
|
||||
|
||||
|
@ -24,7 +25,7 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
for schema in EntitySchema.objects.all():
|
||||
if options['verbosity'] >= 1:
|
||||
print('Rebuilding index for', unicode(schema), end=' ')
|
||||
print('Rebuilding index for', force_text(schema), end=' ')
|
||||
schema.rebuild_indexes()
|
||||
if options['verbosity'] >= 1:
|
||||
print(' Done.')
|
||||
|
|
|
@ -18,6 +18,7 @@ from hashlib import md5
|
|||
|
||||
from django.apps import apps
|
||||
from django.db import models, connection
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
|
||||
|
@ -146,8 +147,8 @@ class CommonSchema(models.Model):
|
|||
try:
|
||||
return eval(self.caption_template, {}, value.content)
|
||||
except Exception as e:
|
||||
return unicode(e)
|
||||
return unicode(value.id)
|
||||
return force_text(e)
|
||||
return force_text(value.id)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
|
|
@ -32,6 +32,7 @@ from django.db.models.query import Q
|
|||
from django.db.transaction import non_atomic_requests, atomic
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.timezone import now
|
||||
from django.utils.http import urlencode
|
||||
|
||||
|
@ -134,7 +135,7 @@ class TransactionalView(APIView):
|
|||
content = {
|
||||
'request': self.request.data,
|
||||
'status_code': 500,
|
||||
'$exc_detail': unicode(exc),
|
||||
'$exc_detail': force_text(exc),
|
||||
'$exc_tb': traceback.format_exc(),
|
||||
}
|
||||
self.transaction.content = content
|
||||
|
@ -2054,7 +2055,7 @@ class FalsePositiveView(DoublonActionView):
|
|||
except AssertionError as e:
|
||||
return Response({
|
||||
'err': 1,
|
||||
'errors': unicode(e),
|
||||
'errors': force_text(e),
|
||||
}, status=500)
|
||||
|
||||
|
||||
|
@ -2095,7 +2096,7 @@ class DedupView(DoublonActionView):
|
|||
except AssertionError as e:
|
||||
return Response({
|
||||
'err': 1,
|
||||
'errors': unicode(e),
|
||||
'errors': force_text(e),
|
||||
}, status=500)
|
||||
|
||||
dedup = DedupView.as_view()
|
||||
|
|
|
@ -5,6 +5,7 @@ import datetime
|
|||
import requests
|
||||
from requests.exceptions import RequestException
|
||||
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.timezone import now
|
||||
from django.conf import settings
|
||||
from django.db import DatabaseError
|
||||
|
@ -203,7 +204,7 @@ class FragmentBuilder(object):
|
|||
error_detail = u'erreur réseau/SSL ou expiration'
|
||||
self.error = {
|
||||
'code': 'transport-error',
|
||||
'detail': unicode(e),
|
||||
'detail': force_text(e),
|
||||
}
|
||||
state = self.state_on_network_error
|
||||
else:
|
||||
|
|
|
@ -8,6 +8,7 @@ from zoo.models import Job
|
|||
|
||||
import requests
|
||||
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.timezone import now
|
||||
from django.conf import settings
|
||||
|
||||
|
@ -63,7 +64,7 @@ class QF(object):
|
|||
if response:
|
||||
for qf in response:
|
||||
try:
|
||||
qf['annee_imposition'] = unicode(int(re.findall('(\d+)', qf['libelle'])[0]) - 1)
|
||||
qf['annee_imposition'] = force_text(int(re.findall('(\d+)', qf['libelle'])[0]) - 1)
|
||||
except:
|
||||
qf['annee_imposition'] = 'inconnue'
|
||||
return response, error
|
||||
|
@ -147,7 +148,7 @@ class QF(object):
|
|||
else:
|
||||
return response[0], None
|
||||
else:
|
||||
return None, u'Implicit calcul-qf réponse invalide: %r' % unicode(response)[:1024]
|
||||
return None, u'Implicit calcul-qf réponse invalide: %r' % force_text(response)[:1024]
|
||||
|
||||
def lire_quotient_familial(self, individu, date_de_reference):
|
||||
federation = individu.content['cles_de_federation'].get('implicit')
|
||||
|
@ -168,7 +169,7 @@ class QF(object):
|
|||
return response, None
|
||||
else:
|
||||
return None, (u'Implicit lire-quotient-familial réponse invalide: %r'
|
||||
% unicode(response)[:1024])
|
||||
% force_text(response)[:1024])
|
||||
|
||||
def editer_carte(self, individu, id_qf):
|
||||
federation = individu.content['cles_de_federation'].get('implicit')
|
||||
|
|
|
@ -23,6 +23,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.conf import settings
|
||||
from django.db import DatabaseError
|
||||
from django.db.transaction import atomic
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.six import StringIO
|
||||
|
||||
from zoo.zoo_meta.models import EntitySchema
|
||||
|
@ -108,7 +109,7 @@ class SynchronizeFederationsImport(object):
|
|||
writer.writerow(['RSU ID', 'prenoms', 'nom de naissance',
|
||||
'nom d\'usage', 'application', 'federation', 'action'])
|
||||
for action in self.actions:
|
||||
action = [unicode(v).encode('utf-8') for v in action]
|
||||
action = [force_bytes(v) for v in action]
|
||||
writer.writerow(action)
|
||||
setattr(self.action, target + '_csv_filename',
|
||||
self.action.csv_filename + '-report.csv')
|
||||
|
|
Loading…
Reference in New Issue