summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2020-01-19 18:11:28 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2020-03-17 18:06:44 (GMT)
commit8112d57b0adc2eadd92d30f7cc437deab03a174d (patch)
tree7caeb24bd0f40d12984cdc6cb82c42c04e8200ed
parent46113c03dd60da5f1a9dd7e48f4b046ff84d2893 (diff)
downloadwelco-8112d57b0adc2eadd92d30f7cc437deab03a174d.zip
welco-8112d57b0adc2eadd92d30f7cc437deab03a174d.tar.gz
welco-8112d57b0adc2eadd92d30f7cc437deab03a174d.tar.bz2
python3: replace unicode references (#39092)
-rw-r--r--tests/test_source_phone.py11
-rw-r--r--welco/sources/mail/maarch.py3
-rw-r--r--welco/sources/phone/views.py12
3 files changed, 15 insertions, 11 deletions
diff --git a/tests/test_source_phone.py b/tests/test_source_phone.py
index 80cf049..f648b1e 100644
--- a/tests/test_source_phone.py
+++ b/tests/test_source_phone.py
@@ -21,6 +21,7 @@ import pytest
from django.core.urlresolvers import reverse
from django.test import override_settings
+from django.utils import six
from django.utils.timezone import now, timedelta
from welco.sources.phone import models
@@ -166,13 +167,13 @@ def test_current_calls(user, client):
assert len(data['all-lines']) == 10
for call in data['calls']:
assert set(call.keys()) <= set(['caller', 'callee', 'start', 'data'])
- assert isinstance(call['caller'], unicode)
- assert isinstance(call['callee'], unicode)
- assert isinstance(call['start'], unicode)
+ assert isinstance(call['caller'], six.string_types)
+ assert isinstance(call['callee'], six.string_types)
+ assert isinstance(call['start'], six.string_types)
if 'data' in call:
assert isinstance(call['data'], dict)
- assert len([call for call in data['lines'] if isinstance(call, unicode)]) == 5
- assert len([call for call in data['all-lines'] if isinstance(call, unicode)]) == 10
+ assert len([call for call in data['lines'] if isinstance(call, six.string_types)]) == 5
+ assert len([call for call in data['all-lines'] if isinstance(call, six.string_types)]) == 10
# unregister user to all remaining lines
for number in range(0, 5):
diff --git a/welco/sources/mail/maarch.py b/welco/sources/mail/maarch.py
index ce1f724..11283fa 100644
--- a/welco/sources/mail/maarch.py
+++ b/welco/sources/mail/maarch.py
@@ -17,6 +17,7 @@
import base64
from dateutil.parser import parse as parse_datetime
+from django.utils import six
from django.utils.six.moves.urllib import parse as urlparse
import requests
@@ -88,7 +89,7 @@ class MaarchCourrier(object):
data = {key: self.__dict__[key] for key in self.__dict__ if key not in excluded_keys}
if data:
for key, value in data.items():
- if isinstance(value, basestring):
+ if isinstance(value, six.string_types):
d.append({'column': key, 'value': value, 'type': 'string'})
elif isinstance(value, int):
d.append({'column': key, 'value': str(value), 'type': 'int'})
diff --git a/welco/sources/phone/views.py b/welco/sources/phone/views.py
index 35a0607..ab9dac4 100644
--- a/welco/sources/phone/views.py
+++ b/welco/sources/phone/views.py
@@ -24,6 +24,8 @@ from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest, HttpResponse
+from django.utils import six
+from django.utils.encoding import force_text
from django.utils.timezone import now
from django.views.generic import TemplateView
@@ -90,13 +92,13 @@ def call_event(request):
assert set(['event', 'caller', 'callee']) <= set(payload.keys()), \
'payload keys must be "event", "caller", "callee" and optionnaly "data"'
assert payload['event'] in ('start', 'stop'), 'event must be "start" or "stop"'
- assert isinstance(payload['caller'], unicode), 'caller must be a string'
- assert isinstance(payload['callee'], unicode), 'callee must be a string'
+ assert isinstance(payload['caller'], six.string_types), 'caller must be a string'
+ assert isinstance(payload['callee'], six.string_types), 'callee must be a string'
if 'data' in payload:
assert isinstance(payload['data'], dict), 'data must be a JSON object'
except (TypeError, ValueError, AssertionError), e:
return HttpResponseBadRequest(json.dumps({'err': 1, 'msg':
- unicode(e)}),
+ force_text(e)}),
content_type='application/json')
# janitoring: stop active calls to the callee
if settings.PHONE_ONE_CALL_PER_CALLEE:
@@ -201,7 +203,7 @@ def take_line(request):
assert payload.keys() == ['callee'], 'payload must have only one key: callee'
except (TypeError, ValueError, AssertionError), e:
return HttpResponseBadRequest(json.dumps({'err': 1, 'msg':
- unicode(e)}),
+ force_text(e)}),
content_type='application/json')
PhoneLine.take(payload['callee'], request.user)
logger.info(u'user %s took line %s', request.user, payload['callee'])
@@ -222,7 +224,7 @@ def release_line(request):
assert payload.keys() == ['callee'], 'payload must have only one key: callee'
except (TypeError, ValueError, AssertionError), e:
return HttpResponseBadRequest(json.dumps({'err': 1, 'msg':
- unicode(e)}),
+ force_text(e)}),
content_type='application/json')
PhoneLine.release(payload['callee'], request.user)
logger.info(u'user %s released line %s', request.user, payload['callee'])