misc: remove usage of "six" module (#63682)
This commit is contained in:
parent
add77fa39a
commit
347944babf
|
@ -1,10 +1,10 @@
|
|||
import base64
|
||||
import hashlib
|
||||
import os
|
||||
import urllib.parse
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from django.utils.six.moves.urllib import parse as urlparse
|
||||
|
||||
SPECIAL_CHARS = '!#$%&+-^_`;[]{}+='
|
||||
|
||||
|
@ -25,7 +25,7 @@ def test_uploadfile(cmisclient, cmis_connector, cmis_tmpdir, tmpdir, monkeypatch
|
|||
orig_file = tmpdir.join(file_name)
|
||||
with orig_file.open('wb') as f:
|
||||
f.write(os.urandom(1024))
|
||||
url = urlparse.urljoin(cmis_connector, 'uploadfile')
|
||||
url = urllib.parse.urljoin(cmis_connector, 'uploadfile')
|
||||
with orig_file.open('rb') as f:
|
||||
file_b64_content = base64.b64encode(f.read())
|
||||
response = requests.post(
|
||||
|
@ -54,7 +54,7 @@ def test_uploadfile(cmisclient, cmis_connector, cmis_tmpdir, tmpdir, monkeypatch
|
|||
|
||||
|
||||
def test_uploadfile_conflict(cmisclient, cmis_connector, cmis_tmpdir, tmpdir, monkeypatch):
|
||||
url = urlparse.urljoin(cmis_connector, 'uploadfile')
|
||||
url = urllib.parse.urljoin(cmis_connector, 'uploadfile')
|
||||
file_b64_content = base64.b64encode('file_content')
|
||||
response = requests.post(
|
||||
url,
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import pprint
|
||||
import random
|
||||
import urllib.parse
|
||||
|
||||
import requests
|
||||
from django.utils.six.moves.urllib import parse
|
||||
|
||||
|
||||
def test_main(conn):
|
||||
# get days
|
||||
query_string = parse.urlencode(
|
||||
query_string = urllib.parse.urlencode(
|
||||
{'start_days': 1, 'end_days': 90, 'start_time': '10:00', 'end_time': '11:00', 'display': 'date'}
|
||||
)
|
||||
url = conn + '/getfreegaps?%s' % query_string
|
||||
|
@ -19,7 +19,7 @@ def test_main(conn):
|
|||
assert data
|
||||
|
||||
# get places
|
||||
query_string = parse.urlencode(
|
||||
query_string = urllib.parse.urlencode(
|
||||
{'start_days': 1, 'end_days': 90, 'start_time': '10:00', 'end_time': '11:00', 'display': 'place'}
|
||||
)
|
||||
url = conn + '/getfreegaps?%s' % query_string
|
||||
|
@ -32,7 +32,7 @@ def test_main(conn):
|
|||
place = data[random.randint(0, len(data) - 1)]['id']
|
||||
|
||||
# get days on one place
|
||||
query_string = parse.urlencode(
|
||||
query_string = urllib.parse.urlencode(
|
||||
{
|
||||
'start_days': 1,
|
||||
'end_days': 90,
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import stat
|
||||
import tempfile
|
||||
|
@ -28,7 +29,6 @@ from django.utils.timezone import now
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.conversion import ensure_encoding
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -53,7 +53,7 @@ class ActesWeb(BaseResource):
|
|||
@endpoint(perm='can_access', methods=['post'], description=_('Create demand'))
|
||||
def create(self, request, *args, **kwargs):
|
||||
try:
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
except (ValueError,):
|
||||
raise APIError('Invalid payload format: json expected')
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
https://entreprise.api.gouv.fr
|
||||
'''
|
||||
|
||||
import urllib.parse
|
||||
|
||||
import requests
|
||||
from django.core import signing
|
||||
from django.db import models
|
||||
|
@ -25,7 +27,6 @@ from django.http import Http404, HttpResponse
|
|||
from django.urls import reverse
|
||||
from django.utils.timezone import datetime, make_aware, timedelta
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from six.moves.urllib_parse import urljoin
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.utils.api import endpoint
|
||||
|
@ -97,7 +98,7 @@ class APIEntreprise(BaseResource):
|
|||
params['recipient'] = kwargs.get('recipient') or self.recipient
|
||||
if kwargs.get('non_diffusables'):
|
||||
params['non_diffusables'] = 'true'
|
||||
url = urljoin(self.url, path)
|
||||
url = urllib.parse.urljoin(self.url, path)
|
||||
try:
|
||||
response = self.requests.get(url, data=params, cache_duration=300)
|
||||
except requests.RequestException as e:
|
||||
|
|
|
@ -32,7 +32,6 @@ except ImportError:
|
|||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
|
@ -96,7 +95,7 @@ class APIParticulier(BaseResource):
|
|||
data={
|
||||
'code': 'connection-error',
|
||||
'platform': self.platform,
|
||||
'error': six.text_type(e),
|
||||
'error': str(e),
|
||||
},
|
||||
)
|
||||
try:
|
||||
|
@ -110,7 +109,7 @@ class APIParticulier(BaseResource):
|
|||
data={
|
||||
'code': 'non-json',
|
||||
'status_code': response.status_code,
|
||||
'exception': six.text_type(e),
|
||||
'exception': str(e),
|
||||
'platform': self.platform,
|
||||
'content': content,
|
||||
},
|
||||
|
|
|
@ -18,7 +18,7 @@ import json
|
|||
from urllib import parse as urlparse
|
||||
|
||||
from django.db import models
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_date, parse_time
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from requests import RequestException
|
||||
|
@ -67,7 +67,7 @@ class ArpegeECP(BaseResource):
|
|||
if result.get('Data'):
|
||||
if 'AccessToken' not in result['Data']:
|
||||
raise APIError('Error on LoginParSubOIDC: missing Data/AccessToken')
|
||||
if not isinstance(result['Data']['AccessToken'], six.string_types):
|
||||
if not isinstance(result['Data']['AccessToken'], str):
|
||||
raise APIError('Error on LoginParSubOIDC: Data/AccessToken is not string')
|
||||
return result['Data']['AccessToken']
|
||||
raise APIError('%s (%s)' % (result.get('LibErreur'), result.get('CodErreur')))
|
||||
|
|
|
@ -21,7 +21,6 @@ from urllib import parse as urlparse
|
|||
import requests
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource, HTTPResource
|
||||
|
@ -73,11 +72,11 @@ class Resource(BaseResource, HTTPResource):
|
|||
response = self.requests.get(url, *args, **kwargs)
|
||||
response.raise_for_status()
|
||||
except requests.RequestException as e:
|
||||
raise APIError('HTTP request failed', data={'exception': six.text_type(e)})
|
||||
raise APIError('HTTP request failed', data={'exception': str(e)})
|
||||
try:
|
||||
root = ET.fromstring(response.content)
|
||||
except ET.ParseError as e:
|
||||
raise APIError('XML parsing failed', data={'exception': six.text_type(e)})
|
||||
raise APIError('XML parsing failed', data={'exception': str(e)})
|
||||
if root.tag != 'return':
|
||||
raise APIError('root XML node is not return', data={'content': response.text[:1024]})
|
||||
return root, response
|
||||
|
|
|
@ -3,7 +3,6 @@ from contextlib import contextmanager
|
|||
|
||||
from django.core.cache import cache
|
||||
from django.db import transaction
|
||||
from django.utils import six
|
||||
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -43,7 +42,7 @@ class RowLockedCache:
|
|||
if self.row:
|
||||
keys.append(str(self.row.pk))
|
||||
for arg in args:
|
||||
if isinstance(arg, six.string_types):
|
||||
if isinstance(arg, str):
|
||||
keys.append(arg)
|
||||
else:
|
||||
keys.append(hash(arg))
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import datetime
|
||||
import gzip
|
||||
import json
|
||||
from io import StringIO
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.db import connection, models
|
||||
from django.db.models import Q
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.http import urlencode
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from requests import RequestException
|
||||
|
||||
from passerelle.address.models import AddressResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.conversion import simplify
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -452,13 +452,10 @@ class BaseAdresse(AddressResource):
|
|||
if ban_gz.status_code != 200:
|
||||
continue
|
||||
|
||||
if six.PY3:
|
||||
ban_file = StringIO(gzip.decompress(ban_gz.content).decode('utf-8'))
|
||||
else:
|
||||
ban_file = gzip.GzipFile(fileobj=StringIO(ban_gz.content))
|
||||
ban_file = StringIO(gzip.decompress(ban_gz.content).decode('utf-8'))
|
||||
line = _not_found = object()
|
||||
for line in ban_file:
|
||||
street_info = json_loads(line)
|
||||
street_info = json.loads(line)
|
||||
if street_info['type'] != 'street':
|
||||
continue
|
||||
ban_id = street_info.get('id')
|
||||
|
@ -466,7 +463,7 @@ class BaseAdresse(AddressResource):
|
|||
continue
|
||||
for key in ('postcode', 'name', 'city'):
|
||||
if isinstance(street_info[key], list):
|
||||
street_info[key] = six.text_type(street_info[key][0])
|
||||
street_info[key] = str(street_info[key][0])
|
||||
if not street_info['postcode'] or not street_info['postcode'].startswith(zipcodes):
|
||||
continue
|
||||
citycode = ban_id.split('_', 1)[0]
|
||||
|
@ -580,7 +577,6 @@ class UnaccentNameMixin:
|
|||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class StreetModel(UnaccentNameMixin, models.Model):
|
||||
|
||||
ban_id = models.CharField(_('BAN Identifier'), max_length=32, blank=True)
|
||||
|
@ -601,7 +597,6 @@ class StreetModel(UnaccentNameMixin, models.Model):
|
|||
return self.name
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class RegionModel(UnaccentNameMixin, models.Model):
|
||||
|
||||
name = models.CharField(_('Region name'), max_length=150)
|
||||
|
@ -627,7 +622,6 @@ class RegionModel(UnaccentNameMixin, models.Model):
|
|||
return '%s %s' % (self.code, self.name)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class DepartmentModel(UnaccentNameMixin, models.Model):
|
||||
|
||||
name = models.CharField(_('Department name'), max_length=100)
|
||||
|
@ -656,7 +650,6 @@ class DepartmentModel(UnaccentNameMixin, models.Model):
|
|||
return '%s %s' % (self.code, self.name)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class CityModel(UnaccentNameMixin, models.Model):
|
||||
|
||||
name = models.CharField(_('City name'), max_length=150)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import json
|
||||
|
||||
from django.http import Http404
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import DetailView, SingleObjectMixin
|
||||
|
||||
from passerelle import utils
|
||||
from passerelle.compat import json_loads
|
||||
|
||||
from .models import Bdp
|
||||
|
||||
|
@ -40,7 +41,7 @@ class PostAdherentView(View, SingleObjectMixin):
|
|||
@utils.protected_api('can_access')
|
||||
@utils.to_json()
|
||||
def post(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body) # JSON w.c.s. formdata
|
||||
data = json.loads(request.body) # JSON w.c.s. formdata
|
||||
date_de_naissance = data['fields'].get('date_de_naissance')
|
||||
# force 1973-04-18T00:00:00Z
|
||||
date_de_naissance = date_de_naissance[:10] + 'T00:00:00Z'
|
||||
|
|
|
@ -3,7 +3,6 @@ import json
|
|||
|
||||
import requests
|
||||
from django.db import models
|
||||
from django.utils.six import string_types
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.sms.models import SMSResource
|
||||
|
@ -95,6 +94,6 @@ class ChoositSMSGateway(SMSResource):
|
|||
results.append('Choosit error: %s' % output['error'])
|
||||
else:
|
||||
results.append(output)
|
||||
if any(isinstance(result, string_types) for result in results):
|
||||
if any(isinstance(result, str) for result in results):
|
||||
raise APIError('Choosit error: some destinations failed', data=list(zip(destinations, results)))
|
||||
# credit consumed is unknown
|
||||
|
|
|
@ -18,7 +18,6 @@ import os
|
|||
import stat
|
||||
|
||||
from django.core.files.storage import default_storage
|
||||
from django.utils import six
|
||||
from django.utils.dateparse import parse_date
|
||||
from django.utils.encoding import force_bytes
|
||||
from lxml import etree
|
||||
|
@ -86,7 +85,7 @@ class BaseType:
|
|||
attr = getattr(self, subelt, None)
|
||||
if not attr:
|
||||
continue
|
||||
if isinstance(attr, six.string_types):
|
||||
if isinstance(attr, str):
|
||||
tag.append(self.make_element(subelt, attr, namespace=self.namespace))
|
||||
else:
|
||||
xml = attr.xml
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
from django.core.files.storage import default_storage
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -47,7 +47,7 @@ class CityWeb(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', methods=['post'], description=_('Create a demand'))
|
||||
def create(self, request, *args, **kwargs):
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
# check mandatory keys
|
||||
for key in ('application_id', 'application_time', 'certificate_type'):
|
||||
if key not in payload:
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import json
|
||||
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import DetailView, SingleObjectMixin
|
||||
|
||||
from passerelle import utils
|
||||
from passerelle.apps.clicrdv.models import ClicRdv
|
||||
from passerelle.compat import json_loads
|
||||
|
||||
|
||||
class ClicRdvDetailView(DetailView):
|
||||
|
@ -87,7 +88,7 @@ class CreateAppointmentView(View, SingleObjectMixin):
|
|||
def post(self, request, intervention_id=None, *args, **kwargs):
|
||||
if intervention_id is None:
|
||||
intervention_id = self.request.GET.get('intervention')
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
return {
|
||||
'data': self.get_object().create_appointment(
|
||||
intervention_id, self.request.GET.get('websource'), data
|
||||
|
|
|
@ -19,6 +19,7 @@ import binascii
|
|||
import functools
|
||||
import re
|
||||
from contextlib import contextmanager
|
||||
from io import BytesIO
|
||||
from urllib import error as urllib2
|
||||
|
||||
import httplib2
|
||||
|
@ -32,7 +33,6 @@ from cmislib.exceptions import (
|
|||
)
|
||||
from django.db import models
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.six import BytesIO
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
|
|
|
@ -24,7 +24,6 @@ import tempfile
|
|||
from collections import OrderedDict
|
||||
|
||||
import pytz
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.contrib.postgres.indexes import GinIndex
|
||||
|
@ -231,7 +230,7 @@ class CsvDataSource(BaseResource):
|
|||
|
||||
options = {}
|
||||
for k, v in self._dialect_options.items():
|
||||
if isinstance(v, six.text_type):
|
||||
if isinstance(v, str):
|
||||
v = force_str(v.encode('ascii'))
|
||||
options[force_str(k.encode('ascii'))] = v
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
import csv
|
||||
import datetime
|
||||
import io
|
||||
from decimal import Decimal
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -41,11 +41,8 @@ class Loader:
|
|||
def load(self, archive):
|
||||
archive_files = archive.namelist()
|
||||
fd = archive.open('data_full.csv')
|
||||
if six.PY3:
|
||||
import io
|
||||
|
||||
fd = io.TextIOWrapper(fd, 'iso-8859-15')
|
||||
csvfile = six.StringIO(fd.read())
|
||||
fd = io.TextIOWrapper(fd, 'iso-8859-15')
|
||||
csvfile = io.StringIO(fd.read())
|
||||
csvreader = csv.reader(csvfile, delimiter='\t')
|
||||
first_row = next(csvreader)
|
||||
csvfile.seek(0)
|
||||
|
|
|
@ -15,12 +15,13 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import csv
|
||||
import io
|
||||
import os
|
||||
from decimal import Decimal
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.storage import DefaultStorage
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -123,10 +124,7 @@ class Loader:
|
|||
|
||||
def csvread(self, filename):
|
||||
fd = self.archive.open(filename)
|
||||
if six.PY3:
|
||||
import io
|
||||
|
||||
fd = io.TextIOWrapper(fd, 'iso-8859-15')
|
||||
fd = io.TextIOWrapper(fd, 'iso-8859-15')
|
||||
|
||||
reader = csv.reader(fd, Dialect)
|
||||
# pylint: disable=stop-iteration-return
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
import csv
|
||||
import datetime
|
||||
import io
|
||||
from decimal import Decimal
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -41,11 +41,8 @@ class Loader:
|
|||
def load(self, archive):
|
||||
archive_files = archive.namelist()
|
||||
fd = archive.open('publipostage.csv')
|
||||
if six.PY3:
|
||||
import io
|
||||
|
||||
fd = io.TextIOWrapper(fd, 'iso-8859-15')
|
||||
csvfile = six.StringIO(fd.read())
|
||||
fd = io.TextIOWrapper(fd, 'iso-8859-15')
|
||||
csvfile = io.StringIO(fd.read())
|
||||
csvreader = csv.reader(csvfile, delimiter=';')
|
||||
first_row = next(csvreader)
|
||||
csvfile.seek(0)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import zipfile
|
||||
|
@ -27,12 +28,10 @@ from django.core.exceptions import ValidationError
|
|||
from django.core.files.storage import default_storage
|
||||
from django.db import models, transaction
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.utils import six
|
||||
from django.utils.timezone import datetime, make_aware, now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
|
||||
SEXES = (
|
||||
|
@ -212,7 +211,7 @@ class GenericFamily(BaseResource):
|
|||
adults = []
|
||||
|
||||
for f in family_files:
|
||||
family_data = json_loads(archive.read(f))
|
||||
family_data = json.loads(archive.read(f))
|
||||
families.append(family_data['id'])
|
||||
address = family_data.get('address') or {}
|
||||
family_data.update(address)
|
||||
|
@ -403,7 +402,7 @@ class GenericFamily(BaseResource):
|
|||
name='regie', methods=['post'], perm='can_access', pattern=r'^invoice/(?P<invoice_id>\w+)/pay/$'
|
||||
)
|
||||
def pay_invoice(self, request, invoice_id, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
invoice = self.get_invoice(invoice_id)
|
||||
if not invoice:
|
||||
return {'data': False}
|
||||
|
@ -454,7 +453,6 @@ class Family(models.Model):
|
|||
return self.external_id
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Person(models.Model):
|
||||
family = models.ForeignKey('Family', on_delete=models.CASCADE)
|
||||
external_id = models.CharField(_('Person\'s external id'), max_length=32, db_index=True)
|
||||
|
|
|
@ -15,12 +15,13 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import json
|
||||
|
||||
from django.utils.encoding import force_text
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import DetailView, SingleObjectMixin
|
||||
|
||||
from passerelle import utils
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.conversion import normalize
|
||||
|
||||
from .models import Gdc, phpserialize, phpserialize_loads
|
||||
|
@ -132,7 +133,7 @@ class PostDemandeView(View, SingleObjectMixin):
|
|||
# <wsdl:part name='voie_id' type='xsd:string'></wsdl:part>
|
||||
# <wsdl:part name='voie_num' type='xsd:string'></wsdl:part>
|
||||
# </wsdl:message>
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
voie_id = data['fields'].get('voie_raw')
|
||||
voie_str = data['fields'].get('voie')
|
||||
insee = data['fields'].get('commune_raw')
|
||||
|
|
|
@ -21,8 +21,6 @@ from collections import OrderedDict
|
|||
from django.contrib.postgres.fields import JSONField
|
||||
from django.db import IntegrityError, models, transaction
|
||||
from django.http import Http404
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
|
@ -239,10 +237,7 @@ class Gesbac(BaseResource):
|
|||
if not csv_file.startswith(self.input_files_prefix):
|
||||
continue
|
||||
with client.open(csv_file, 'rb') as fd:
|
||||
if six.PY3:
|
||||
content = io.TextIOWrapper(fd, encoding=FILES_ENCODING)
|
||||
else:
|
||||
content = io.BytesIO(force_bytes(fd.read().decode(FILES_ENCODING)))
|
||||
content = io.TextIOWrapper(fd, encoding=FILES_ENCODING)
|
||||
for row in csv.reader(content, delimiter=CSV_DELIMITER):
|
||||
data.append(row)
|
||||
for card_data in data:
|
||||
|
@ -357,16 +352,9 @@ class Form(models.Model):
|
|||
def send(self):
|
||||
with self.resource.outcoming_sftp.client() as client:
|
||||
with client.open(self.get_filename(), mode='wb') as fd:
|
||||
if six.PY3:
|
||||
fd = io.TextIOWrapper(fd, encoding=FILES_ENCODING)
|
||||
fd = io.TextIOWrapper(fd, encoding=FILES_ENCODING)
|
||||
writer = csv.writer(fd, delimiter=CSV_DELIMITER)
|
||||
for row in self.demand_data:
|
||||
# encode strings to ASCII
|
||||
if six.PY2:
|
||||
row = [
|
||||
item.encode(FILES_ENCODING) if isinstance(item, six.string_types) else item
|
||||
for item in row
|
||||
]
|
||||
writer.writerow(row)
|
||||
self.status = 'sent'
|
||||
self.save()
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
|
@ -22,7 +23,6 @@ from django.template import Context, Template
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import APIError, endpoint
|
||||
from passerelle.utils.conversion import simplify
|
||||
|
||||
|
@ -33,7 +33,7 @@ def get_hex_uuid():
|
|||
|
||||
def clean_json_data(data):
|
||||
try:
|
||||
payload = json_loads(data)
|
||||
payload = json.loads(data)
|
||||
if not isinstance(payload, dict):
|
||||
raise APIError('payload must be a dict')
|
||||
return payload
|
||||
|
|
|
@ -15,14 +15,13 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils import SFTPField
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.files import atomic_write
|
||||
|
@ -93,7 +92,7 @@ class MDEL(BaseResource):
|
|||
@endpoint(perm='can_access', methods=['post'])
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""Create a demand"""
|
||||
formdata = json_loads(request.body)
|
||||
formdata = json.loads(request.body)
|
||||
extra = formdata.pop('extra', {})
|
||||
fields = formdata.pop('fields', {})
|
||||
|
||||
|
@ -193,7 +192,6 @@ class MDEL(BaseResource):
|
|||
self.get_response_files()
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Demand(models.Model):
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
|
|
@ -28,7 +28,7 @@ from django.contrib.postgres.fields import JSONField
|
|||
from django.db import IntegrityError, models, transaction
|
||||
from django.http import HttpResponse
|
||||
from django.urls import reverse
|
||||
from django.utils import functional, six
|
||||
from django.utils import functional
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource, SkipJob
|
||||
|
@ -214,7 +214,6 @@ class Resource(BaseResource):
|
|||
return
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Demand(models.Model):
|
||||
STATUS_PENDING = 'pending'
|
||||
STATUS_PUSHED = 'pushed'
|
||||
|
|
|
@ -19,7 +19,6 @@ from __future__ import unicode_literals
|
|||
|
||||
import xmlschema
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.utils.api import endpoint
|
||||
|
@ -117,7 +116,7 @@ class Resource(abstract.Resource):
|
|||
else:
|
||||
del d['filiationInconnu']
|
||||
# convert codeNationalite to array of strings
|
||||
if isinstance(d.get('codeNationalite'), six.text_type):
|
||||
if isinstance(d.get('codeNationalite'), str):
|
||||
d['codeNationalite'] = [d['codeNationalite']]
|
||||
for key in d:
|
||||
if key in ('anneeNaissance', 'jourNaissance', 'moisNaissance'):
|
||||
|
|
|
@ -22,7 +22,6 @@ from django.utils.http import urlencode
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -245,7 +244,7 @@ class Okina(BaseResource):
|
|||
@endpoint(name='subscriber', methods=['post'], perm='can_access')
|
||||
def create_subscriber(self, request):
|
||||
try:
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload must be a JSON object', http_status=400)
|
||||
if not isinstance(payload, dict):
|
||||
|
@ -261,14 +260,14 @@ class Okina(BaseResource):
|
|||
qrcode = self.request('subscribers/%s/qrcode' % subscriber_id, result_is_json=False)
|
||||
content_type = qrcode.headers.get('Content-Type')
|
||||
if not (content_type and content_type.startswith('image/')):
|
||||
response = json_loads(qrcode.content)
|
||||
response = json.loads(qrcode.content)
|
||||
raise APIError(response['message'], http_status=response['status'], err=response['code'])
|
||||
return HttpResponse(qrcode.content, content_type=content_type)
|
||||
|
||||
@endpoint(name='subscription', methods=['post'], perm='can_access')
|
||||
def create_subscription(self, request):
|
||||
try:
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload must be a JSON object', http_status=400)
|
||||
if not isinstance(payload, dict):
|
||||
|
|
|
@ -19,7 +19,6 @@ import math
|
|||
import xml.etree.ElementTree as ET
|
||||
|
||||
import pyproj
|
||||
import six
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.core.cache import cache
|
||||
from django.db import models, transaction
|
||||
|
@ -396,7 +395,7 @@ class OpenGIS(BaseResource):
|
|||
for attribute, properties in self.attributes_mapping:
|
||||
for field in properties:
|
||||
if closest_feature['properties'].get(field):
|
||||
result['address'][attribute] = six.text_type(closest_feature['properties'][field])
|
||||
result['address'][attribute] = str(closest_feature['properties'][field])
|
||||
break
|
||||
return result
|
||||
raise APIError('Unable to geocode')
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
from urllib.parse import parse_qsl, urlsplit, urlunsplit
|
||||
|
||||
from django.core.cache import cache
|
||||
|
@ -24,7 +25,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from requests import RequestException
|
||||
|
||||
from passerelle.base.models import BaseQuery, BaseResource, HTTPResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.http_authenticators import HttpBearerAuth
|
||||
from passerelle.utils.json import unflatten
|
||||
|
@ -303,7 +303,7 @@ class PloneRestApi(BaseResource, HTTPResource):
|
|||
)
|
||||
def create(self, request, uri, publish=False):
|
||||
try:
|
||||
post_data = json_loads(request.body)
|
||||
post_data = json.loads(request.body)
|
||||
except ValueError as e:
|
||||
raise ParameterTypeError(str(e))
|
||||
post_data = unflatten(post_data)
|
||||
|
@ -330,7 +330,7 @@ class PloneRestApi(BaseResource, HTTPResource):
|
|||
)
|
||||
def update(self, request, uid, uri=''):
|
||||
try:
|
||||
post_data = json_loads(request.body)
|
||||
post_data = json.loads(request.body)
|
||||
except ValueError as e:
|
||||
raise ParameterTypeError(str(e))
|
||||
post_data = unflatten(post_data)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import base64
|
||||
import copy
|
||||
import json
|
||||
|
||||
from django.db import models
|
||||
from django.template.loader import get_template
|
||||
|
@ -24,7 +25,6 @@ from django.utils.http import urlencode
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.conversion import simplify, to_pdf
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -276,7 +276,7 @@ class Solis(BaseResource):
|
|||
)
|
||||
def apa_link(self, request):
|
||||
try:
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON dict')
|
||||
if not isinstance(data, dict):
|
||||
|
@ -302,7 +302,7 @@ class Solis(BaseResource):
|
|||
)
|
||||
def apa_unlink(self, request):
|
||||
try:
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON dict')
|
||||
if not isinstance(data, dict):
|
||||
|
@ -411,7 +411,7 @@ class Solis(BaseResource):
|
|||
)
|
||||
def apa_integration(self, request):
|
||||
try:
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON object', http_status=400)
|
||||
if not isinstance(payload, dict):
|
||||
|
@ -566,7 +566,7 @@ class Solis(BaseResource):
|
|||
)
|
||||
def rsa_link(self, request):
|
||||
try:
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON dict')
|
||||
if not isinstance(data, dict):
|
||||
|
@ -593,7 +593,7 @@ class Solis(BaseResource):
|
|||
)
|
||||
def rsa_unlink(self, request):
|
||||
try:
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON dict')
|
||||
if not isinstance(data, dict):
|
||||
|
|
|
@ -28,7 +28,6 @@ from django.core.files import File
|
|||
from django.db import models, transaction
|
||||
from django.template import engines
|
||||
from django.urls import reverse
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from lxml import etree as ET
|
||||
|
@ -77,8 +76,8 @@ def simplify(s):
|
|||
'''Simplify XML node tag names because XSD from DGME are garbage'''
|
||||
if not s:
|
||||
return ''
|
||||
if not isinstance(s, six.text_type):
|
||||
s = six.text_type(s, 'utf-8', 'ignore')
|
||||
if not isinstance(s, str):
|
||||
s = str(s, 'utf-8', 'ignore')
|
||||
s = normalize(s)
|
||||
s = re.sub(r'[^\w\s\'-_]', '', s)
|
||||
s = s.replace('-', '_')
|
||||
|
@ -536,7 +535,6 @@ def default_rule():
|
|||
return {}
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Mapping(models.Model):
|
||||
resource = models.ForeignKey(
|
||||
Resource, verbose_name=_('Resource'), related_name='mappings', on_delete=models.CASCADE
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
import datetime
|
||||
|
||||
import isodate
|
||||
from django.utils import six
|
||||
from lxml import etree as ET
|
||||
from zeep.utils import qname_attr
|
||||
|
||||
|
@ -57,7 +56,7 @@ ANY_TYPE = ET.QName(XSD, 'anyType')
|
|||
|
||||
TYPE_CASTER = {
|
||||
BOOLEAN: parse_bool,
|
||||
STRING: six.text_type,
|
||||
STRING: str,
|
||||
DATE: parse_date,
|
||||
INT: int,
|
||||
INTEGER: int,
|
||||
|
@ -245,7 +244,7 @@ class Schema:
|
|||
def qname_display(self, name):
|
||||
if name.namespace in self.reverse_nsmap:
|
||||
name = '%s:%s' % (self.reverse_nsmap[name.namespace], name.localname)
|
||||
return six.text_type(name)
|
||||
return str(name)
|
||||
|
||||
def paths(self):
|
||||
roots = sorted(self.elements.keys())
|
||||
|
@ -292,7 +291,6 @@ class Schema:
|
|||
yield path
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Path:
|
||||
def __init__(self, path, xsd_type):
|
||||
assert path
|
||||
|
@ -301,7 +299,7 @@ class Path:
|
|||
try:
|
||||
self.caster = TYPE_CASTER[xsd_type]
|
||||
except KeyError:
|
||||
raise KeyError(six.text_type(xsd_type))
|
||||
raise KeyError(str(xsd_type))
|
||||
|
||||
def resolve(self, root):
|
||||
def helper(node, path):
|
||||
|
@ -319,4 +317,4 @@ class Path:
|
|||
return self.caster(child.text)
|
||||
|
||||
def __str__(self):
|
||||
return '.'.join(six.text_type(name) for name in self.path)
|
||||
return '.'.join(str(name) for name in self.path)
|
||||
|
|
|
@ -26,7 +26,7 @@ from django.forms.models import modelform_factory
|
|||
from django.forms.widgets import ClearableFileInput
|
||||
from django.test import override_settings
|
||||
from django.urls import reverse
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.log import AdminEmailHandler
|
||||
from django.utils.text import slugify
|
||||
|
@ -71,7 +71,6 @@ BASE_EXPORT_FIELDS = (
|
|||
)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class ApiUser(models.Model):
|
||||
username = models.CharField(max_length=128, verbose_name=_('Username'), unique=True)
|
||||
fullname = models.CharField(max_length=50, verbose_name=_('Full Name'))
|
||||
|
@ -135,7 +134,6 @@ class InheritanceManager(ModelUtilsInheritanceManager):
|
|||
return self.filter(Q(users=None) | Q(users=apiuser))
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class BaseResource(models.Model):
|
||||
title = models.CharField(max_length=50, verbose_name=_('Title'))
|
||||
slug = models.SlugField(verbose_name=_('Identifier'), unique=True)
|
||||
|
@ -653,7 +651,6 @@ class BaseResource(models.Model):
|
|||
).exists()
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class AccessRight(models.Model):
|
||||
codename = models.CharField(max_length=100, verbose_name='codename')
|
||||
resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||
|
@ -798,7 +795,7 @@ class Job(models.Model):
|
|||
def set_after_timestamp(self, value):
|
||||
if isinstance(value, datetime.datetime):
|
||||
self.after_timestamp = value
|
||||
elif isinstance(value, six.integer_types + (float,)):
|
||||
elif isinstance(value, (float, int)):
|
||||
self.after_timestamp = timezone.now() + datetime.timedelta(seconds=value)
|
||||
elif isinstance(value, datetime.timedelta):
|
||||
self.after_timestamp = timezone.now() + value
|
||||
|
@ -849,7 +846,6 @@ class Job(models.Model):
|
|||
self.save()
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class ResourceLog(models.Model):
|
||||
timestamp = models.DateTimeField(auto_now_add=True)
|
||||
appname = models.CharField(max_length=128, verbose_name='appname', null=True)
|
||||
|
@ -1063,7 +1059,6 @@ class HTTPResource(models.Model):
|
|||
abstract = True
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class BaseQuery(models.Model):
|
||||
"""Base for building custom queries.
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import hmac
|
|||
import random
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from django.utils import six
|
||||
from django.utils.encoding import smart_bytes
|
||||
from django.utils.http import quote, urlencode
|
||||
|
||||
|
@ -38,7 +37,7 @@ def sign_query(query, key, algo='sha256', timestamp=None, nonce=None):
|
|||
|
||||
def sign_string(s, key, algo='sha256'):
|
||||
digestmod = getattr(hashlib, algo)
|
||||
if isinstance(key, six.text_type):
|
||||
if isinstance(key, str):
|
||||
key = key.encode('utf-8')
|
||||
hash = hmac.HMAC(smart_bytes(key), digestmod=digestmod, msg=smart_bytes(s))
|
||||
return hash.digest()
|
||||
|
@ -74,10 +73,6 @@ def check_string(s, signature, key, algo='sha256'):
|
|||
if len(signature2) != len(signature):
|
||||
return False
|
||||
res = 0
|
||||
if six.PY3:
|
||||
for a, b in zip(signature, signature2):
|
||||
res |= a ^ b
|
||||
else:
|
||||
for a, b in zip(signature, signature2):
|
||||
res |= ord(a) ^ ord(b)
|
||||
for a, b in zip(signature, signature2):
|
||||
res |= a ^ b
|
||||
return res == 0
|
||||
|
|
|
@ -29,8 +29,6 @@ from django.utils.timezone import make_aware
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic import CreateView, DeleteView, DetailView, FormView, ListView, UpdateView, View
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
|
||||
from ..utils import ImportSiteError, export_site, get_trusted_services, import_site
|
||||
from ..views import GenericConnectorMixin
|
||||
from .forms import AccessRightForm, ApiUserForm, AvailabilityParametersForm, ImportSiteForm
|
||||
|
@ -332,7 +330,7 @@ class ImportSiteView(FormView):
|
|||
|
||||
def form_valid(self, form):
|
||||
try:
|
||||
site_json = json_loads(self.request.FILES['site_json'].read())
|
||||
site_json = json.loads(self.request.FILES['site_json'].read())
|
||||
except ValueError:
|
||||
form.add_error('site_json', _('File is not in the expected JSON format.'))
|
||||
return self.form_invalid(form)
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import json
|
||||
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
|
||||
def json_loads(value):
|
||||
if six.PY3:
|
||||
value = force_text(value)
|
||||
return json.loads(value)
|
|
@ -18,18 +18,18 @@ from __future__ import unicode_literals
|
|||
|
||||
import base64
|
||||
import datetime
|
||||
import json
|
||||
|
||||
import pytz
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.utils import six, timezone
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from zeep.exceptions import Fault as WebFault
|
||||
from zeep.helpers import serialize_object
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.conversion import to_pdf
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -201,7 +201,6 @@ def get_client(instance):
|
|||
return instance.soap_client()
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class DPark(BaseResource):
|
||||
log_requests_errors = False
|
||||
|
||||
|
@ -290,7 +289,7 @@ class DPark(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', methods=['post'], description=_('Register a subscription application'))
|
||||
def register(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
is_erroneous(
|
||||
data,
|
||||
(
|
||||
|
@ -348,7 +347,7 @@ class DPark(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', methods=['post'], description=_('Link user to a subscription'))
|
||||
def link(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
if 'nameid' not in data:
|
||||
raise WrongParameter(['nameid'], [])
|
||||
result = self.check_file_exists(data)
|
||||
|
@ -370,7 +369,7 @@ class DPark(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', methods=['post'], description=_('Unlink user to subscription'))
|
||||
def unlink(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
is_erroneous(data, ('nameid',))
|
||||
pairings = Pairing.objects.filter(**data)
|
||||
if pairings.exists() is False:
|
||||
|
@ -479,7 +478,7 @@ class DPark(BaseResource):
|
|||
|
||||
@endpoint(name='notify-payment', perm='can_access', methods=['post'], description=_('Notify a payment'))
|
||||
def payment_notification(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
is_erroneous(
|
||||
data,
|
||||
(
|
||||
|
@ -519,7 +518,7 @@ class DPark(BaseResource):
|
|||
)
|
||||
def send_files(self, request, *args, **kwargs):
|
||||
try:
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
except ValueError as exc:
|
||||
raise APIError(str(exc), http_status=400)
|
||||
|
||||
|
@ -568,7 +567,6 @@ class DPark(BaseResource):
|
|||
return {'data': True}
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Pairing(models.Model):
|
||||
INFO_CACHE_DURATION = 5 * 60
|
||||
PAYMENT_INFO_CACHE_DURATION = 20 * 60
|
||||
|
|
|
@ -20,12 +20,10 @@ import re
|
|||
|
||||
from django.db import models
|
||||
from django.utils.dateparse import parse_date, parse_datetime
|
||||
from django.utils.six import string_types
|
||||
from django.utils.timezone import get_fixed_timezone, is_naive, make_aware, utc
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -68,7 +66,7 @@ def parse_gdema_datetime(value):
|
|||
|
||||
def normalize(value):
|
||||
'''convert /Date()/ to datetime, integers to strings'''
|
||||
if isinstance(value, string_types):
|
||||
if isinstance(value, str):
|
||||
datetime = parse_gdema_datetime(value)
|
||||
if datetime:
|
||||
return datetime
|
||||
|
@ -253,7 +251,7 @@ class Gdema(BaseResource):
|
|||
)
|
||||
def create_request(self, request):
|
||||
try:
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload must be a JSON object', http_status=400)
|
||||
if not isinstance(payload, dict):
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from django.db import models
|
||||
|
@ -22,7 +23,6 @@ from django.utils.text import slugify
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
|
||||
COMMUNE_EXTRA_MAPPING = {'Vaulx-en-Velin': 'VAULX'}
|
||||
|
@ -123,7 +123,7 @@ class GrandLyonStreetSections(BaseResource):
|
|||
sections = self.requests.get(
|
||||
'https://download.data.grandlyon.com/ws/grandlyon/adr_voie_lieu.adraxevoie/all.json?maxfeatures=1000000'
|
||||
).content
|
||||
for value in json_loads(sections).get('values'):
|
||||
for value in json.loads(sections).get('values'):
|
||||
if not value.get('codefuv') or not value.get('codetroncon'):
|
||||
continue
|
||||
section, dummy = StreetSection.objects.get_or_create(
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import base64
|
||||
import json
|
||||
import re
|
||||
from email.mime.base import MIMEBase
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
|
@ -28,7 +29,6 @@ from suds.transport import Reply
|
|||
from suds.transport.http import HttpAuthenticated
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.soap import sudsobject_to_dict
|
||||
from passerelle.utils.api import APIError, endpoint
|
||||
|
||||
|
@ -258,7 +258,7 @@ Response :
|
|||
def create(self, request):
|
||||
# get creation fields from payload
|
||||
try:
|
||||
formdata = FormData(json_loads(request.body), CREATION_SCHEMA)
|
||||
formdata = FormData(json.loads(request.body), CREATION_SCHEMA)
|
||||
except ValueError as e:
|
||||
raise ParameterTypeError(str(e))
|
||||
# create suds object from formdata
|
||||
|
@ -329,7 +329,7 @@ Response :
|
|||
)
|
||||
def add_information(self, request, iddemande=None, idgreco=None, information=None):
|
||||
if request.body:
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
if not isinstance(payload, dict):
|
||||
raise ParameterTypeError('payload must be a dict')
|
||||
idgreco = payload.get('idgreco') or idgreco
|
||||
|
@ -356,7 +356,7 @@ Response :
|
|||
)
|
||||
def update(self, request, iddemande=None, idgreco=None, comment=None):
|
||||
if request.body:
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
if not isinstance(payload, dict):
|
||||
raise ParameterTypeError('payload must be a dict')
|
||||
idgreco = payload.get('idgreco') or idgreco
|
||||
|
@ -383,7 +383,7 @@ Response :
|
|||
display_order=7,
|
||||
)
|
||||
def add_confirmation(self, request):
|
||||
payload = json_loads(request.body)
|
||||
payload = json.loads(request.body)
|
||||
if not isinstance(payload, dict):
|
||||
raise ParameterTypeError('payload must be a dict')
|
||||
idgreco = payload.get('idgreco')
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import re
|
||||
from urllib import parse as urlparse
|
||||
|
||||
|
@ -26,7 +27,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from lxml import etree
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.views import WrongParameter
|
||||
|
@ -237,7 +237,7 @@ class GrenobleGRU(BaseResource):
|
|||
@endpoint(name='create-demand', perm='can_access', methods=['post'], description=_('Create a demand'))
|
||||
def create_demand(self, request, *args, **kwargs):
|
||||
try:
|
||||
payload = self.build_gru_params(json_loads(request.body))
|
||||
payload = self.build_gru_params(json.loads(request.body))
|
||||
except (KeyError, ValueError) as e:
|
||||
raise APIError(e)
|
||||
response = self.request('ws_creation_demande.php', payload)
|
||||
|
@ -253,7 +253,7 @@ class GrenobleGRU(BaseResource):
|
|||
pattern=r'(?P<demand_id>[\w-]+)/add-attachment/$',
|
||||
)
|
||||
def add_attachment_to_demand(self, request, demand_id, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
if 'file' not in data:
|
||||
raise WrongParameter(['file'], [])
|
||||
file_data = data['file']
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import re
|
||||
from urllib.parse import urljoin
|
||||
|
||||
|
@ -23,7 +24,6 @@ from django.db import models
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.http_authenticators import HttpBearerAuth
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -134,7 +134,7 @@ class LilleUrbanCard(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', description=_('Card Request'), methods=['post'])
|
||||
def card_request(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
self.preprocess_card_request_data(data)
|
||||
self.preprocess_contact_data(data)
|
||||
self.preprocess_service_data(data)
|
||||
|
@ -169,7 +169,7 @@ class LilleUrbanCard(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', description=_('Add new subscriptions'), methods=['post'])
|
||||
def add_subscriptions(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
self.preprocess_card_request_data(data)
|
||||
self.preprocess_contact_data(data)
|
||||
self.preprocess_service_data(data)
|
||||
|
@ -193,7 +193,7 @@ class LilleUrbanCard(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', description=_('Code Change'), methods=['post'])
|
||||
def code_change(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
response = self.requests.post(
|
||||
urljoin(self.base_url, '/clu/ws/modifierCodeSecret'),
|
||||
json=data,
|
||||
|
@ -211,7 +211,7 @@ class LilleUrbanCard(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', description=_('Code check'), methods=['post'])
|
||||
def code_check(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
if 'password' in data:
|
||||
data['code_secret'] = data.pop('password')
|
||||
response = self.requests.get(
|
||||
|
@ -262,7 +262,7 @@ class LilleUrbanCard(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', description=_('Card Revocation'), methods=['post'])
|
||||
def card_revocation(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
self.preprocess_contact_data(data)
|
||||
response = self.requests.post(
|
||||
urljoin(self.base_url, '/clu/ws/revoquerCarte'), json=data, auth=HttpBearerAuth(self.get_token())
|
||||
|
@ -279,7 +279,7 @@ class LilleUrbanCard(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', description=_('Subscription Revocation'), methods=['post'])
|
||||
def subscription_revocation(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
self.preprocess_contact_data(data)
|
||||
self.preprocess_service_data(data)
|
||||
response = self.requests.post(
|
||||
|
@ -299,7 +299,7 @@ class LilleUrbanCard(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', description=_('Subscription Renewal'), methods=['post'])
|
||||
def subscription_renewal(self, request, *args, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
self.preprocess_contact_data(data)
|
||||
response = self.requests.post(
|
||||
urljoin(self.base_url, '/clu/ws/renouvelerAbonnements'),
|
||||
|
|
|
@ -22,7 +22,6 @@ from urllib import parse as urlparse
|
|||
|
||||
import requests
|
||||
from django.db import models, transaction
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource, HTTPResource
|
||||
|
@ -135,7 +134,7 @@ class MDPH13Resource(BaseResource, HTTPResource):
|
|||
'traitée et expédiée': 'historique',
|
||||
'traitée non expédiée': 'historique',
|
||||
}
|
||||
if not all(isinstance(demande.get('typologie'), six.text_type) for demande in demandes):
|
||||
if not all(isinstance(demande.get('typologie'), str) for demande in demandes):
|
||||
raise APIError('typologie-must-be-a-string', data=content)
|
||||
if not all(demande['typologie'].lower() in typologies for demande in demandes):
|
||||
unknowns = set([demande['typologie'].lower() for demande in demandes]) - set(
|
||||
|
@ -158,7 +157,7 @@ class MDPH13Resource(BaseResource, HTTPResource):
|
|||
|
||||
def check(value, path):
|
||||
if path[-1].startswith('date_'):
|
||||
if isinstance(value, six.text_type) and not self.DATE_RE.match(value):
|
||||
if isinstance(value, str) and not self.DATE_RE.match(value):
|
||||
errors.append('%s is not a date string' % '.'.join(path))
|
||||
|
||||
json_walker(data, check)
|
||||
|
@ -297,14 +296,13 @@ class MDPH13Resource(BaseResource, HTTPResource):
|
|||
raise
|
||||
file_data.update(to_json().err_to_response(e))
|
||||
# do it later as get_filter() can modify str(link)
|
||||
file_data['text'] = six.text_type(link)
|
||||
file_data['text'] = str(link)
|
||||
data.append(file_data)
|
||||
if link_id:
|
||||
return {'data': data[0] if data else None}
|
||||
return {'data': data}
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Link(models.Model):
|
||||
resource = models.ForeignKey(MDPH13Resource, on_delete=models.CASCADE)
|
||||
name_id = models.CharField(verbose_name=_('NameID'), max_length=256)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import csv
|
||||
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -51,8 +50,7 @@ class NancyPoll(BaseResource):
|
|||
content = self.csv_file.read()
|
||||
if not content:
|
||||
raise APIError('No content found')
|
||||
if six.PY3:
|
||||
content = force_text(content)
|
||||
content = force_text(content)
|
||||
|
||||
reader = csv.reader(content.splitlines())
|
||||
next(reader)
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
import calendar
|
||||
from datetime import datetime
|
||||
|
||||
from django.utils import six
|
||||
|
||||
ENCODE_TOKENS = {
|
||||
'integer': 16,
|
||||
'real': 19,
|
||||
|
@ -228,7 +226,7 @@ class MSTEEncoder:
|
|||
if ref is not None:
|
||||
self._push_token_type('ref')
|
||||
self._push(ref)
|
||||
elif isinstance(obj, six.string_types):
|
||||
elif isinstance(obj, str):
|
||||
self._encode_string(obj)
|
||||
elif obj is None:
|
||||
self._encode_nil()
|
||||
|
|
|
@ -23,7 +23,6 @@ from django.db import models
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.contrib.solis_apa import conciliation, integration, suivi
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -314,7 +313,7 @@ class SolisAPA(BaseResource):
|
|||
uri = 'importFlow?flow=ImportIntegrationDemande&application=%s' % APPLICATION
|
||||
url = self.get_resource_url(uri)
|
||||
|
||||
data = {'ImportInputWSDemandeApa': integration.build_message(json_loads(data))}
|
||||
data = {'ImportInputWSDemandeApa': integration.build_message(json.loads(data))}
|
||||
data = json.dumps(data)
|
||||
self.logger.debug('Demande APA: %s' % data, extra={'solis_apa_demande': data})
|
||||
response = self.requests.post(url, data=data, headers=HEADERS)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import json
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from django.db import models
|
||||
|
@ -23,7 +24,6 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from requests import RequestException
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import APIError, endpoint
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ class StrasbourgEu(BaseResource):
|
|||
if name_id is None:
|
||||
raise APIError('missing name_id')
|
||||
# expected content: {"interests": ["123", "456"]}
|
||||
response = json_loads(request.body)
|
||||
response = json.loads(request.body)
|
||||
if 'error ' in response:
|
||||
return {'err': 1, 'err_desc': response.get('error')}
|
||||
interests = response.get('interests')
|
||||
|
@ -134,7 +134,7 @@ class StrasbourgEu(BaseResource):
|
|||
else:
|
||||
# expected content: {"title": ..., "description": ..., "url": ...,
|
||||
# ...}, cf https://strasbourgeurometropole.github.io/slate/#ajout-d-39-une-notification
|
||||
notification = json_loads(request.body)
|
||||
notification = json.loads(request.body)
|
||||
notification['userId'] = name_id
|
||||
url = urlparse.urljoin(self.liferay_api_url, 'jsonws/notification.notification/add-notification')
|
||||
try:
|
||||
|
@ -172,7 +172,7 @@ class StrasbourgEu(BaseResource):
|
|||
else:
|
||||
# expected content: {"title": ..., "url": ..., ...},
|
||||
# cf https://strasbourgeurometropole.github.io/slate/?shell#ajout-d-39-un-favori
|
||||
favorite = json_loads(request.body)
|
||||
favorite = json.loads(request.body)
|
||||
# change type to typeId
|
||||
types_url = urlparse.urljoin(self.liferay_api_url, 'jsonws/favorite.favorite/get-types')
|
||||
try:
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import base64
|
||||
import json
|
||||
import logging
|
||||
import xml.etree.ElementTree as ET
|
||||
from datetime import datetime
|
||||
|
@ -26,7 +27,6 @@ from django.utils.encoding import smart_text
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.soap import client_to_jsondict
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -315,7 +315,7 @@ class TeamnetAxel(BaseResource):
|
|||
pattern=r'^(?P<regie_id>\w+)/invoice/(?P<invoice_id>[\w,-]+)/pay/$',
|
||||
)
|
||||
def pay_invoice(self, request, regie_id, invoice_id, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
transaction_id = data.get('transaction_id')
|
||||
transaction_date = data.get('transaction_date')
|
||||
email = data.get('email')
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
# borrowed from https://pypi.python.org/pypi/suds_requests
|
||||
# and https://docs.oracle.com/cd/E50245_01/E50253/html/vmprg-soap-example-authentication-python.html
|
||||
|
||||
from django.utils.six import BytesIO
|
||||
from io import BytesIO
|
||||
|
||||
from suds.client import Client
|
||||
from suds.transport import Reply
|
||||
from suds.transport.http import HttpAuthenticated
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import base64
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -27,7 +28,6 @@ from django.utils.dates import WEEKDAYS as WEEKDAYS_LABELS
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.contrib.utils import axel
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -873,7 +873,7 @@ class ToulouseAxel(BaseResource):
|
|||
},
|
||||
)
|
||||
def pay_invoice(self, request, regie_id, invoice_id, **kwargs):
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
dui, invoice_id = invoice_id.rsplit('-', 1)
|
||||
|
||||
invoice = self.get_invoice(regie_id=regie_id, dui=dui, invoice_id=invoice_id)
|
||||
|
|
|
@ -20,8 +20,6 @@ from __future__ import unicode_literals
|
|||
import datetime
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.utils.six import string_types
|
||||
|
||||
from passerelle.utils.conversion import normalize
|
||||
|
||||
situation_familiale_mapping = OrderedDict(
|
||||
|
@ -92,7 +90,7 @@ def upperize(data):
|
|||
if isinstance(data, list):
|
||||
for i, val in enumerate(data):
|
||||
data[i] = upperize(val)
|
||||
if isinstance(data, string_types):
|
||||
if isinstance(data, str):
|
||||
data = normalize(data).upper()
|
||||
return data
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ from django.contrib.postgres.fields import ArrayField
|
|||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils import six
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -250,7 +249,6 @@ class SMSResource(BaseResource):
|
|||
abstract = True
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class SMSLog(models.Model):
|
||||
timestamp = models.DateTimeField(auto_now_add=True)
|
||||
appname = models.CharField(max_length=128, verbose_name='appname', null=True)
|
||||
|
|
|
@ -21,6 +21,7 @@ import re
|
|||
import time
|
||||
import warnings
|
||||
from functools import wraps
|
||||
from io import BytesIO
|
||||
from itertools import chain, islice
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -33,7 +34,6 @@ from django.utils.decorators import available_attrs
|
|||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.functional import lazy
|
||||
from django.utils.html import mark_safe
|
||||
from django.utils.six import BytesIO
|
||||
from django.utils.translation import ngettext_lazy
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
from requests import Response as RequestResponse
|
||||
|
|
|
@ -19,7 +19,6 @@ from __future__ import absolute_import
|
|||
import inspect
|
||||
|
||||
from django.urls import reverse
|
||||
from django.utils import six
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
# make APIError available from this module
|
||||
|
@ -109,7 +108,7 @@ class endpoint:
|
|||
def __call__(self, func):
|
||||
func.endpoint_info = self
|
||||
if not self.name:
|
||||
self.name = func.func_name if six.PY2 else func.__name__
|
||||
self.name = func.__name__
|
||||
self.func = func
|
||||
return func
|
||||
|
||||
|
|
|
@ -19,11 +19,10 @@ import math
|
|||
import re
|
||||
import unicodedata
|
||||
import warnings
|
||||
from io import BytesIO
|
||||
|
||||
import unidecode
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six import BytesIO
|
||||
from PIL import Image
|
||||
|
||||
|
||||
|
@ -74,20 +73,20 @@ def to_ascii(s):
|
|||
|
||||
def exception_to_text(e):
|
||||
try:
|
||||
return six.text_type(e)
|
||||
return str(e)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
r = repr(e)
|
||||
return six.text_type(r, errors='replace')
|
||||
return str(r, errors='replace')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
args = e.args
|
||||
try:
|
||||
content = six.text_type(repr(args)) if args != [] else ''
|
||||
content = str(repr(args)) if args != [] else ''
|
||||
except Exception:
|
||||
content = '<exception-while-rendering-args>'
|
||||
except AttributeError:
|
||||
|
|
|
@ -31,8 +31,6 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils import six
|
||||
|
||||
from passerelle.utils.validation import is_number
|
||||
|
||||
FLATTEN_SEPARATOR = '/'
|
||||
|
@ -110,7 +108,7 @@ def flatten(data, separator=FLATTEN_SEPARATOR):
|
|||
for path, value in helper(value):
|
||||
yield [str(i)] + path, value
|
||||
elif isinstance(data, dict):
|
||||
for key, value in six.iteritems(data):
|
||||
for key, value in data.items():
|
||||
for path, value in helper(value):
|
||||
yield [str(key)] + path, value
|
||||
else:
|
||||
|
|
|
@ -27,7 +27,6 @@ import paramiko
|
|||
from django import forms
|
||||
from django.core import validators
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from paramiko.dsskey import DSSKey
|
||||
|
@ -59,7 +58,6 @@ def _load_private_key(content_or_file, password=None):
|
|||
pass
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class SFTP:
|
||||
def __init__(self, url, private_key_content=None, private_key_password=None):
|
||||
self.url = url
|
||||
|
|
|
@ -31,7 +31,6 @@ from django import forms
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
|
||||
from passerelle.base import signature
|
||||
|
||||
|
@ -114,7 +113,6 @@ class Evolution(BaseObject):
|
|||
self.who = EvolutionUser(wcs_api, **self.who)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class FormData(BaseObject):
|
||||
geolocations = None
|
||||
evolution = None
|
||||
|
@ -411,7 +409,7 @@ class FormDefSubmit:
|
|||
content_type = kwargs.get('content_type', 'application/octet-stream')
|
||||
if hasattr(value, 'read'):
|
||||
content = base64.b64encode(value.read())
|
||||
elif isinstance(value, six.binary_type):
|
||||
elif isinstance(value, bytes):
|
||||
content = base64.b64encode(value)
|
||||
elif isinstance(value, dict):
|
||||
if not set(value).issuperset(set(['filename', 'content'])):
|
||||
|
@ -428,7 +426,7 @@ class FormDefSubmit:
|
|||
}
|
||||
|
||||
def _set_type_date(self, varname, field, value):
|
||||
if isinstance(value, six.string_types):
|
||||
if isinstance(value, str):
|
||||
value = datetime.datetime.strptime(value, '%Y-%m-%d').date()
|
||||
if isinstance(value, datetime.datetime):
|
||||
value = value.date()
|
||||
|
@ -444,7 +442,7 @@ class FormDefSubmit:
|
|||
self.data[varname] = value
|
||||
|
||||
def _set_type_bool(self, varname, field, value):
|
||||
if isinstance(value, six.string_types):
|
||||
if isinstance(value, str):
|
||||
value = value.lower().strip() in ['yes', 'true', 'on']
|
||||
if not isinstance(value, bool):
|
||||
raise TypeError('value must be a boolean or a string true, yes, on, false, no, off')
|
||||
|
@ -454,7 +452,6 @@ class FormDefSubmit:
|
|||
raise CancelSubmitError
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class FormDef(BaseObject):
|
||||
geolocations = None
|
||||
|
||||
|
@ -645,7 +642,6 @@ def get_wcs_choices(session=None):
|
|||
return choices
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class FormDefRef:
|
||||
_formdef = None
|
||||
_api = None
|
||||
|
@ -655,7 +651,7 @@ class FormDefRef:
|
|||
if value2:
|
||||
self.wcs_slug, self.formdef_slug = value1, value2
|
||||
else:
|
||||
self.wcs_slug, self.formdef_slug = six.text_type(value1).rsplit(':', 1)
|
||||
self.wcs_slug, self.formdef_slug = str(value1).rsplit(':', 1)
|
||||
|
||||
@property
|
||||
def api(self):
|
||||
|
|
|
@ -28,7 +28,6 @@ from django.template import Context, Template, TemplateDoesNotExist, TemplateSyn
|
|||
from django.template.loader import get_template
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.six import python_2_unicode_compatible
|
||||
from jsonschema import ValidationError, validate
|
||||
|
||||
from passerelle.utils.files import atomic_write
|
||||
|
@ -92,7 +91,6 @@ class ZipTemplateSyntaxError(ZipTemplateError):
|
|||
VARIABLE_RE = re.compile(r'{{ *(\w*)')
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class ZipPart:
|
||||
def __init__(self, zip_template, name_template, template_path=None, content_expression=None):
|
||||
self.zip_template = zip_template
|
||||
|
|
|
@ -53,7 +53,6 @@ from django.views.generic.detail import SingleObjectMixin
|
|||
from jsonschema import ValidationError, validate, validators
|
||||
|
||||
from passerelle.base.models import BaseResource, ResourceLog
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.conversion import normalize
|
||||
from passerelle.utils.json import unflatten
|
||||
from passerelle.utils.jsonresponse import APIError, JSONEncoder
|
||||
|
@ -397,7 +396,7 @@ class GenericEndpointView(GenericConnectorMixin, SingleObjectMixin, View):
|
|||
merge_extra = hasattr(json_schema, 'items') and json_schema.get('merge_extra', False)
|
||||
pre_process = hasattr(json_schema, 'items') and json_schema.get('pre_process')
|
||||
try:
|
||||
data = json_loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
except ValueError as e:
|
||||
raise APIError("could not decode body to json: %s" % e, http_status=400)
|
||||
if must_unflatten:
|
||||
|
|
|
@ -6,14 +6,10 @@ import pytest
|
|||
from django.contrib.auth.models import User
|
||||
from django.core.cache import cache
|
||||
from django.core.files import File
|
||||
from django.utils import six
|
||||
from httmock import HTTMock, remember_called, response, urlmatch
|
||||
|
||||
from tests.utils import make_resource
|
||||
|
||||
if six.PY2:
|
||||
collect_ignore = ['wcs/']
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def media(settings, tmpdir):
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
from io import StringIO
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from django.core.files import File
|
||||
from django.utils.six import StringIO
|
||||
|
||||
import tests.utils
|
||||
from passerelle.apps.base_adresse.models import BaseAdresse
|
||||
|
|
|
@ -13,7 +13,6 @@ from httmock import HTTMock
|
|||
import tests.utils
|
||||
from passerelle.apps.cartads_cs.models import CartaDSCS, CartaDSDossier, CartaDSFile
|
||||
from passerelle.base.models import Job
|
||||
from passerelle.compat import json_loads
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -716,12 +715,12 @@ def test_role_sync(connector, app, cached_data):
|
|||
assert url.netloc == 'idp.example.org'
|
||||
if url.path == '/api/roles/':
|
||||
dossier = CartaDSDossier.objects.all().first()
|
||||
assert json_loads(request.body) == json.loads(
|
||||
assert json.loads(request.body) == json.loads(
|
||||
'{"name": "Suivi Cart@DS (%s)", "slug": "_cartads_%s"}' % (dossier.id, dossier.id)
|
||||
)
|
||||
return {'content': json.dumps({'uuid': 'role-uuid'}), 'status_code': 200}
|
||||
elif url.path == '/api/roles/role-uuid/relationships/members/':
|
||||
body = json_loads(request.body)
|
||||
body = json.loads(request.body)
|
||||
idp_mock.subscribed_roles = set([x['uuid'] for x in body['data']])
|
||||
return {'content': json.dumps({'err': 0}), 'status_code': 200}
|
||||
raise Exception('unhandled http call (%s)' % url)
|
||||
|
|
|
@ -17,16 +17,17 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import uuid
|
||||
from io import StringIO
|
||||
from posix import stat_result
|
||||
from stat import ST_MTIME
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
import webtest
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.files import File
|
||||
|
@ -35,12 +36,10 @@ from django.core.management import call_command
|
|||
from django.test import Client, override_settings
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import force_bytes, force_str, force_text
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.timezone import now
|
||||
|
||||
from passerelle.apps.csvdatasource.models import CsvDataSource, Query, TableRow, upload_to
|
||||
from passerelle.base.models import AccessRight, ApiUser
|
||||
from passerelle.compat import json_loads
|
||||
from tests.test_manager import login
|
||||
|
||||
data = """121;69981;DELANOUE;Eliot;H
|
||||
|
@ -114,7 +113,7 @@ def setup():
|
|||
|
||||
|
||||
def parse_response(response):
|
||||
return json_loads(response.content)['data']
|
||||
return json.loads(response.content)['data']
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -345,7 +344,7 @@ def test_on_the_fly_dialect_detection(client, setup):
|
|||
_, url = setup(data=StringIO(data))
|
||||
CsvDataSource.objects.all().update(_dialect_options=None)
|
||||
resp = client.get(url)
|
||||
result = json_loads(resp.content)
|
||||
result = json.loads(resp.content)
|
||||
assert result['err'] == 0
|
||||
assert len(result['data']) == 20
|
||||
|
||||
|
@ -353,7 +352,7 @@ def test_on_the_fly_dialect_detection(client, setup):
|
|||
def test_missing_columns(client, setup):
|
||||
_, url = setup(data=StringIO(data + 'A;B;C\n'))
|
||||
resp = client.get(url)
|
||||
result = json_loads(resp.content)
|
||||
result = json.loads(resp.content)
|
||||
assert result['err'] == 0
|
||||
assert len(result['data']) == 21
|
||||
assert result['data'][-1] == {'lname': 'C', 'sex': '', 'id': 'B', 'fname': '', 'fam': 'A'}
|
||||
|
@ -364,20 +363,20 @@ def test_unknown_sheet_name(client, setup):
|
|||
csvdata.sheet_name = 'unknown'
|
||||
csvdata.save()
|
||||
resp = client.get(url)
|
||||
result = json_loads(resp.content)
|
||||
result = json.loads(resp.content)
|
||||
assert len(result['data']) == 20
|
||||
|
||||
|
||||
def test_cache_new_shorter_file(client, setup):
|
||||
csvdata, url = setup(data=StringIO(data + 'A;B;C\n'))
|
||||
resp = client.get(url)
|
||||
result = json_loads(resp.content)
|
||||
result = json.loads(resp.content)
|
||||
assert result['err'] == 0
|
||||
assert len(result['data']) == 21
|
||||
csvdata.csv_file = File(StringIO(data), 'data.csv')
|
||||
csvdata.save()
|
||||
resp = client.get(url)
|
||||
result = json_loads(resp.content)
|
||||
result = json.loads(resp.content)
|
||||
assert len(result['data']) == 20
|
||||
|
||||
|
||||
|
@ -400,7 +399,7 @@ def test_query_array(app, setup, filetype):
|
|||
for row in response.json['data']:
|
||||
assert len(row) == 2
|
||||
assert isinstance(row[0], int)
|
||||
assert isinstance(row[1], six.text_type)
|
||||
assert isinstance(row[1], str)
|
||||
|
||||
|
||||
def test_query_q_filter(app, setup, filetype):
|
||||
|
@ -449,7 +448,7 @@ def test_query_dict(app, setup, filetype):
|
|||
for row in response.json['data']:
|
||||
assert len(row) == 2
|
||||
assert isinstance(row['id'], int)
|
||||
assert isinstance(row['prenom'], six.text_type)
|
||||
assert isinstance(row['prenom'], str)
|
||||
|
||||
|
||||
def test_query_tuples(app, setup, filetype):
|
||||
|
@ -473,7 +472,7 @@ def test_query_tuples(app, setup, filetype):
|
|||
assert row[0][0] == 'id'
|
||||
assert isinstance(row[0][1], int)
|
||||
assert row[1][0] == 'prenom'
|
||||
assert isinstance(row[1][1], six.text_type)
|
||||
assert isinstance(row[1][1], str)
|
||||
|
||||
|
||||
def test_query_onerow(app, setup, filetype):
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
import pytest
|
||||
from django.core.files import File
|
||||
from django.core.management import call_command
|
||||
from django.db import connection
|
||||
from django.utils.six import BytesIO
|
||||
|
||||
from passerelle.apps.csvdatasource.models import CsvDataSource
|
||||
from passerelle.contrib.teamnet_axel.models import TeamnetAxel
|
||||
|
|
|
@ -20,7 +20,6 @@ import os
|
|||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
from django.urls import reverse
|
||||
|
||||
import tests.utils
|
||||
|
@ -119,7 +118,7 @@ Création de la demande via le webService de la commune de Grenoble
|
|||
|
||||
@pytest.fixture(params=['01', '02', '10', '20', '21', '23', '4242'])
|
||||
def remote_response(request):
|
||||
text = six.text_type(request.param)
|
||||
text = str(request.param)
|
||||
return tests.utils.FakedResponse(index=request.param_index, text=text)
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import json
|
|||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
from io import BytesIO, StringIO
|
||||
|
||||
import pytest
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
@ -12,7 +13,6 @@ from django.test import Client
|
|||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.six import BytesIO, StringIO
|
||||
|
||||
from passerelle.apps.base_adresse.models import BaseAdresse
|
||||
from passerelle.apps.bdp.models import Bdp
|
||||
|
@ -20,7 +20,6 @@ from passerelle.apps.csvdatasource.models import CsvDataSource, Query
|
|||
from passerelle.apps.ovh.models import OVHSMSGateway
|
||||
from passerelle.apps.sector.models import SectorResource
|
||||
from passerelle.base.models import AccessRight, ApiUser
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils import ImportSiteError, export_site, import_site
|
||||
|
||||
data = """121;69981;DELANOUE;Eliot;H
|
||||
|
@ -91,7 +90,7 @@ def setup():
|
|||
|
||||
|
||||
def parse_response(response):
|
||||
return json_loads(response.content)['data']
|
||||
return json.loads(response.content)['data']
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -138,7 +137,7 @@ def test_export_csvdatasource(app, setup, filetype):
|
|||
assert first == second
|
||||
|
||||
output = get_output_of_command('export_site')
|
||||
third = json_loads(output)
|
||||
third = json.loads(output)
|
||||
third['resources'][0]['csv_file']['name'] = 'whocares'
|
||||
assert first == third
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
@ -5,7 +6,6 @@ from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
|||
from django.http import Http404
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils import to_json
|
||||
|
||||
|
||||
|
@ -109,7 +109,7 @@ def test_jsonresponse_log_as_warning_exception(caplog):
|
|||
assert record.method == 'GET'
|
||||
assert "Error occurred while processing request" in record.message
|
||||
assert response.status_code == 488
|
||||
data = json_loads(response.content)
|
||||
data = json.loads(response.content)
|
||||
assert data['err'] == 'logaswarningexception'
|
||||
assert data['err_desc'] == 'log as warning exception'
|
||||
|
||||
|
@ -124,7 +124,7 @@ def test_jsonresponse_error_header():
|
|||
|
||||
result = test_func(req)
|
||||
assert result.status_code == 200
|
||||
data = json_loads(result.content)
|
||||
data = json.loads(result.content)
|
||||
assert data == {'test': 'un test', 'err': 0}
|
||||
|
||||
@to_json()
|
||||
|
@ -135,7 +135,7 @@ def test_jsonresponse_error_header():
|
|||
raise CustomException
|
||||
|
||||
result = test_func2(req)
|
||||
data = json_loads(result.content)
|
||||
data = json.loads(result.content)
|
||||
assert 'err_class' in data
|
||||
assert 'err' in data
|
||||
assert data['err'] == 1
|
||||
|
@ -161,7 +161,7 @@ def test_jsonresponse_with_callback():
|
|||
content_type = result.get('Content-Type')
|
||||
assert 'application/javascript' in content_type
|
||||
assert result.content.startswith(b'myfunc(')
|
||||
args = json_loads(result.content[7:-2])
|
||||
args = json.loads(result.content[7:-2])
|
||||
assert args == {'foo': 'bar', 'err': 0}
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import pytest
|
|||
from httmock import HTTMock
|
||||
|
||||
import tests.utils
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.contrib.lille_urban_card.models import LilleUrbanCard
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -29,7 +28,7 @@ def mocked_http(url, request):
|
|||
if url.path == '/clu/ws/auth/connexion':
|
||||
return {'content': TOKEN_RESPONSE, 'status_code': 200}
|
||||
if url.path == '/clu/ws/demanderCarte':
|
||||
request_json = json_loads(request.body)
|
||||
request_json = json.loads(request.body)
|
||||
if request_json.get('simulate_error') == 'doublon':
|
||||
error = {'erreur': 'Demande 113-9166 : 1 demande(s) ...'}
|
||||
return {'content': json.dumps(error), 'status_code': 409}
|
||||
|
@ -50,7 +49,7 @@ def mocked_http(url, request):
|
|||
}
|
||||
return {'content': json.dumps(content), 'status_code': 200}
|
||||
if url.path == '/clu/ws/ajouterAbonnements':
|
||||
request_json = json_loads(request.body)
|
||||
request_json = json.loads(request.body)
|
||||
if request_json.get('simulate_error') == 'data':
|
||||
error = {'statut': 'ERREUR_DONNEES', 'erreur': 'Demande vide...'}
|
||||
return {'content': json.dumps(error), 'status_code': 400}
|
||||
|
@ -60,7 +59,7 @@ def mocked_http(url, request):
|
|||
}
|
||||
return {'content': json.dumps(content), 'status_code': 200}
|
||||
if url.path == '/clu/ws/modifierCodeSecret':
|
||||
request_json = json_loads(request.body)
|
||||
request_json = json.loads(request.body)
|
||||
if request_json.get('simulate_error') == 'wrong num serie':
|
||||
error = {'statut': 'ERREUR_NUM_SERIE', 'erreur': 'Le numero de serie...'}
|
||||
return {'content': json.dumps(error), 'status_code': 404}
|
||||
|
@ -72,13 +71,13 @@ def mocked_http(url, request):
|
|||
return {'content': json.dumps(error), 'status_code': 404}
|
||||
return {'content': json.dumps({'message': 'Le mot de passe est valide'}), 'status_code': 200}
|
||||
if url.path in ('/clu/ws/revoquerCarte', '/clu/ws/revoquerAbonnement'):
|
||||
request_json = json_loads(request.body)
|
||||
request_json = json.loads(request.body)
|
||||
if request_json.get('simulate_error') == 'doublon':
|
||||
error = {'erreur': 'La demande xx existe...'}
|
||||
return {'content': json.dumps(error), 'status_code': 409}
|
||||
return {'content': json.dumps({'message': 'ok'}), 'status_code': 200}
|
||||
if url.path == '/clu/ws/renouvelerAbonnements':
|
||||
request_json = json_loads(request.body)
|
||||
request_json = json.loads(request.body)
|
||||
if request_json.get('simulate_error') == 'wrong num serie':
|
||||
error = {'statut': 'ERREUR_NUM_SERIE', 'erreur': 'Le numero de serie...'}
|
||||
return {'content': json.dumps(error), 'status_code': 409}
|
||||
|
|
|
@ -2,13 +2,13 @@ import datetime
|
|||
import json
|
||||
import re
|
||||
import uuid
|
||||
from io import StringIO
|
||||
|
||||
import freezegun
|
||||
import pytest
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.files import File
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.timezone import now
|
||||
from webtest import Upload
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import base64
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
|
@ -30,7 +31,6 @@ import tests.utils
|
|||
from passerelle.apps.mdel.mdel import AttachedFile, Description, Message, get_resource_base_dir
|
||||
from passerelle.apps.mdel.models import MDEL, Demand
|
||||
from passerelle.apps.mdel.utils import parse_date
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils import SFTP
|
||||
|
||||
AEC_XSD = 'ActeEtatCivil-V1.A.xsd'
|
||||
|
@ -69,9 +69,9 @@ def setup(db):
|
|||
|
||||
@pytest.fixture(
|
||||
params=[
|
||||
json_loads(get_file_from_test_base_dir('formdata_aec_naiss.json')),
|
||||
json_loads(get_file_from_test_base_dir('formdata_aec_mariage.json')),
|
||||
json_loads(get_file_from_test_base_dir('formdata_aec_deces.json')),
|
||||
json.loads(get_file_from_test_base_dir('formdata_aec_naiss.json')),
|
||||
json.loads(get_file_from_test_base_dir('formdata_aec_mariage.json')),
|
||||
json.loads(get_file_from_test_base_dir('formdata_aec_deces.json')),
|
||||
],
|
||||
ids=['naissance', 'mariage', 'deces'],
|
||||
)
|
||||
|
@ -79,7 +79,7 @@ def aec_payload(request):
|
|||
return request.param
|
||||
|
||||
|
||||
ILE_PAYLOAD = json_loads(get_file_from_test_base_dir('formdata.json'))
|
||||
ILE_PAYLOAD = json.loads(get_file_from_test_base_dir('formdata.json'))
|
||||
|
||||
|
||||
def test_message():
|
||||
|
@ -344,7 +344,7 @@ def test_create_aec_demand_with_input_sftp(app, setup, aec_payload, sftpserver):
|
|||
|
||||
|
||||
def test_create_aec_demand_type_without_date_acte(app, setup):
|
||||
payload = json_loads(get_file_from_test_base_dir('formdata_aec_deces.json'))
|
||||
payload = json.loads(get_file_from_test_base_dir('formdata_aec_deces.json'))
|
||||
payload['fields'].pop('date_acte')
|
||||
resp = app.post_json('/mdel/test/create', params=payload, status=200)
|
||||
assert resp.json['err_desc'] == '<date_acte> is required'
|
||||
|
@ -506,13 +506,13 @@ def test_create_ile_demand_type(app, setup):
|
|||
|
||||
def test_create_ile_demand_type_invalid_document_proof(app, setup):
|
||||
# test with missing key
|
||||
payload = json_loads(get_file_from_test_base_dir('formdata.json'))
|
||||
payload = json.loads(get_file_from_test_base_dir('formdata.json'))
|
||||
payload['fields'].pop('justificatif_domicile_hebergeur')
|
||||
resp = app.post_json('/mdel/test/create', params=payload, status=200)
|
||||
assert resp.json['err_desc'] == 'justificatif_domicile and all its attributes are required'
|
||||
|
||||
# test with invalid content
|
||||
payload = json_loads(get_file_from_test_base_dir('formdata.json'))
|
||||
payload = json.loads(get_file_from_test_base_dir('formdata.json'))
|
||||
payload['fields']['justificatif_identite'] = None
|
||||
payload['fields']['justificatif_identite_verso'] = None
|
||||
resp = app.post_json('/mdel/test/create', params=payload, status=200)
|
||||
|
@ -658,7 +658,7 @@ def test_date_parsing():
|
|||
|
||||
|
||||
def test_aec_filenames_and_routing(app, setup):
|
||||
aec_payload = json_loads(get_file_from_test_base_dir('formdata_aec_naiss.json'))
|
||||
aec_payload = json.loads(get_file_from_test_base_dir('formdata_aec_naiss.json'))
|
||||
resp = app.post_json('/mdel/test/create', params=aec_payload, status=200)
|
||||
|
||||
assert resp.json['data']['demand_id'] == '15-4-AEC-LA'
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import datetime
|
||||
from io import StringIO
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
@ -8,7 +9,6 @@ from django.db import connection
|
|||
from django.db.migrations.executor import MigrationExecutor
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.six import StringIO
|
||||
from mock import patch
|
||||
from requests.exceptions import ReadTimeout
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import json
|
||||
from io import StringIO
|
||||
|
||||
import pytest
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.files import File
|
||||
from django.test import Client
|
||||
from django.urls import reverse
|
||||
from django.utils.six import StringIO
|
||||
|
||||
from passerelle.base.models import AccessRight, ApiUser
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.contrib.nancypoll.models import NancyPoll
|
||||
|
||||
data = """
|
||||
|
@ -30,7 +31,7 @@ data = """
|
|||
|
||||
|
||||
def parse_response(response):
|
||||
return json_loads(response.content)['data']
|
||||
return json.loads(response.content)['data']
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -50,7 +51,7 @@ def setup(db):
|
|||
def test_failure(setup):
|
||||
url, client = setup
|
||||
qs = {'street_no': '37000', 'street_name': 'Rue du Marechal Juin'}
|
||||
resp = json_loads(client.get(url, qs).content)
|
||||
resp = json.loads(client.get(url, qs).content)
|
||||
assert resp['err_desc'] == 'Polling Station Not Found'
|
||||
assert int(resp['err']) != 0
|
||||
|
||||
|
@ -60,8 +61,8 @@ def test_no_params(setup):
|
|||
qs = {}
|
||||
resp = client.get(url, qs)
|
||||
assert resp.status_code == 200
|
||||
assert json_loads(resp.content)['err_desc'] == 'All parameters are required'
|
||||
assert int(json_loads(resp.content)['err']) != 0
|
||||
assert json.loads(resp.content)['err_desc'] == 'All parameters are required'
|
||||
assert int(json.loads(resp.content)['err']) != 0
|
||||
|
||||
|
||||
def test_invalid_street_no(setup):
|
||||
|
@ -69,8 +70,8 @@ def test_invalid_street_no(setup):
|
|||
qs = {'street_no': 'lol', 'street_name': 'whatever'}
|
||||
resp = client.get(url, qs)
|
||||
assert resp.status_code == 200
|
||||
assert json_loads(resp.content)['err_desc'] == 'Invalid street no value'
|
||||
assert int(json_loads(resp.content)['err']) != 0
|
||||
assert json.loads(resp.content)['err_desc'] == 'Invalid street no value'
|
||||
assert int(json.loads(resp.content)['err']) != 0
|
||||
|
||||
|
||||
def test_success_i_side(setup):
|
||||
|
|
|
@ -8,7 +8,6 @@ import pytest
|
|||
import requests
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.log import AdminEmailHandler
|
||||
from django.utils.six import PY2
|
||||
from httmock import HTTMock
|
||||
|
||||
import tests.utils
|
||||
|
@ -315,10 +314,7 @@ def test_logged_requests_and_responses_max_size(app, db, monkeypatch, settings):
|
|||
assert not ResourceLog.objects.all()[1].extra.get('response_content')
|
||||
|
||||
# - connector error
|
||||
if PY2:
|
||||
assert ResourceLog.objects.all()[2].extra['body'] == "'user_query_var=11111111111111111111'"
|
||||
else:
|
||||
assert ResourceLog.objects.all()[2].extra['body'] == 'user_query_var=11111111111111111111'
|
||||
assert ResourceLog.objects.all()[2].extra['body'] == 'user_query_var=11111111111111111111'
|
||||
assert (
|
||||
ResourceLog.objects.all()[2].extra['exception'] == "{'connector_error_var': '44444444444444444444'}"
|
||||
)
|
||||
|
@ -334,16 +330,10 @@ def test_logged_requests_and_responses_max_size(app, db, monkeypatch, settings):
|
|||
# - connector POST queries
|
||||
assert ResourceLog.objects.all()[1].extra['request_payload'] == "connector_query_var=22222222222222222222"
|
||||
assert ResourceLog.objects.all()[1].extra.get('response_headers') == {'Content-Type': 'foo/bar'}
|
||||
if PY2:
|
||||
assert (
|
||||
ResourceLog.objects.all()[1].extra.get('response_content')
|
||||
== '{"service_reply_var": "33333333333333333333"}'
|
||||
)
|
||||
else:
|
||||
assert (
|
||||
ResourceLog.objects.all()[1].extra.get('response_content')
|
||||
== '{"service_reply_var": "33333333333333333333"}'
|
||||
)
|
||||
assert (
|
||||
ResourceLog.objects.all()[1].extra.get('response_content')
|
||||
== '{"service_reply_var": "33333333333333333333"}'
|
||||
)
|
||||
|
||||
# log troncated payloads
|
||||
parameters = connector.logging_parameters
|
||||
|
@ -361,10 +351,7 @@ def test_logged_requests_and_responses_max_size(app, db, monkeypatch, settings):
|
|||
assert ResourceLog.objects.all()[1].extra['request_payload'] == 'connector_query_var=22222'
|
||||
|
||||
# - connector error
|
||||
if PY2:
|
||||
assert ResourceLog.objects.all()[2].extra['body'] == "'user_query_var=1111111111'"
|
||||
else:
|
||||
assert ResourceLog.objects.all()[2].extra['body'] == 'user_query_var=1111111111'
|
||||
assert ResourceLog.objects.all()[2].extra['body'] == 'user_query_var=1111111111'
|
||||
|
||||
# log troncated service response
|
||||
parameters = connector.logging_parameters
|
||||
|
@ -376,10 +363,7 @@ def test_logged_requests_and_responses_max_size(app, db, monkeypatch, settings):
|
|||
assert len(ResourceLog.objects.all()) == 3
|
||||
|
||||
# - connector POST queries
|
||||
if PY2:
|
||||
assert ResourceLog.objects.all()[1].extra.get('response_content') == '{"service_reply_var": "33'
|
||||
else:
|
||||
assert ResourceLog.objects.all()[1].extra.get('response_content') == '{"service_reply_var": "33'
|
||||
assert ResourceLog.objects.all()[1].extra.get('response_content') == '{"service_reply_var": "33'
|
||||
|
||||
|
||||
def test_proxy_logger_email_traceback(app, db, email_handler, settings, mailoutbox, connector, monkeypatch):
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import datetime
|
||||
import os
|
||||
from io import StringIO
|
||||
from posix import stat_result
|
||||
from stat import ST_MTIME
|
||||
|
||||
|
@ -26,7 +27,6 @@ from django.core.files import File
|
|||
from django.core.management import call_command
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import force_str, force_text
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.timezone import now
|
||||
|
||||
import tests.utils
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from io import StringIO
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.files import File
|
||||
from django.utils.six import StringIO
|
||||
|
||||
import tests.utils
|
||||
from passerelle.apps.solis.models import Solis, SolisAPALink, SolisRSALink, unflat
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
import inspect
|
||||
|
||||
from django.apps import apps
|
||||
from django.utils import six, translation
|
||||
from django.utils import translation
|
||||
|
||||
from passerelle.base.templatetags.passerelle import render_body_schemas, render_json_schema
|
||||
|
||||
|
@ -25,7 +25,6 @@ from passerelle.base.templatetags.passerelle import render_body_schemas, render_
|
|||
def test_render_body_schemas(db):
|
||||
# FIXME: db should be required but the way ProxyLogger is initialized force an access to the DB
|
||||
def collect_schemas():
|
||||
predicate = inspect.isfunction if six.PY3 else inspect.ismethod
|
||||
for app in apps.get_app_configs():
|
||||
connector_model = None
|
||||
if not hasattr(app, 'get_connector_model'):
|
||||
|
@ -33,7 +32,7 @@ def test_render_body_schemas(db):
|
|||
connector_model = app.get_connector_model()
|
||||
if connector_model is None:
|
||||
continue
|
||||
for _, method in inspect.getmembers(connector_model, predicate):
|
||||
for _, method in inspect.getmembers(connector_model, inspect.isfunction):
|
||||
if not hasattr(method, 'endpoint_info'):
|
||||
continue
|
||||
if method.endpoint_info.post and method.endpoint_info.post.get('request_body', {}).get(
|
||||
|
|
|
@ -7,7 +7,6 @@ from django.contrib.contenttypes.models import ContentType
|
|||
from django.urls import reverse
|
||||
|
||||
from passerelle.base.models import AccessRight, ApiUser
|
||||
from passerelle.compat import json_loads
|
||||
|
||||
|
||||
def generic_endpoint_url(connector, endpoint, slug='test'):
|
||||
|
@ -25,7 +24,7 @@ class FakedResponse(mock.Mock):
|
|||
headers = {}
|
||||
|
||||
def json(self):
|
||||
return json_loads(self.content)
|
||||
return json.loads(self.content)
|
||||
|
||||
|
||||
def mock_url(url=None, response='', status_code=200, headers=None, reason=None, exception=None, qs=None):
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import configparser
|
||||
import contextlib
|
||||
import os
|
||||
import pickle
|
||||
|
@ -29,7 +30,6 @@ import time
|
|||
import httmock
|
||||
import psycopg2
|
||||
import pytest
|
||||
from django.utils.six.moves import configparser as ConfigParser
|
||||
|
||||
|
||||
def find_free_tcp_port():
|
||||
|
@ -157,7 +157,7 @@ class WcsHost(object):
|
|||
@property
|
||||
@contextlib.contextmanager
|
||||
def site_options(self):
|
||||
config = ConfigParser.ConfigParser()
|
||||
config = configparser.ConfigParser()
|
||||
|
||||
site_options_path = os.path.join(self.app_dir, 'site-options.cfg')
|
||||
if os.path.exists(site_options_path):
|
||||
|
|
Loading…
Reference in New Issue