0002-replaced-force_text-with-equivalent-force_str-68183.patch
combo/apps/calendar/views.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
from django.contrib import messages |
18 | 18 |
from django.http import HttpResponseRedirect |
19 |
from django.utils.encoding import force_text
|
|
19 |
from django.utils.encoding import force_str
|
|
20 | 20 |
from django.views.generic import DetailView, View |
21 | 21 |
from django.views.generic.detail import SingleObjectMixin |
22 | 22 | |
... | ... | |
36 | 36 |
try: |
37 | 37 |
form.is_valid() |
38 | 38 |
except ValueError as exc: |
39 |
messages.error(request, force_text(exc))
|
|
39 |
messages.error(request, force_str(exc))
|
|
40 | 40 |
redirect_url = '%s?%s' % (cell.page.get_online_url(), request.GET.urlencode()) |
41 | 41 |
return HttpResponseRedirect(redirect_url) |
42 | 42 |
data = form.cleaned_data |
combo/apps/dashboard/views.py | ||
---|---|---|
28 | 28 |
HttpResponseRedirect, |
29 | 29 |
) |
30 | 30 |
from django.urls import reverse |
31 |
from django.utils.encoding import force_text
|
|
31 |
from django.utils.encoding import force_str
|
|
32 | 32 |
from django.views.decorators.csrf import csrf_exempt |
33 | 33 |
from django.views.generic import View |
34 | 34 |
from rest_framework import permissions |
... | ... | |
130 | 130 |
return HttpResponseNotAllowed(['post']) |
131 | 131 | |
132 | 132 |
try: |
133 |
request_body = json.loads(force_text(request.body))
|
|
133 |
request_body = json.loads(force_str(request.body))
|
|
134 | 134 |
except json.JSONDecodeError: |
135 | 135 |
return HttpResponseBadRequest('bad json request: "%s"' % request.body) |
136 | 136 |
combo/apps/dataviz/models.py | ||
---|---|---|
31 | 31 |
from django.urls import reverse |
32 | 32 |
from django.utils import timezone |
33 | 33 |
from django.utils.dates import WEEKDAYS |
34 |
from django.utils.encoding import force_text
|
|
34 |
from django.utils.encoding import force_str
|
|
35 | 35 |
from django.utils.functional import cached_property |
36 | 36 |
from django.utils.translation import gettext |
37 | 37 |
from django.utils.translation import gettext_lazy as _ |
... | ... | |
646 | 646 |
value = hours_string |
647 | 647 |
else: |
648 | 648 |
value = _('Less than an hour') |
649 |
return force_text(value)
|
|
649 |
return force_str(value)
|
|
650 | 650 | |
651 | 651 |
return format_duration |
652 | 652 |
elif measure == 'percent': |
combo/apps/lingo/views.py | ||
---|---|---|
40 | 40 |
from django.template.response import TemplateResponse |
41 | 41 |
from django.urls import reverse |
42 | 42 |
from django.utils import dateparse |
43 |
from django.utils.encoding import force_text, smart_text
|
|
43 |
from django.utils.encoding import force_str, smart_text
|
|
44 | 44 |
from django.utils.http import urlencode |
45 | 45 |
from django.utils.translation import gettext_lazy as _ |
46 | 46 |
from django.views.decorators.csrf import csrf_exempt |
... | ... | |
138 | 138 |
return HttpResponseForbidden() |
139 | 139 | |
140 | 140 |
try: |
141 |
request_body = json.loads(force_text(request.body))
|
|
141 |
request_body = json.loads(force_str(request.body))
|
|
142 | 142 |
except json.JSONDecodeError: |
143 | 143 |
return BadRequestJsonResponse('bad json request: "%s"' % request.body) |
144 | 144 | |
... | ... | |
247 | 247 |
return HttpResponseForbidden() |
248 | 248 | |
249 | 249 |
try: |
250 |
request_body = json.loads(force_text(request.body))
|
|
250 |
request_body = json.loads(force_str(request.body))
|
|
251 | 251 |
except json.JSONDecodeError: |
252 | 252 |
return BadRequestJsonResponse('bad json request: "%s"' % request.body) |
253 | 253 | |
... | ... | |
311 | 311 |
) |
312 | 312 |
except eopayment.ResponseError as e: |
313 | 313 |
logger.error('failed in validation operation: %s', e) |
314 |
return JsonResponse({'err': 1, 'e': force_text(e)})
|
|
314 |
return JsonResponse({'err': 1, 'e': force_str(e)})
|
|
315 | 315 | |
316 | 316 |
logger.info('bank validation result: %r', result) |
317 | 317 |
operation = TransactionOperation( |
... | ... | |
348 | 348 |
result = transaction.make_eopayment(request=request).backend.cancel(amount, transaction.bank_data) |
349 | 349 |
except eopayment.ResponseError as e: |
350 | 350 |
logger.error('failed in cancel operation: %s', e) |
351 |
return JsonResponse({'err': 1, 'e': force_text(e)})
|
|
351 |
return JsonResponse({'err': 1, 'e': force_str(e)})
|
|
352 | 352 | |
353 | 353 |
logger.info('bank cancellation result: %r', result) |
354 | 354 |
operation = TransactionOperation( |
... | ... | |
683 | 683 |
request.method, |
684 | 684 |
backend_response, |
685 | 685 |
) |
686 |
return HttpResponseBadRequest(force_text(e))
|
|
686 |
return HttpResponseBadRequest(force_str(e))
|
|
687 | 687 |
logger.info('lingo: received synchronous payment notification for %s', transaction) |
688 | 688 |
return HttpResponse() |
689 | 689 | |
... | ... | |
691 | 691 |
return self.handle_callback(request, request.environ['QUERY_STRING'], **kwargs) |
692 | 692 | |
693 | 693 |
def post(self, request, *args, **kwargs): |
694 |
return self.handle_callback(request, force_text(request.body), **kwargs)
|
|
694 |
return self.handle_callback(request, force_str(request.body), **kwargs)
|
|
695 | 695 | |
696 | 696 |
@csrf_exempt |
697 | 697 |
def dispatch(self, *args, **kwargs): |
... | ... | |
708 | 708 | |
709 | 709 |
def post(self, request, *args, **kwargs): |
710 | 710 |
return self.handle_return( |
711 |
request, force_text(request.body) or request.environ['QUERY_STRING'], **kwargs
|
|
711 |
request, force_str(request.body) or request.environ['QUERY_STRING'], **kwargs
|
|
712 | 712 |
) |
713 | 713 | |
714 | 714 |
def handle_return(self, request, backend_response, **kwargs): |
... | ... | |
910 | 910 |
else: |
911 | 911 |
msg = _('Sorry, no invoice were found with that number and amount.') |
912 | 912 |
if request.GET.get('ajax') == 'on': |
913 |
return JsonResponse({'url': url, 'msg': msg and force_text(msg)})
|
|
913 |
return JsonResponse({'url': url, 'msg': msg and force_str(msg)})
|
|
914 | 914 |
if url: |
915 | 915 |
return HttpResponseRedirect(url) |
916 | 916 |
messages.warning(request, msg) |
combo/apps/maps/forms.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
from django import forms |
18 |
from django.utils.encoding import force_text
|
|
18 |
from django.utils.encoding import force_str
|
|
19 | 19 |
from django.utils.text import slugify |
20 | 20 |
from django.utils.translation import gettext_lazy as _ |
21 | 21 | |
... | ... | |
58 | 58 |
# new widget for icon field |
59 | 59 |
self.fields['icon'].widget = IconRadioSelect() |
60 | 60 |
self.fields['icon'].choices = list( |
61 |
sorted(self.fields['icon'].choices, key=lambda x: slugify(force_text(x[1])))
|
|
61 |
sorted(self.fields['icon'].choices, key=lambda x: slugify(force_str(x[1])))
|
|
62 | 62 |
) |
63 | 63 |
if self.instance.kind == 'geojson': |
64 | 64 |
todelete_fields = ['tiles_template_url', 'tiles_attribution', 'tiles_default'] |
combo/apps/notifications/api_views.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
from django.contrib.auth.models import User |
18 | 18 |
from django.db import transaction |
19 |
from django.utils.encoding import force_text
|
|
19 |
from django.utils.encoding import force_str
|
|
20 | 20 |
from rest_framework import authentication, permissions, serializers, status |
21 | 21 |
from rest_framework.generics import GenericAPIView |
22 | 22 |
from rest_framework.response import Response |
... | ... | |
96 | 96 |
) |
97 | 97 |
notification_ids.append(notification.public_id) |
98 | 98 |
except ValueError as e: |
99 |
response = {'err': 1, 'err_desc': {'id': [force_text(e)]}}
|
|
99 |
response = {'err': 1, 'err_desc': {'id': [force_str(e)]}}
|
|
100 | 100 |
return Response(response, status.HTTP_400_BAD_REQUEST) |
101 | 101 | |
102 | 102 |
data = {} |
combo/apps/notifications/models.py | ||
---|---|---|
20 | 20 |
from django.db import models |
21 | 21 |
from django.db.models import Q |
22 | 22 |
from django.db.models.query import QuerySet |
23 |
from django.utils.encoding import force_text
|
|
23 |
from django.utils.encoding import force_str
|
|
24 | 24 |
from django.utils.timezone import now, timedelta |
25 | 25 |
from django.utils.translation import gettext_lazy as _ |
26 | 26 | |
... | ... | |
145 | 145 | |
146 | 146 |
if id: |
147 | 147 |
try: |
148 |
id = force_text(id)
|
|
148 |
id = force_str(id)
|
|
149 | 149 |
except Exception as e: |
150 | 150 |
raise ValueError('id must be convertible to unicode', e) |
151 | 151 |
if not re.match(cls.ID_RE, id): |
combo/apps/pwa/models.py | ||
---|---|---|
25 | 25 |
from django.core.files.base import ContentFile |
26 | 26 |
from django.core.files.storage import default_storage |
27 | 27 |
from django.db import models |
28 |
from django.utils.encoding import force_bytes, force_text
|
|
28 |
from django.utils.encoding import force_bytes, force_str
|
|
29 | 29 |
from django.utils.translation import gettext_lazy as _ |
30 | 30 |
from py_vapid import Vapid |
31 | 31 | |
... | ... | |
73 | 73 |
vapid = Vapid() |
74 | 74 |
vapid.generate_keys() |
75 | 75 |
self.push_notifications_infos = { |
76 |
'private_key': force_text(vapid.private_pem()),
|
|
76 |
'private_key': force_str(vapid.private_pem()),
|
|
77 | 77 |
} |
78 | 78 |
elif not self.push_notifications: |
79 | 79 |
self.push_notifications_infos = {} |
... | ... | |
91 | 91 |
serialized_settings = json.loads(serializers.serialize('json', [obj])) |
92 | 92 |
result = serialized_settings[0].get('fields') |
93 | 93 |
if obj.application_icon: |
94 |
result['icon:base64'] = force_text(base64.encodebytes(obj.application_icon.read()))
|
|
94 |
result['icon:base64'] = force_str(base64.encodebytes(obj.application_icon.read()))
|
|
95 | 95 |
return result |
96 | 96 | |
97 | 97 |
@classmethod |
... | ... | |
171 | 171 |
) |
172 | 172 |
)[0] |
173 | 173 |
if self.icon: |
174 |
serialized_entry['icon:base64'] = force_text(base64.encodebytes(self.icon.read()))
|
|
174 |
serialized_entry['icon:base64'] = force_str(base64.encodebytes(self.icon.read()))
|
|
175 | 175 |
del serialized_entry['model'] |
176 | 176 |
del serialized_entry['pk'] |
177 | 177 |
return serialized_entry |
combo/apps/pwa/views.py | ||
---|---|---|
21 | 21 |
from django.conf import settings |
22 | 22 |
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, JsonResponse |
23 | 23 |
from django.template.loader import TemplateDoesNotExist, get_template |
24 |
from django.utils.encoding import force_text
|
|
24 |
from django.utils.encoding import force_str
|
|
25 | 25 |
from django.views.decorators.csrf import csrf_exempt |
26 | 26 |
from django.views.generic import TemplateView |
27 | 27 |
from py_vapid import Vapid |
... | ... | |
50 | 50 |
if settings.PWA_VAPID_PUBLIK_KEY: # legacy |
51 | 51 |
pwa_vapid_public_key = settings.PWA_VAPID_PUBLIK_KEY |
52 | 52 |
elif hasattr(serialization.Encoding, 'X962'): |
53 |
pwa_vapid_public_key = force_text(
|
|
53 |
pwa_vapid_public_key = force_str(
|
|
54 | 54 |
base64.urlsafe_b64encode( |
55 | 55 |
Vapid.from_pem(pwa_settings.push_notifications_infos['private_key'].encode('ascii')) |
56 | 56 |
.private_key.public_key() |
... | ... | |
92 | 92 |
return HttpResponseForbidden() |
93 | 93 | |
94 | 94 |
try: |
95 |
subscription_data = json.loads(force_text(request.body))
|
|
95 |
subscription_data = json.loads(force_str(request.body))
|
|
96 | 96 |
except json.JSONDecodeError: |
97 | 97 |
return HttpResponseBadRequest('bad json request: "%s"' % request.body) |
98 | 98 |
combo/data/fields.py | ||
---|---|---|
20 | 20 |
from django.conf import settings |
21 | 21 |
from django.core import validators |
22 | 22 |
from django.forms.widgets import TextInput |
23 |
from django.utils.encoding import force_text
|
|
23 |
from django.utils.encoding import force_str
|
|
24 | 24 | |
25 | 25 | |
26 | 26 |
class RichTextField(ckeditor.fields.RichTextField): |
... | ... | |
52 | 52 | |
53 | 53 | |
54 | 54 |
def templatable_url_validator(value): |
55 |
value = force_text(value)
|
|
55 |
value = force_str(value)
|
|
56 | 56 |
if '{{' in value or '{%' in value: |
57 | 57 |
# leave templates alone |
58 | 58 |
return |
combo/data/models.py | ||
---|---|---|
56 | 56 |
from django.test.client import RequestFactory |
57 | 57 |
from django.urls import reverse |
58 | 58 |
from django.utils import timezone |
59 |
from django.utils.encoding import force_text, smart_bytes
|
|
59 |
from django.utils.encoding import force_str, smart_bytes
|
|
60 | 60 |
from django.utils.html import strip_tags |
61 | 61 |
from django.utils.safestring import mark_safe |
62 | 62 |
from django.utils.text import slugify |
... | ... | |
859 | 859 |
label = self.get_verbose_name() |
860 | 860 |
additional_label = self.get_additional_label() |
861 | 861 |
if label and additional_label: |
862 |
return '%s (%s)' % (label, re.sub(r'\r?\n', ' ', force_text(additional_label)))
|
|
862 |
return '%s (%s)' % (label, re.sub(r'\r?\n', ' ', force_str(additional_label)))
|
|
863 | 863 |
else: |
864 |
return force_text(label)
|
|
864 |
return force_str(label)
|
|
865 | 865 | |
866 | 866 |
@classmethod |
867 | 867 |
def get_verbose_name(cls): |
... | ... | |
2122 | 2122 |
) |
2123 | 2123 |
except requests.RequestException as e: |
2124 | 2124 |
extra_context[data_key + '_status'] = -1 |
2125 |
extra_context[data_key + '_error'] = force_text(e)
|
|
2125 |
extra_context[data_key + '_error'] = force_str(e)
|
|
2126 | 2126 |
extra_context[data_key + '_exception'] = e |
2127 | 2127 |
logger = logging.getLogger(__name__) |
2128 | 2128 |
if log_errors: |
2129 |
logger.warning('error on request %r: %s', url, force_text(e))
|
|
2129 |
logger.warning('error on request %r: %s', url, force_str(e))
|
|
2130 | 2130 |
else: |
2131 |
logger.debug('error on request %r: %s', url, force_text(e))
|
|
2131 |
logger.debug('error on request %r: %s', url, force_str(e))
|
|
2132 | 2132 |
continue |
2133 | 2133 |
extra_context[data_key + '_status'] = json_response.status_code |
2134 | 2134 |
if json_response.status_code // 100 == 2: |
... | ... | |
2314 | 2314 |
parameters = JSONField(blank=True, default=dict) |
2315 | 2315 | |
2316 | 2316 |
def __str__(self): |
2317 |
return force_text(_('%s (JSON Cell)') % self.get_label())
|
|
2317 |
return force_str(_('%s (JSON Cell)') % self.get_label())
|
|
2318 | 2318 | |
2319 | 2319 |
@classmethod |
2320 | 2320 |
def get_cell_types(cls): |
combo/manager/views.py | ||
---|---|---|
37 | 37 |
from django.shortcuts import get_object_or_404, redirect, render |
38 | 38 |
from django.template import engines |
39 | 39 |
from django.urls import reverse, reverse_lazy |
40 |
from django.utils.encoding import force_bytes, force_text
|
|
40 |
from django.utils.encoding import force_bytes, force_str
|
|
41 | 41 |
from django.utils.formats import date_format |
42 | 42 |
from django.utils.timezone import localtime |
43 | 43 |
from django.utils.translation import gettext_lazy as _ |
... | ... | |
156 | 156 |
except tarfile.TarError: |
157 | 157 |
try: |
158 | 158 |
fd.seek(0) |
159 |
json_site = json.loads(force_text(fd.read()))
|
|
159 |
json_site = json.loads(force_str(fd.read()))
|
|
160 | 160 |
except ValueError: |
161 | 161 |
form.add_error('site_file', _('File is not in the expected TAR or JSON format.')) |
162 | 162 |
return self.form_invalid(form) |
... | ... | |
171 | 171 |
else: |
172 | 172 |
pages = import_site_tar(fd, request=self.request) |
173 | 173 |
except ImportSiteError as e: |
174 |
form.add_error('site_file', force_text(e))
|
|
174 |
form.add_error('site_file', force_str(e))
|
|
175 | 175 |
return self.form_invalid(form) |
176 | 176 |
else: |
177 | 177 |
for page in pages: |
... | ... | |
957 | 957 |
json_str = json.dumps( |
958 | 958 |
[ |
959 | 959 |
{ |
960 |
'label': force_text(label),
|
|
960 |
'label': force_str(label),
|
|
961 | 961 |
'slug': slug, |
962 | 962 |
'url': request.build_absolute_uri(reverse('combo-manager-homepage')), |
963 | 963 |
} |
combo/monkeypatch.py | ||
---|---|---|
20 | 20 |
from django.forms.utils import flatatt |
21 | 21 |
from django.template.loader import render_to_string |
22 | 22 |
from django.urls import reverse |
23 |
from django.utils.encoding import force_text
|
|
23 |
from django.utils.encoding import force_str
|
|
24 | 24 |
from django.utils.html import conditional_escape |
25 | 25 |
from django.utils.safestring import mark_safe |
26 | 26 |
from django.utils.translation import get_language |
... | ... | |
43 | 43 | |
44 | 44 |
# Force to text to evaluate possible lazy objects |
45 | 45 |
external_plugin_resources = [ |
46 |
[force_text(a), force_text(b), force_text(c)] for a, b, c in self.external_plugin_resources
|
|
46 |
[force_str(a), force_str(b), force_str(c)] for a, b, c in self.external_plugin_resources
|
|
47 | 47 |
] |
48 | 48 | |
49 | 49 |
return mark_safe( |
... | ... | |
51 | 51 |
'ckeditor/widget.html', |
52 | 52 |
{ |
53 | 53 |
'final_attrs': flatatt(final_attrs), |
54 |
'value': conditional_escape(force_text(value)),
|
|
54 |
'value': conditional_escape(force_str(value)),
|
|
55 | 55 |
'id': final_attrs['id'], |
56 | 56 |
'config': ckeditor.widgets.json_encode(self.config), |
57 | 57 |
'external_plugin_resources': ckeditor.widgets.json_encode(external_plugin_resources), |
combo/public/templatetags/combo.py | ||
---|---|---|
41 | 41 |
from django.template import Template, TemplateSyntaxError, defaultfilters |
42 | 42 |
from django.template.defaultfilters import stringfilter |
43 | 43 |
from django.utils import dateparse |
44 |
from django.utils.encoding import force_text
|
|
44 |
from django.utils.encoding import force_str
|
|
45 | 45 |
from django.utils.timezone import is_naive, make_aware |
46 | 46 | |
47 | 47 |
from combo.apps.dashboard.models import DashboardCell, Tile |
... | ... | |
333 | 333 | |
334 | 334 |
@register.filter |
335 | 335 |
def split(string, separator=' '): |
336 |
return (force_text(string) or '').split(separator)
|
|
336 |
return (force_str(string) or '').split(separator)
|
|
337 | 337 | |
338 | 338 | |
339 | 339 |
@register.filter |
... | ... | |
341 | 341 |
if not string: |
342 | 342 |
return '' |
343 | 343 |
if chars: |
344 |
return force_text(string).strip(force_text(chars))
|
|
344 |
return force_str(string).strip(force_str(chars))
|
|
345 | 345 |
else: |
346 |
return force_text(string).strip()
|
|
346 |
return force_str(string).strip()
|
|
347 | 347 | |
348 | 348 | |
349 | 349 |
@register.filter |
350 | 350 |
def removeprefix(string, prefix): |
351 | 351 |
if not string: |
352 | 352 |
return '' |
353 |
value = force_text(string)
|
|
354 |
prefix = force_text(prefix)
|
|
353 |
value = force_str(string)
|
|
354 |
prefix = force_str(prefix)
|
|
355 | 355 |
if prefix and value.startswith(prefix): |
356 | 356 |
return value[len(prefix) :] |
357 | 357 |
return value |
... | ... | |
361 | 361 |
def removesuffix(string, suffix): |
362 | 362 |
if not string: |
363 | 363 |
return '' |
364 |
value = force_text(string)
|
|
365 |
suffix = force_text(suffix)
|
|
364 |
value = force_str(string)
|
|
365 |
suffix = force_str(suffix)
|
|
366 | 366 |
if suffix and value.endswith(suffix): |
367 | 367 |
return value[: -len(suffix)] |
368 | 368 |
return value |
... | ... | |
413 | 413 | |
414 | 414 |
@register.filter |
415 | 415 |
def startswith(string, substring): |
416 |
return string and force_text(string).startswith(force_text(substring))
|
|
416 |
return string and force_str(string).startswith(force_str(substring))
|
|
417 | 417 | |
418 | 418 | |
419 | 419 |
@register.filter |
420 | 420 |
def endswith(string, substring): |
421 |
return string and force_text(string).endswith(force_text(substring))
|
|
421 |
return string and force_str(string).endswith(force_str(substring))
|
|
422 | 422 | |
423 | 423 | |
424 | 424 |
def parse_float(value): |
combo/public/views.py | ||
---|---|---|
40 | 40 |
from django.template import engines |
41 | 41 |
from django.template.loader import TemplateDoesNotExist, get_template |
42 | 42 |
from django.utils import lorem_ipsum, timezone |
43 |
from django.utils.encoding import force_text
|
|
43 |
from django.utils.encoding import force_str
|
|
44 | 44 |
from django.utils.http import urlencode |
45 | 45 |
from django.utils.translation import gettext as _ |
46 | 46 |
from django.views.decorators.csrf import csrf_exempt |
... | ... | |
142 | 142 |
except PostException as e: |
143 | 143 |
exception = e |
144 | 144 |
if not request.is_ajax(): |
145 |
messages.error( |
|
146 |
request, force_text(e) if force_text(e) != 'None' else _('Error sending data.') |
|
147 |
) |
|
145 |
messages.error(request, force_str(e) if force_str(e) != 'None' else _('Error sending data.')) |
|
148 | 146 | |
149 | 147 |
if action_response: |
150 | 148 |
response = HttpResponse( |
... | ... | |
159 | 157 | |
160 | 158 |
response = render_cell(request, cell) |
161 | 159 |
if exception: |
162 |
response['x-error-message'] = force_text(exception)
|
|
160 |
response['x-error-message'] = force_str(exception)
|
|
163 | 161 |
return response |
164 | 162 | |
165 | 163 |
combo/utils/crypto.py | ||
---|---|---|
19 | 19 |
from Cryptodome import Random |
20 | 20 |
from Cryptodome.Cipher import AES |
21 | 21 |
from Cryptodome.Protocol.KDF import PBKDF2 |
22 |
from django.utils.encoding import force_text
|
|
22 |
from django.utils.encoding import force_str
|
|
23 | 23 | |
24 | 24 | |
25 | 25 |
class DecryptionError(Exception): |
... | ... | |
34 | 34 |
aes_key = PBKDF2(key, iv) |
35 | 35 |
aes = AES.new(aes_key, AES.MODE_CFB, iv) |
36 | 36 |
crypted = aes.encrypt(data) |
37 |
return force_text(b'%s%s' % (binascii.hexlify(iv[:2]), binascii.hexlify(crypted)))
|
|
37 |
return force_str(b'%s%s' % (binascii.hexlify(iv[:2]), binascii.hexlify(crypted)))
|
|
38 | 38 | |
39 | 39 | |
40 | 40 |
def aes_hex_decrypt(key, payload, raise_on_error=True): |
... | ... | |
54 | 54 |
return None |
55 | 55 |
aes_key = PBKDF2(key, iv) |
56 | 56 |
aes = AES.new(aes_key, AES.MODE_CFB, iv) |
57 |
return force_text(aes.decrypt(crypted), 'utf-8') |
|
57 |
return force_str(aes.decrypt(crypted), 'utf-8') |
combo/utils/urls.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
from django.conf import settings |
20 | 20 |
from django.template import Context, Template, TemplateSyntaxError, VariableDoesNotExist |
21 |
from django.utils.encoding import force_text
|
|
21 |
from django.utils.encoding import force_str
|
|
22 | 22 |
from django.utils.http import quote |
23 | 23 | |
24 | 24 | |
... | ... | |
67 | 67 |
return '[' |
68 | 68 |
if varname not in template_vars: |
69 | 69 |
raise TemplateError('unknown variable %s' % varname) |
70 |
return force_text(template_vars[varname])
|
|
70 |
return force_str(template_vars[varname])
|
|
71 | 71 | |
72 | 72 |
return re.sub(r'(\[.+?\])', repl, url) |
tests/test_cells.py | ||
---|---|---|
17 | 17 |
from django.test.client import RequestFactory |
18 | 18 |
from django.test.utils import CaptureQueriesContext |
19 | 19 |
from django.urls import reverse |
20 |
from django.utils.encoding import force_bytes, force_text
|
|
20 |
from django.utils.encoding import force_bytes, force_str
|
|
21 | 21 |
from django.utils.timezone import now |
22 | 22 | |
23 | 23 |
from combo.data.library import get_cell_classes |
... | ... | |
50 | 50 | |
51 | 51 |
def mock_json_response(content, **kwargs): |
52 | 52 |
content = force_bytes(content) |
53 |
text = force_text(content)
|
|
53 |
text = force_str(content)
|
|
54 | 54 |
return mock.Mock(content=content, text=text, json=lambda: json.loads(text), **kwargs) |
55 | 55 | |
56 | 56 | |
... | ... | |
79 | 79 |
app_label = 'data' |
80 | 80 | |
81 | 81 |
cells = [TextCelleWithMedia() for i in range(3)] |
82 |
assert '/static/coincoin.js' in force_text(sum((cell.media for cell in cells), Media()))
|
|
82 |
assert '/static/coincoin.js' in force_str(sum((cell.media for cell in cells), Media()))
|
|
83 | 83 | |
84 | 84 | |
85 | 85 |
def test_additional_label(): |
tests/test_import_export.py | ||
---|---|---|
13 | 13 |
from django.core.files.storage import default_storage |
14 | 14 |
from django.core.management import call_command |
15 | 15 |
from django.core.management.base import CommandError |
16 |
from django.utils.encoding import force_bytes, force_text
|
|
16 |
from django.utils.encoding import force_bytes, force_str
|
|
17 | 17 | |
18 | 18 |
from combo.apps.assets.models import Asset |
19 | 19 |
from combo.apps.assets.utils import clean_assets_files |
... | ... | |
304 | 304 | |
305 | 305 |
# check with a change in icon file content |
306 | 306 |
data = json.loads(output) |
307 |
data['pwa']['settings']['icon:base64'] = force_text(base64.encodebytes(b'TEST'))
|
|
307 |
data['pwa']['settings']['icon:base64'] = force_str(base64.encodebytes(b'TEST'))
|
|
308 | 308 |
import_site(data=data) |
309 | 309 |
assert PwaSettings.objects.get().application_icon.read() == b'TEST' |
310 | 310 | |
311 | 311 |
# check with a change in icon file name |
312 | 312 |
data = json.loads(output) |
313 |
data['pwa']['settings']['icon:base64'] = force_text(base64.encodebytes(b'TEST2'))
|
|
313 |
data['pwa']['settings']['icon:base64'] = force_str(base64.encodebytes(b'TEST2'))
|
|
314 | 314 |
data['pwa']['settings']['application_icon'] = 'pwa/test2.png' |
315 | 315 |
import_site(data=data) |
316 | 316 |
assert os.path.basename(PwaSettings.objects.get().application_icon.file.name) == 'test2.png' |
... | ... | |
339 | 339 | |
340 | 340 |
# check with a change in icon file content |
341 | 341 |
data = json.loads(output) |
342 |
data['pwa']['navigation'][1]['icon:base64'] = force_text(base64.encodebytes(b'TEST'))
|
|
342 |
data['pwa']['navigation'][1]['icon:base64'] = force_str(base64.encodebytes(b'TEST'))
|
|
343 | 343 |
import_site(data=data) |
344 | 344 |
assert PwaNavigationEntry.objects.all().count() == 2 |
345 | 345 |
assert PwaNavigationEntry.objects.get(order=1).icon.read() == b'TEST' |
... | ... | |
347 | 347 |
# check with a change in icon file name |
348 | 348 |
data = json.loads(output) |
349 | 349 |
data['pwa']['navigation'][1]['fields']['icon'] = 'pwa/test2.png' |
350 |
data['pwa']['navigation'][1]['icon:base64'] = force_text(base64.encodebytes(b'TEST2'))
|
|
350 |
data['pwa']['navigation'][1]['icon:base64'] = force_str(base64.encodebytes(b'TEST2'))
|
|
351 | 351 |
import_site(data=data) |
352 | 352 |
assert PwaNavigationEntry.objects.all().count() == 2 |
353 | 353 |
assert os.path.basename(PwaNavigationEntry.objects.get(order=1).icon.file.name) == 'test2.png' |
tests/test_lingo_remote_regie.py | ||
---|---|---|
14 | 14 |
from django.test import override_settings |
15 | 15 |
from django.test.client import RequestFactory |
16 | 16 |
from django.urls import reverse |
17 |
from django.utils.encoding import force_bytes, force_text
|
|
17 |
from django.utils.encoding import force_bytes, force_str
|
|
18 | 18 |
from django.utils.timezone import now, timedelta |
19 | 19 |
from requests.exceptions import ConnectionError |
20 | 20 |
from requests.models import Response |
... | ... | |
390 | 390 |
assert 'item' in form.fields |
391 | 391 |
assert form['item'].value == 'F201601' |
392 | 392 |
assert 'regie' in form.fields |
393 |
assert form['regie'].value == force_text(remote_regie.pk)
|
|
393 |
assert form['regie'].value == force_str(remote_regie.pk)
|
|
394 | 394 | |
395 | 395 |
form['email'] = 'ghost@buster.com' |
396 | 396 | |
... | ... | |
602 | 602 |
assert 'item' in form.fields |
603 | 603 |
assert form['item'].value == 'F201601' |
604 | 604 |
assert 'regie' in form.fields |
605 |
assert form['regie'].value == force_text(remote_regie.pk)
|
|
605 |
assert form['regie'].value == force_str(remote_regie.pk)
|
|
606 | 606 | |
607 | 607 |
form['email'] = 'test@example.net' |
608 | 608 |
resp = form.submit() |
tests/test_notification.py | ||
---|---|---|
8 | 8 |
from django.test import Client |
9 | 9 |
from django.test.client import RequestFactory |
10 | 10 |
from django.urls import reverse |
11 |
from django.utils.encoding import force_text
|
|
11 |
from django.utils.encoding import force_str
|
|
12 | 12 |
from django.utils.timezone import now |
13 | 13 |
from mellon.models import UserSAMLIdentifier |
14 | 14 | |
... | ... | |
151 | 151 |
def notify(data, count, check_id=None): |
152 | 152 |
resp = client.post(reverse('api-notification-add'), json.dumps(data), content_type='application/json') |
153 | 153 |
assert resp.status_code == 200 |
154 |
result = json.loads(force_text(resp.content))
|
|
154 |
result = json.loads(force_str(resp.content))
|
|
155 | 155 |
assert result['err'] == 0 |
156 | 156 |
if 'id' in data: |
157 | 157 |
assert check_id is not None and result['data']['id'] == check_id |
... | ... | |
203 | 203 | |
204 | 204 |
resp = client.get(reverse('api-notification-count')) |
205 | 205 |
assert resp.status_code == 200 |
206 |
assert json.loads(force_text(resp.content))['new'] == 3
|
|
207 |
assert json.loads(force_text(resp.content))['total'] == 3
|
|
206 |
assert json.loads(force_str(resp.content))['new'] == 3
|
|
207 |
assert json.loads(force_str(resp.content))['total'] == 3
|
|
208 | 208 |
resp = client.get(reverse('api-notification-ack', kwargs={'notification_id': '%s' % (notif_id - 5)})) |
209 | 209 |
resp = client.get(reverse('api-notification-count')) |
210 | 210 |
assert resp.status_code == 200 |
211 |
assert json.loads(force_text(resp.content))['new'] == 2
|
|
212 |
assert json.loads(force_text(resp.content))['total'] == 3
|
|
211 |
assert json.loads(force_str(resp.content))['new'] == 2
|
|
212 |
assert json.loads(force_str(resp.content))['total'] == 3
|
|
213 | 213 |
resp = client.get(reverse('api-notification-forget', kwargs={'notification_id': '%s' % (notif_id - 5)})) |
214 | 214 |
resp = client.get(reverse('api-notification-count')) |
215 | 215 |
assert resp.status_code == 200 |
216 |
assert json.loads(force_text(resp.content))['new'] == 2
|
|
217 |
assert json.loads(force_text(resp.content))['total'] == 2
|
|
216 |
assert json.loads(force_str(resp.content))['new'] == 2
|
|
217 |
assert json.loads(force_str(resp.content))['total'] == 2
|
|
218 | 218 | |
219 | 219 | |
220 | 220 |
def test_notification_ws_badrequest(john_doe): |
... | ... | |
225 | 225 |
content_type='application/json', |
226 | 226 |
) |
227 | 227 |
assert resp.status_code == 400 |
228 |
result = json.loads(force_text(resp.content))
|
|
228 |
result = json.loads(force_str(resp.content))
|
|
229 | 229 |
assert result['err'] == 1 |
230 | 230 |
assert message in list(result['err_desc'].values())[0][0] |
231 | 231 | |
... | ... | |
270 | 270 |
def notify(data): |
271 | 271 |
resp = client.post(reverse('api-notification-add'), json.dumps(data), content_type='application/json') |
272 | 272 | |
273 |
return json.loads(force_text(resp.content))
|
|
273 |
return json.loads(force_str(resp.content))
|
|
274 | 274 | |
275 | 275 |
result = notify({'summary': 'foo', 'id': '1'}) |
276 | 276 |
assert result['err'] == 1 |
277 |
- |