0001-misc-remove-usage-of-six-module-63682.patch
functests/cmis/tests_cmis.py | ||
---|---|---|
1 | 1 |
import base64 |
2 | 2 |
import hashlib |
3 | 3 |
import os |
4 |
import urllib.parse |
|
4 | 5 | |
5 | 6 |
import pytest |
6 | 7 |
import requests |
7 |
from django.utils.six.moves.urllib import parse as urlparse |
|
8 | 8 | |
9 | 9 |
SPECIAL_CHARS = '!#$%&+-^_`;[]{}+=' |
10 | 10 | |
... | ... | |
25 | 25 |
orig_file = tmpdir.join(file_name) |
26 | 26 |
with orig_file.open('wb') as f: |
27 | 27 |
f.write(os.urandom(1024)) |
28 |
url = urlparse.urljoin(cmis_connector, 'uploadfile') |
|
28 |
url = urllib.parse.urljoin(cmis_connector, 'uploadfile')
|
|
29 | 29 |
with orig_file.open('rb') as f: |
30 | 30 |
file_b64_content = base64.b64encode(f.read()) |
31 | 31 |
response = requests.post( |
... | ... | |
54 | 54 | |
55 | 55 | |
56 | 56 |
def test_uploadfile_conflict(cmisclient, cmis_connector, cmis_tmpdir, tmpdir, monkeypatch): |
57 |
url = urlparse.urljoin(cmis_connector, 'uploadfile') |
|
57 |
url = urllib.parse.urljoin(cmis_connector, 'uploadfile')
|
|
58 | 58 |
file_b64_content = base64.b64encode('file_content') |
59 | 59 |
response = requests.post( |
60 | 60 |
url, |
functests/planitech/test_planitech.py | ||
---|---|---|
1 | 1 |
import pprint |
2 | 2 |
import random |
3 |
import urllib.parse |
|
3 | 4 | |
4 | 5 |
import requests |
5 |
from django.utils.six.moves.urllib import parse |
|
6 | 6 | |
7 | 7 | |
8 | 8 |
def test_main(conn): |
9 | 9 |
# get days |
10 |
query_string = parse.urlencode( |
|
10 |
query_string = urllib.parse.urlencode(
|
|
11 | 11 |
{'start_days': 1, 'end_days': 90, 'start_time': '10:00', 'end_time': '11:00', 'display': 'date'} |
12 | 12 |
) |
13 | 13 |
url = conn + '/getfreegaps?%s' % query_string |
... | ... | |
19 | 19 |
assert data |
20 | 20 | |
21 | 21 |
# get places |
22 |
query_string = parse.urlencode( |
|
22 |
query_string = urllib.parse.urlencode(
|
|
23 | 23 |
{'start_days': 1, 'end_days': 90, 'start_time': '10:00', 'end_time': '11:00', 'display': 'place'} |
24 | 24 |
) |
25 | 25 |
url = conn + '/getfreegaps?%s' % query_string |
... | ... | |
32 | 32 |
place = data[random.randint(0, len(data) - 1)]['id'] |
33 | 33 | |
34 | 34 |
# get days on one place |
35 |
query_string = parse.urlencode( |
|
35 |
query_string = urllib.parse.urlencode(
|
|
36 | 36 |
{ |
37 | 37 |
'start_days': 1, |
38 | 38 |
'end_days': 90, |
passerelle/apps/actesweb/models.py | ||
---|---|---|
16 | 16 |
from __future__ import unicode_literals |
17 | 17 | |
18 | 18 |
import contextlib |
19 |
import json |
|
19 | 20 |
import os |
20 | 21 |
import stat |
21 | 22 |
import tempfile |
... | ... | |
28 | 29 |
from django.utils.translation import ugettext_lazy as _ |
29 | 30 | |
30 | 31 |
from passerelle.base.models import BaseResource |
31 |
from passerelle.compat import json_loads |
|
32 | 32 |
from passerelle.utils.api import endpoint |
33 | 33 |
from passerelle.utils.conversion import ensure_encoding |
34 | 34 |
from passerelle.utils.jsonresponse import APIError |
... | ... | |
53 | 53 |
@endpoint(perm='can_access', methods=['post'], description=_('Create demand')) |
54 | 54 |
def create(self, request, *args, **kwargs): |
55 | 55 |
try: |
56 |
payload = json_loads(request.body)
|
|
56 |
payload = json.loads(request.body)
|
|
57 | 57 |
except (ValueError,): |
58 | 58 |
raise APIError('Invalid payload format: json expected') |
59 | 59 |
passerelle/apps/api_entreprise/models.py | ||
---|---|---|
18 | 18 |
https://entreprise.api.gouv.fr |
19 | 19 |
''' |
20 | 20 | |
21 |
import urllib.parse |
|
22 | ||
21 | 23 |
import requests |
22 | 24 |
from django.core import signing |
23 | 25 |
from django.db import models |
... | ... | |
25 | 27 |
from django.urls import reverse |
26 | 28 |
from django.utils.timezone import datetime, make_aware, timedelta |
27 | 29 |
from django.utils.translation import ugettext_lazy as _ |
28 |
from six.moves.urllib_parse import urljoin |
|
29 | 30 | |
30 | 31 |
from passerelle.base.models import BaseResource |
31 | 32 |
from passerelle.utils.api import endpoint |
... | ... | |
97 | 98 |
params['recipient'] = kwargs.get('recipient') or self.recipient |
98 | 99 |
if kwargs.get('non_diffusables'): |
99 | 100 |
params['non_diffusables'] = 'true' |
100 |
url = urljoin(self.url, path) |
|
101 |
url = urllib.parse.urljoin(self.url, path)
|
|
101 | 102 |
try: |
102 | 103 |
response = self.requests.get(url, data=params, cache_duration=300) |
103 | 104 |
except requests.RequestException as e: |
passerelle/apps/api_particulier/models.py | ||
---|---|---|
32 | 32 |
from django.contrib.postgres.fields import ArrayField |
33 | 33 |
from django.core.cache import cache |
34 | 34 |
from django.db import models |
35 |
from django.utils import six |
|
36 | 35 |
from django.utils.translation import ugettext_lazy as _ |
37 | 36 | |
38 | 37 |
from passerelle.base.models import BaseResource |
... | ... | |
96 | 95 |
data={ |
97 | 96 |
'code': 'connection-error', |
98 | 97 |
'platform': self.platform, |
99 |
'error': six.text_type(e),
|
|
98 |
'error': str(e),
|
|
100 | 99 |
}, |
101 | 100 |
) |
102 | 101 |
try: |
... | ... | |
110 | 109 |
data={ |
111 | 110 |
'code': 'non-json', |
112 | 111 |
'status_code': response.status_code, |
113 |
'exception': six.text_type(e),
|
|
112 |
'exception': str(e),
|
|
114 | 113 |
'platform': self.platform, |
115 | 114 |
'content': content, |
116 | 115 |
}, |
passerelle/apps/arpege_ecp/models.py | ||
---|---|---|
18 | 18 |
from urllib import parse as urlparse |
19 | 19 | |
20 | 20 |
from django.db import models |
21 |
from django.utils import six, timezone
|
|
21 |
from django.utils import timezone |
|
22 | 22 |
from django.utils.dateparse import parse_date, parse_time |
23 | 23 |
from django.utils.translation import ugettext_lazy as _ |
24 | 24 |
from requests import RequestException |
... | ... | |
67 | 67 |
if result.get('Data'): |
68 | 68 |
if 'AccessToken' not in result['Data']: |
69 | 69 |
raise APIError('Error on LoginParSubOIDC: missing Data/AccessToken') |
70 |
if not isinstance(result['Data']['AccessToken'], six.string_types):
|
|
70 |
if not isinstance(result['Data']['AccessToken'], str):
|
|
71 | 71 |
raise APIError('Error on LoginParSubOIDC: Data/AccessToken is not string') |
72 | 72 |
return result['Data']['AccessToken'] |
73 | 73 |
raise APIError('%s (%s)' % (result.get('LibErreur'), result.get('CodErreur'))) |
passerelle/apps/atos_genesys/models.py | ||
---|---|---|
21 | 21 |
import requests |
22 | 22 |
from django.contrib.postgres.fields import JSONField |
23 | 23 |
from django.db import models |
24 |
from django.utils import six |
|
25 | 24 |
from django.utils.translation import ugettext_lazy as _ |
26 | 25 | |
27 | 26 |
from passerelle.base.models import BaseResource, HTTPResource |
... | ... | |
73 | 72 |
response = self.requests.get(url, *args, **kwargs) |
74 | 73 |
response.raise_for_status() |
75 | 74 |
except requests.RequestException as e: |
76 |
raise APIError('HTTP request failed', data={'exception': six.text_type(e)})
|
|
75 |
raise APIError('HTTP request failed', data={'exception': str(e)})
|
|
77 | 76 |
try: |
78 | 77 |
root = ET.fromstring(response.content) |
79 | 78 |
except ET.ParseError as e: |
80 |
raise APIError('XML parsing failed', data={'exception': six.text_type(e)})
|
|
79 |
raise APIError('XML parsing failed', data={'exception': str(e)})
|
|
81 | 80 |
if root.tag != 'return': |
82 | 81 |
raise APIError('root XML node is not return', data={'content': response.text[:1024]}) |
83 | 82 |
return root, response |
passerelle/apps/atos_genesys/utils.py | ||
---|---|---|
3 | 3 | |
4 | 4 |
from django.core.cache import cache |
5 | 5 |
from django.db import transaction |
6 |
from django.utils import six |
|
7 | 6 | |
8 | 7 |
from passerelle.utils.jsonresponse import APIError |
9 | 8 | |
... | ... | |
43 | 42 |
if self.row: |
44 | 43 |
keys.append(str(self.row.pk)) |
45 | 44 |
for arg in args: |
46 |
if isinstance(arg, six.string_types):
|
|
45 |
if isinstance(arg, str):
|
|
47 | 46 |
keys.append(arg) |
48 | 47 |
else: |
49 | 48 |
keys.append(hash(arg)) |
passerelle/apps/base_adresse/models.py | ||
---|---|---|
1 | 1 |
import datetime |
2 | 2 |
import gzip |
3 |
import json |
|
4 |
from io import StringIO |
|
3 | 5 |
from urllib import parse as urlparse |
4 | 6 | |
5 | 7 |
from django.contrib.postgres.fields import JSONField |
6 | 8 |
from django.db import connection, models |
7 | 9 |
from django.db.models import Q |
8 |
from django.utils import six, timezone
|
|
10 |
from django.utils import timezone |
|
9 | 11 |
from django.utils.http import urlencode |
10 |
from django.utils.six import StringIO |
|
11 | 12 |
from django.utils.translation import ugettext_lazy as _ |
12 | 13 |
from requests import RequestException |
13 | 14 | |
14 | 15 |
from passerelle.address.models import AddressResource |
15 |
from passerelle.compat import json_loads |
|
16 | 16 |
from passerelle.utils.api import endpoint |
17 | 17 |
from passerelle.utils.conversion import simplify |
18 | 18 |
from passerelle.utils.jsonresponse import APIError |
... | ... | |
452 | 452 |
if ban_gz.status_code != 200: |
453 | 453 |
continue |
454 | 454 | |
455 |
if six.PY3: |
|
456 |
ban_file = StringIO(gzip.decompress(ban_gz.content).decode('utf-8')) |
|
457 |
else: |
|
458 |
ban_file = gzip.GzipFile(fileobj=StringIO(ban_gz.content)) |
|
455 |
ban_file = StringIO(gzip.decompress(ban_gz.content).decode('utf-8')) |
|
459 | 456 |
line = _not_found = object() |
460 | 457 |
for line in ban_file: |
461 |
street_info = json_loads(line)
|
|
458 |
street_info = json.loads(line)
|
|
462 | 459 |
if street_info['type'] != 'street': |
463 | 460 |
continue |
464 | 461 |
ban_id = street_info.get('id') |
... | ... | |
466 | 463 |
continue |
467 | 464 |
for key in ('postcode', 'name', 'city'): |
468 | 465 |
if isinstance(street_info[key], list): |
469 |
street_info[key] = six.text_type(street_info[key][0])
|
|
466 |
street_info[key] = str(street_info[key][0])
|
|
470 | 467 |
if not street_info['postcode'] or not street_info['postcode'].startswith(zipcodes): |
471 | 468 |
continue |
472 | 469 |
citycode = ban_id.split('_', 1)[0] |
... | ... | |
580 | 577 |
super().save(*args, **kwargs) |
581 | 578 | |
582 | 579 | |
583 |
@six.python_2_unicode_compatible |
|
584 | 580 |
class StreetModel(UnaccentNameMixin, models.Model): |
585 | 581 | |
586 | 582 |
ban_id = models.CharField(_('BAN Identifier'), max_length=32, blank=True) |
... | ... | |
601 | 597 |
return self.name |
602 | 598 | |
603 | 599 | |
604 |
@six.python_2_unicode_compatible |
|
605 | 600 |
class RegionModel(UnaccentNameMixin, models.Model): |
606 | 601 | |
607 | 602 |
name = models.CharField(_('Region name'), max_length=150) |
... | ... | |
627 | 622 |
return '%s %s' % (self.code, self.name) |
628 | 623 | |
629 | 624 | |
630 |
@six.python_2_unicode_compatible |
|
631 | 625 |
class DepartmentModel(UnaccentNameMixin, models.Model): |
632 | 626 | |
633 | 627 |
name = models.CharField(_('Department name'), max_length=100) |
... | ... | |
656 | 650 |
return '%s %s' % (self.code, self.name) |
657 | 651 | |
658 | 652 | |
659 |
@six.python_2_unicode_compatible |
|
660 | 653 |
class CityModel(UnaccentNameMixin, models.Model): |
661 | 654 | |
662 | 655 |
name = models.CharField(_('City name'), max_length=150) |
passerelle/apps/bdp/views.py | ||
---|---|---|
1 |
import json |
|
2 | ||
1 | 3 |
from django.http import Http404 |
2 | 4 |
from django.views.generic.base import View |
3 | 5 |
from django.views.generic.detail import DetailView, SingleObjectMixin |
4 | 6 | |
5 | 7 |
from passerelle import utils |
6 |
from passerelle.compat import json_loads |
|
7 | 8 | |
8 | 9 |
from .models import Bdp |
9 | 10 | |
... | ... | |
40 | 41 |
@utils.protected_api('can_access') |
41 | 42 |
@utils.to_json() |
42 | 43 |
def post(self, request, *args, **kwargs): |
43 |
data = json_loads(request.body) # JSON w.c.s. formdata
|
|
44 |
data = json.loads(request.body) # JSON w.c.s. formdata
|
|
44 | 45 |
date_de_naissance = data['fields'].get('date_de_naissance') |
45 | 46 |
# force 1973-04-18T00:00:00Z |
46 | 47 |
date_de_naissance = date_de_naissance[:10] + 'T00:00:00Z' |
passerelle/apps/choosit/models.py | ||
---|---|---|
3 | 3 | |
4 | 4 |
import requests |
5 | 5 |
from django.db import models |
6 |
from django.utils.six import string_types |
|
7 | 6 |
from django.utils.translation import ugettext_lazy as _ |
8 | 7 | |
9 | 8 |
from passerelle.sms.models import SMSResource |
... | ... | |
95 | 94 |
results.append('Choosit error: %s' % output['error']) |
96 | 95 |
else: |
97 | 96 |
results.append(output) |
98 |
if any(isinstance(result, string_types) for result in results):
|
|
97 |
if any(isinstance(result, str) for result in results): |
|
99 | 98 |
raise APIError('Choosit error: some destinations failed', data=list(zip(destinations, results))) |
100 | 99 |
# credit consumed is unknown |
passerelle/apps/cityweb/cityweb.py | ||
---|---|---|
18 | 18 |
import stat |
19 | 19 | |
20 | 20 |
from django.core.files.storage import default_storage |
21 |
from django.utils import six |
|
22 | 21 |
from django.utils.dateparse import parse_date |
23 | 22 |
from django.utils.encoding import force_bytes |
24 | 23 |
from lxml import etree |
... | ... | |
86 | 85 |
attr = getattr(self, subelt, None) |
87 | 86 |
if not attr: |
88 | 87 |
continue |
89 |
if isinstance(attr, six.string_types):
|
|
88 |
if isinstance(attr, str):
|
|
90 | 89 |
tag.append(self.make_element(subelt, attr, namespace=self.namespace)) |
91 | 90 |
else: |
92 | 91 |
xml = attr.xml |
passerelle/apps/cityweb/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import json |
|
17 | 18 |
import os |
18 | 19 | |
19 | 20 |
from django.core.files.storage import default_storage |
20 | 21 |
from django.utils.translation import ugettext_lazy as _ |
21 | 22 | |
22 | 23 |
from passerelle.base.models import BaseResource |
23 |
from passerelle.compat import json_loads |
|
24 | 24 |
from passerelle.utils.api import endpoint |
25 | 25 |
from passerelle.utils.jsonresponse import APIError |
26 | 26 | |
... | ... | |
47 | 47 | |
48 | 48 |
@endpoint(perm='can_access', methods=['post'], description=_('Create a demand')) |
49 | 49 |
def create(self, request, *args, **kwargs): |
50 |
payload = json_loads(request.body)
|
|
50 |
payload = json.loads(request.body)
|
|
51 | 51 |
# check mandatory keys |
52 | 52 |
for key in ('application_id', 'application_time', 'certificate_type'): |
53 | 53 |
if key not in payload: |
passerelle/apps/clicrdv/views.py | ||
---|---|---|
1 |
import json |
|
2 | ||
1 | 3 |
from django.views.generic.base import View |
2 | 4 |
from django.views.generic.detail import DetailView, SingleObjectMixin |
3 | 5 | |
4 | 6 |
from passerelle import utils |
5 | 7 |
from passerelle.apps.clicrdv.models import ClicRdv |
6 |
from passerelle.compat import json_loads |
|
7 | 8 | |
8 | 9 | |
9 | 10 |
class ClicRdvDetailView(DetailView): |
... | ... | |
87 | 88 |
def post(self, request, intervention_id=None, *args, **kwargs): |
88 | 89 |
if intervention_id is None: |
89 | 90 |
intervention_id = self.request.GET.get('intervention') |
90 |
data = json_loads(request.body)
|
|
91 |
data = json.loads(request.body)
|
|
91 | 92 |
return { |
92 | 93 |
'data': self.get_object().create_appointment( |
93 | 94 |
intervention_id, self.request.GET.get('websource'), data |
passerelle/apps/cmis/models.py | ||
---|---|---|
19 | 19 |
import functools |
20 | 20 |
import re |
21 | 21 |
from contextlib import contextmanager |
22 |
from io import BytesIO |
|
22 | 23 |
from urllib import error as urllib2 |
23 | 24 | |
24 | 25 |
import httplib2 |
... | ... | |
32 | 33 |
) |
33 | 34 |
from django.db import models |
34 | 35 |
from django.utils.functional import cached_property |
35 |
from django.utils.six import BytesIO |
|
36 | 36 |
from django.utils.translation import ugettext_lazy as _ |
37 | 37 | |
38 | 38 |
from passerelle.base.models import BaseResource |
passerelle/apps/csvdatasource/models.py | ||
---|---|---|
24 | 24 |
from collections import OrderedDict |
25 | 25 | |
26 | 26 |
import pytz |
27 |
import six |
|
28 | 27 |
from django.conf import settings |
29 | 28 |
from django.contrib.postgres.fields import JSONField |
30 | 29 |
from django.core.exceptions import ValidationError |
... | ... | |
230 | 229 | |
231 | 230 |
options = {} |
232 | 231 |
for k, v in self._dialect_options.items(): |
233 |
if isinstance(v, six.text_type):
|
|
232 |
if isinstance(v, str):
|
|
234 | 233 |
v = force_str(v.encode('ascii')) |
235 | 234 |
options[force_str(k.encode('ascii'))] = v |
236 | 235 |
passerelle/apps/family/loaders/concerto_fondettes.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
import csv |
18 | 18 |
import datetime |
19 |
import io |
|
19 | 20 |
from decimal import Decimal |
20 | 21 | |
21 | 22 |
from django.core.exceptions import ValidationError |
22 |
from django.utils import six |
|
23 | 23 |
from django.utils.encoding import force_text |
24 | 24 |
from django.utils.translation import ugettext_lazy as _ |
25 | 25 | |
... | ... | |
41 | 41 |
def load(self, archive): |
42 | 42 |
archive_files = archive.namelist() |
43 | 43 |
fd = archive.open('data_full.csv') |
44 |
if six.PY3: |
|
45 |
import io |
|
46 | ||
47 |
fd = io.TextIOWrapper(fd, 'iso-8859-15') |
|
48 |
csvfile = six.StringIO(fd.read()) |
|
44 |
fd = io.TextIOWrapper(fd, 'iso-8859-15') |
|
45 |
csvfile = io.StringIO(fd.read()) |
|
49 | 46 |
csvreader = csv.reader(csvfile, delimiter='\t') |
50 | 47 |
first_row = next(csvreader) |
51 | 48 |
csvfile.seek(0) |
passerelle/apps/family/loaders/concerto_orleans.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import csv |
18 |
import io |
|
18 | 19 |
import os |
19 | 20 |
from decimal import Decimal |
20 | 21 | |
21 | 22 |
from django.core.exceptions import ValidationError |
22 | 23 |
from django.core.files.storage import DefaultStorage |
23 |
from django.utils import six, timezone
|
|
24 |
from django.utils import timezone |
|
24 | 25 |
from django.utils.encoding import force_text |
25 | 26 |
from django.utils.translation import ugettext_lazy as _ |
26 | 27 | |
... | ... | |
123 | 124 | |
124 | 125 |
def csvread(self, filename): |
125 | 126 |
fd = self.archive.open(filename) |
126 |
if six.PY3: |
|
127 |
import io |
|
128 | ||
129 |
fd = io.TextIOWrapper(fd, 'iso-8859-15') |
|
127 |
fd = io.TextIOWrapper(fd, 'iso-8859-15') |
|
130 | 128 | |
131 | 129 |
reader = csv.reader(fd, Dialect) |
132 | 130 |
# pylint: disable=stop-iteration-return |
passerelle/apps/family/loaders/opus_fondettes.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
import csv |
18 | 18 |
import datetime |
19 |
import io |
|
19 | 20 |
from decimal import Decimal |
20 | 21 | |
21 | 22 |
from django.core.exceptions import ValidationError |
22 |
from django.utils import six |
|
23 | 23 |
from django.utils.encoding import force_text |
24 | 24 |
from django.utils.translation import ugettext_lazy as _ |
25 | 25 | |
... | ... | |
41 | 41 |
def load(self, archive): |
42 | 42 |
archive_files = archive.namelist() |
43 | 43 |
fd = archive.open('publipostage.csv') |
44 |
if six.PY3: |
|
45 |
import io |
|
46 | ||
47 |
fd = io.TextIOWrapper(fd, 'iso-8859-15') |
|
48 |
csvfile = six.StringIO(fd.read()) |
|
44 |
fd = io.TextIOWrapper(fd, 'iso-8859-15') |
|
45 |
csvfile = io.StringIO(fd.read()) |
|
49 | 46 |
csvreader = csv.reader(csvfile, delimiter=';') |
50 | 47 |
first_row = next(csvreader) |
51 | 48 |
csvfile.seek(0) |
passerelle/apps/family/models.py | ||
---|---|---|
16 | 16 |
# You should have received a copy of the GNU Affero General Public License |
17 | 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | |
19 |
import json |
|
19 | 20 |
import os |
20 | 21 |
import sys |
21 | 22 |
import zipfile |
... | ... | |
27 | 28 |
from django.core.files.storage import default_storage |
28 | 29 |
from django.db import models, transaction |
29 | 30 |
from django.http import Http404, HttpResponse |
30 |
from django.utils import six |
|
31 | 31 |
from django.utils.timezone import datetime, make_aware, now |
32 | 32 |
from django.utils.translation import ugettext_lazy as _ |
33 | 33 | |
34 | 34 |
from passerelle.base.models import BaseResource |
35 |
from passerelle.compat import json_loads |
|
36 | 35 |
from passerelle.utils.api import endpoint |
37 | 36 | |
38 | 37 |
SEXES = ( |
... | ... | |
212 | 211 |
adults = [] |
213 | 212 | |
214 | 213 |
for f in family_files: |
215 |
family_data = json_loads(archive.read(f))
|
|
214 |
family_data = json.loads(archive.read(f))
|
|
216 | 215 |
families.append(family_data['id']) |
217 | 216 |
address = family_data.get('address') or {} |
218 | 217 |
family_data.update(address) |
... | ... | |
403 | 402 |
name='regie', methods=['post'], perm='can_access', pattern=r'^invoice/(?P<invoice_id>\w+)/pay/$' |
404 | 403 |
) |
405 | 404 |
def pay_invoice(self, request, invoice_id, **kwargs): |
406 |
data = json_loads(request.body)
|
|
405 |
data = json.loads(request.body)
|
|
407 | 406 |
invoice = self.get_invoice(invoice_id) |
408 | 407 |
if not invoice: |
409 | 408 |
return {'data': False} |
... | ... | |
454 | 453 |
return self.external_id |
455 | 454 | |
456 | 455 | |
457 |
@six.python_2_unicode_compatible |
|
458 | 456 |
class Person(models.Model): |
459 | 457 |
family = models.ForeignKey('Family', on_delete=models.CASCADE) |
460 | 458 |
external_id = models.CharField(_('Person\'s external id'), max_length=32, db_index=True) |
passerelle/apps/gdc/views.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 | |
18 |
import json |
|
19 | ||
18 | 20 |
from django.utils.encoding import force_text |
19 | 21 |
from django.views.generic.base import View |
20 | 22 |
from django.views.generic.detail import DetailView, SingleObjectMixin |
21 | 23 | |
22 | 24 |
from passerelle import utils |
23 |
from passerelle.compat import json_loads |
|
24 | 25 |
from passerelle.utils.conversion import normalize |
25 | 26 | |
26 | 27 |
from .models import Gdc, phpserialize, phpserialize_loads |
... | ... | |
132 | 133 |
# <wsdl:part name='voie_id' type='xsd:string'></wsdl:part> |
133 | 134 |
# <wsdl:part name='voie_num' type='xsd:string'></wsdl:part> |
134 | 135 |
# </wsdl:message> |
135 |
data = json_loads(request.body)
|
|
136 |
data = json.loads(request.body)
|
|
136 | 137 |
voie_id = data['fields'].get('voie_raw') |
137 | 138 |
voie_str = data['fields'].get('voie') |
138 | 139 |
insee = data['fields'].get('commune_raw') |
passerelle/apps/gesbac/models.py | ||
---|---|---|
21 | 21 |
from django.contrib.postgres.fields import JSONField |
22 | 22 |
from django.db import IntegrityError, models, transaction |
23 | 23 |
from django.http import Http404 |
24 |
from django.utils import six |
|
25 |
from django.utils.encoding import force_bytes |
|
26 | 24 |
from django.utils.translation import ugettext_lazy as _ |
27 | 25 | |
28 | 26 |
from passerelle.base.models import BaseResource |
... | ... | |
239 | 237 |
if not csv_file.startswith(self.input_files_prefix): |
240 | 238 |
continue |
241 | 239 |
with client.open(csv_file, 'rb') as fd: |
242 |
if six.PY3: |
|
243 |
content = io.TextIOWrapper(fd, encoding=FILES_ENCODING) |
|
244 |
else: |
|
245 |
content = io.BytesIO(force_bytes(fd.read().decode(FILES_ENCODING))) |
|
240 |
content = io.TextIOWrapper(fd, encoding=FILES_ENCODING) |
|
246 | 241 |
for row in csv.reader(content, delimiter=CSV_DELIMITER): |
247 | 242 |
data.append(row) |
248 | 243 |
for card_data in data: |
... | ... | |
357 | 352 |
def send(self): |
358 | 353 |
with self.resource.outcoming_sftp.client() as client: |
359 | 354 |
with client.open(self.get_filename(), mode='wb') as fd: |
360 |
if six.PY3: |
|
361 |
fd = io.TextIOWrapper(fd, encoding=FILES_ENCODING) |
|
355 |
fd = io.TextIOWrapper(fd, encoding=FILES_ENCODING) |
|
362 | 356 |
writer = csv.writer(fd, delimiter=CSV_DELIMITER) |
363 | 357 |
for row in self.demand_data: |
364 |
# encode strings to ASCII |
|
365 |
if six.PY2: |
|
366 |
row = [ |
|
367 |
item.encode(FILES_ENCODING) if isinstance(item, six.string_types) else item |
|
368 |
for item in row |
|
369 |
] |
|
370 | 358 |
writer.writerow(row) |
371 | 359 |
self.status = 'sent' |
372 | 360 |
self.save() |
passerelle/apps/jsondatastore/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import json |
|
17 | 18 |
import uuid |
18 | 19 | |
19 | 20 |
from django.contrib.postgres.fields import JSONField |
... | ... | |
22 | 23 |
from django.utils.translation import ugettext_lazy as _ |
23 | 24 | |
24 | 25 |
from passerelle.base.models import BaseResource |
25 |
from passerelle.compat import json_loads |
|
26 | 26 |
from passerelle.utils.api import APIError, endpoint |
27 | 27 |
from passerelle.utils.conversion import simplify |
28 | 28 | |
... | ... | |
33 | 33 | |
34 | 34 |
def clean_json_data(data): |
35 | 35 |
try: |
36 |
payload = json_loads(data)
|
|
36 |
payload = json.loads(data)
|
|
37 | 37 |
if not isinstance(payload, dict): |
38 | 38 |
raise APIError('payload must be a dict') |
39 | 39 |
return payload |
passerelle/apps/mdel/models.py | ||
---|---|---|
15 | 15 |
# You should have received a copy of the GNU Affero General Public License |
16 | 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | |
18 |
import json |
|
18 | 19 |
import os |
19 | 20 | |
20 | 21 |
from django.db import models |
21 |
from django.utils import six |
|
22 | 22 |
from django.utils.translation import ugettext_lazy as _ |
23 | 23 | |
24 | 24 |
from passerelle.base.models import BaseResource |
25 |
from passerelle.compat import json_loads |
|
26 | 25 |
from passerelle.utils import SFTPField |
27 | 26 |
from passerelle.utils.api import endpoint |
28 | 27 |
from passerelle.utils.files import atomic_write |
... | ... | |
93 | 92 |
@endpoint(perm='can_access', methods=['post']) |
94 | 93 |
def create(self, request, *args, **kwargs): |
95 | 94 |
"""Create a demand""" |
96 |
formdata = json_loads(request.body)
|
|
95 |
formdata = json.loads(request.body)
|
|
97 | 96 |
extra = formdata.pop('extra', {}) |
98 | 97 |
fields = formdata.pop('fields', {}) |
99 | 98 | |
... | ... | |
193 | 192 |
self.get_response_files() |
194 | 193 | |
195 | 194 | |
196 |
@six.python_2_unicode_compatible |
|
197 | 195 |
class Demand(models.Model): |
198 | 196 |
created_at = models.DateTimeField(auto_now_add=True) |
199 | 197 |
updated_at = models.DateTimeField(auto_now=True) |
passerelle/apps/mdel_ddpacs/abstract.py | ||
---|---|---|
28 | 28 |
from django.db import IntegrityError, models, transaction |
29 | 29 |
from django.http import HttpResponse |
30 | 30 |
from django.urls import reverse |
31 |
from django.utils import functional, six
|
|
31 |
from django.utils import functional |
|
32 | 32 |
from django.utils.translation import ugettext_lazy as _ |
33 | 33 | |
34 | 34 |
from passerelle.base.models import BaseResource, SkipJob |
... | ... | |
214 | 214 |
return |
215 | 215 | |
216 | 216 | |
217 |
@six.python_2_unicode_compatible |
|
218 | 217 |
class Demand(models.Model): |
219 | 218 |
STATUS_PENDING = 'pending' |
220 | 219 |
STATUS_PUSHED = 'pushed' |
passerelle/apps/mdel_ddpacs/models.py | ||
---|---|---|
19 | 19 | |
20 | 20 |
import xmlschema |
21 | 21 |
from django.db import models |
22 |
from django.utils import six |
|
23 | 22 |
from django.utils.translation import ugettext_lazy as _ |
24 | 23 | |
25 | 24 |
from passerelle.utils.api import endpoint |
... | ... | |
117 | 116 |
else: |
118 | 117 |
del d['filiationInconnu'] |
119 | 118 |
# convert codeNationalite to array of strings |
120 |
if isinstance(d.get('codeNationalite'), six.text_type):
|
|
119 |
if isinstance(d.get('codeNationalite'), str):
|
|
121 | 120 |
d['codeNationalite'] = [d['codeNationalite']] |
122 | 121 |
for key in d: |
123 | 122 |
if key in ('anneeNaissance', 'jourNaissance', 'moisNaissance'): |
passerelle/apps/okina/models.py | ||
---|---|---|
22 | 22 |
from django.utils.translation import ugettext_lazy as _ |
23 | 23 | |
24 | 24 |
from passerelle.base.models import BaseResource |
25 |
from passerelle.compat import json_loads |
|
26 | 25 |
from passerelle.utils.api import endpoint |
27 | 26 |
from passerelle.utils.jsonresponse import APIError |
28 | 27 | |
... | ... | |
245 | 244 |
@endpoint(name='subscriber', methods=['post'], perm='can_access') |
246 | 245 |
def create_subscriber(self, request): |
247 | 246 |
try: |
248 |
payload = json_loads(request.body)
|
|
247 |
payload = json.loads(request.body)
|
|
249 | 248 |
except ValueError: |
250 | 249 |
raise APIError('payload must be a JSON object', http_status=400) |
251 | 250 |
if not isinstance(payload, dict): |
... | ... | |
261 | 260 |
qrcode = self.request('subscribers/%s/qrcode' % subscriber_id, result_is_json=False) |
262 | 261 |
content_type = qrcode.headers.get('Content-Type') |
263 | 262 |
if not (content_type and content_type.startswith('image/')): |
264 |
response = json_loads(qrcode.content)
|
|
263 |
response = json.loads(qrcode.content)
|
|
265 | 264 |
raise APIError(response['message'], http_status=response['status'], err=response['code']) |
266 | 265 |
return HttpResponse(qrcode.content, content_type=content_type) |
267 | 266 | |
268 | 267 |
@endpoint(name='subscription', methods=['post'], perm='can_access') |
269 | 268 |
def create_subscription(self, request): |
270 | 269 |
try: |
271 |
payload = json_loads(request.body)
|
|
270 |
payload = json.loads(request.body)
|
|
272 | 271 |
except ValueError: |
273 | 272 |
raise APIError('payload must be a JSON object', http_status=400) |
274 | 273 |
if not isinstance(payload, dict): |
passerelle/apps/opengis/models.py | ||
---|---|---|
19 | 19 |
import xml.etree.ElementTree as ET |
20 | 20 | |
21 | 21 |
import pyproj |
22 |
import six |
|
23 | 22 |
from django.contrib.postgres.fields import JSONField |
24 | 23 |
from django.core.cache import cache |
25 | 24 |
from django.db import models, transaction |
... | ... | |
396 | 395 |
for attribute, properties in self.attributes_mapping: |
397 | 396 |
for field in properties: |
398 | 397 |
if closest_feature['properties'].get(field): |
399 |
result['address'][attribute] = six.text_type(closest_feature['properties'][field])
|
|
398 |
result['address'][attribute] = str(closest_feature['properties'][field])
|
|
400 | 399 |
break |
401 | 400 |
return result |
402 | 401 |
raise APIError('Unable to geocode') |
passerelle/apps/plone_restapi/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import json |
|
17 | 18 |
from urllib.parse import parse_qsl, urlsplit, urlunsplit |
18 | 19 | |
19 | 20 |
from django.core.cache import cache |
... | ... | |
24 | 25 |
from requests import RequestException |
25 | 26 | |
26 | 27 |
from passerelle.base.models import BaseQuery, BaseResource, HTTPResource |
27 |
from passerelle.compat import json_loads |
|
28 | 28 |
from passerelle.utils.api import endpoint |
29 | 29 |
from passerelle.utils.http_authenticators import HttpBearerAuth |
30 | 30 |
from passerelle.utils.json import unflatten |
... | ... | |
303 | 303 |
) |
304 | 304 |
def create(self, request, uri, publish=False): |
305 | 305 |
try: |
306 |
post_data = json_loads(request.body)
|
|
306 |
post_data = json.loads(request.body)
|
|
307 | 307 |
except ValueError as e: |
308 | 308 |
raise ParameterTypeError(str(e)) |
309 | 309 |
post_data = unflatten(post_data) |
... | ... | |
330 | 330 |
) |
331 | 331 |
def update(self, request, uid, uri=''): |
332 | 332 |
try: |
333 |
post_data = json_loads(request.body)
|
|
333 |
post_data = json.loads(request.body)
|
|
334 | 334 |
except ValueError as e: |
335 | 335 |
raise ParameterTypeError(str(e)) |
336 | 336 |
post_data = unflatten(post_data) |
passerelle/apps/solis/models.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
import base64 |
18 | 18 |
import copy |
19 |
import json |
|
19 | 20 | |
20 | 21 |
from django.db import models |
21 | 22 |
from django.template.loader import get_template |
... | ... | |
24 | 25 |
from django.utils.translation import ugettext_lazy as _ |
25 | 26 | |
26 | 27 |
from passerelle.base.models import BaseResource |
27 |
from passerelle.compat import json_loads |
|
28 | 28 |
from passerelle.utils.api import endpoint |
29 | 29 |
from passerelle.utils.conversion import simplify, to_pdf |
30 | 30 |
from passerelle.utils.jsonresponse import APIError |
... | ... | |
276 | 276 |
) |
277 | 277 |
def apa_link(self, request): |
278 | 278 |
try: |
279 |
data = json_loads(request.body)
|
|
279 |
data = json.loads(request.body)
|
|
280 | 280 |
except ValueError: |
281 | 281 |
raise APIError('payload is not a JSON dict') |
282 | 282 |
if not isinstance(data, dict): |
... | ... | |
302 | 302 |
) |
303 | 303 |
def apa_unlink(self, request): |
304 | 304 |
try: |
305 |
data = json_loads(request.body)
|
|
305 |
data = json.loads(request.body)
|
|
306 | 306 |
except ValueError: |
307 | 307 |
raise APIError('payload is not a JSON dict') |
308 | 308 |
if not isinstance(data, dict): |
... | ... | |
411 | 411 |
) |
412 | 412 |
def apa_integration(self, request): |
413 | 413 |
try: |
414 |
payload = json_loads(request.body)
|
|
414 |
payload = json.loads(request.body)
|
|
415 | 415 |
except ValueError: |
416 | 416 |
raise APIError('payload is not a JSON object', http_status=400) |
417 | 417 |
if not isinstance(payload, dict): |
... | ... | |
566 | 566 |
) |
567 | 567 |
def rsa_link(self, request): |
568 | 568 |
try: |
569 |
data = json_loads(request.body)
|
|
569 |
data = json.loads(request.body)
|
|
570 | 570 |
except ValueError: |
571 | 571 |
raise APIError('payload is not a JSON dict') |
572 | 572 |
if not isinstance(data, dict): |
... | ... | |
593 | 593 |
) |
594 | 594 |
def rsa_unlink(self, request): |
595 | 595 |
try: |
596 |
data = json_loads(request.body)
|
|
596 |
data = json.loads(request.body)
|
|
597 | 597 |
except ValueError: |
598 | 598 |
raise APIError('payload is not a JSON dict') |
599 | 599 |
if not isinstance(data, dict): |
passerelle/apps/sp_fr/models.py | ||
---|---|---|
28 | 28 |
from django.db import models, transaction |
29 | 29 |
from django.template import engines |
30 | 30 |
from django.urls import reverse |
31 |
from django.utils import six |
|
32 | 31 |
from django.utils.translation import ugettext |
33 | 32 |
from django.utils.translation import ugettext_lazy as _ |
34 | 33 |
from lxml import etree as ET |
... | ... | |
77 | 76 |
'''Simplify XML node tag names because XSD from DGME are garbage''' |
78 | 77 |
if not s: |
79 | 78 |
return '' |
80 |
if not isinstance(s, six.text_type):
|
|
81 |
s = six.text_type(s, 'utf-8', 'ignore')
|
|
79 |
if not isinstance(s, str):
|
|
80 |
s = str(s, 'utf-8', 'ignore')
|
|
82 | 81 |
s = normalize(s) |
83 | 82 |
s = re.sub(r'[^\w\s\'-_]', '', s) |
84 | 83 |
s = s.replace('-', '_') |
... | ... | |
536 | 535 |
return {} |
537 | 536 | |
538 | 537 | |
539 |
@six.python_2_unicode_compatible |
|
540 | 538 |
class Mapping(models.Model): |
541 | 539 |
resource = models.ForeignKey( |
542 | 540 |
Resource, verbose_name=_('Resource'), related_name='mappings', on_delete=models.CASCADE |
passerelle/apps/sp_fr/xsd.py | ||
---|---|---|
17 | 17 |
import datetime |
18 | 18 | |
19 | 19 |
import isodate |
20 |
from django.utils import six |
|
21 | 20 |
from lxml import etree as ET |
22 | 21 |
from zeep.utils import qname_attr |
23 | 22 | |
... | ... | |
57 | 56 | |
58 | 57 |
TYPE_CASTER = { |
59 | 58 |
BOOLEAN: parse_bool, |
60 |
STRING: six.text_type,
|
|
59 |
STRING: str,
|
|
61 | 60 |
DATE: parse_date, |
62 | 61 |
INT: int, |
63 | 62 |
INTEGER: int, |
... | ... | |
245 | 244 |
def qname_display(self, name): |
246 | 245 |
if name.namespace in self.reverse_nsmap: |
247 | 246 |
name = '%s:%s' % (self.reverse_nsmap[name.namespace], name.localname) |
248 |
return six.text_type(name)
|
|
247 |
return str(name)
|
|
249 | 248 | |
250 | 249 |
def paths(self): |
251 | 250 |
roots = sorted(self.elements.keys()) |
... | ... | |
292 | 291 |
yield path |
293 | 292 | |
294 | 293 | |
295 |
@six.python_2_unicode_compatible |
|
296 | 294 |
class Path: |
297 | 295 |
def __init__(self, path, xsd_type): |
298 | 296 |
assert path |
... | ... | |
301 | 299 |
try: |
302 | 300 |
self.caster = TYPE_CASTER[xsd_type] |
303 | 301 |
except KeyError: |
304 |
raise KeyError(six.text_type(xsd_type))
|
|
302 |
raise KeyError(str(xsd_type))
|
|
305 | 303 | |
306 | 304 |
def resolve(self, root): |
307 | 305 |
def helper(node, path): |
... | ... | |
319 | 317 |
return self.caster(child.text) |
320 | 318 | |
321 | 319 |
def __str__(self): |
322 |
return '.'.join(six.text_type(name) for name in self.path) |
|
320 |
return '.'.join(str(name) for name in self.path) |
passerelle/base/models.py | ||
---|---|---|
26 | 26 |
from django.forms.widgets import ClearableFileInput |
27 | 27 |
from django.test import override_settings |
28 | 28 |
from django.urls import reverse |
29 |
from django.utils import six, timezone
|
|
29 |
from django.utils import timezone |
|
30 | 30 |
from django.utils.encoding import force_text |
31 | 31 |
from django.utils.log import AdminEmailHandler |
32 | 32 |
from django.utils.text import slugify |
... | ... | |
71 | 71 |
) |
72 | 72 | |
73 | 73 | |
74 |
@six.python_2_unicode_compatible |
|
75 | 74 |
class ApiUser(models.Model): |
76 | 75 |
username = models.CharField(max_length=128, verbose_name=_('Username'), unique=True) |
77 | 76 |
fullname = models.CharField(max_length=50, verbose_name=_('Full Name')) |
... | ... | |
135 | 134 |
return self.filter(Q(users=None) | Q(users=apiuser)) |
136 | 135 | |
137 | 136 | |
138 |
@six.python_2_unicode_compatible |
|
139 | 137 |
class BaseResource(models.Model): |
140 | 138 |
title = models.CharField(max_length=50, verbose_name=_('Title')) |
141 | 139 |
slug = models.SlugField(verbose_name=_('Identifier'), unique=True) |
... | ... | |
653 | 651 |
).exists() |
654 | 652 | |
655 | 653 | |
656 |
@six.python_2_unicode_compatible |
|
657 | 654 |
class AccessRight(models.Model): |
658 | 655 |
codename = models.CharField(max_length=100, verbose_name='codename') |
659 | 656 |
resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) |
... | ... | |
798 | 795 |
def set_after_timestamp(self, value): |
799 | 796 |
if isinstance(value, datetime.datetime): |
800 | 797 |
self.after_timestamp = value |
801 |
elif isinstance(value, six.integer_types + (float,)):
|
|
798 |
elif isinstance(value, (float, int)):
|
|
802 | 799 |
self.after_timestamp = timezone.now() + datetime.timedelta(seconds=value) |
803 | 800 |
elif isinstance(value, datetime.timedelta): |
804 | 801 |
self.after_timestamp = timezone.now() + value |
... | ... | |
849 | 846 |
self.save() |
850 | 847 | |
851 | 848 | |
852 |
@six.python_2_unicode_compatible |
|
853 | 849 |
class ResourceLog(models.Model): |
854 | 850 |
timestamp = models.DateTimeField(auto_now_add=True) |
855 | 851 |
appname = models.CharField(max_length=128, verbose_name='appname', null=True) |
... | ... | |
1063 | 1059 |
abstract = True |
1064 | 1060 | |
1065 | 1061 | |
1066 |
@six.python_2_unicode_compatible |
|
1067 | 1062 |
class BaseQuery(models.Model): |
1068 | 1063 |
"""Base for building custom queries. |
1069 | 1064 |
passerelle/base/signature.py | ||
---|---|---|
5 | 5 |
import random |
6 | 6 |
from urllib import parse as urlparse |
7 | 7 | |
8 |
from django.utils import six |
|
9 | 8 |
from django.utils.encoding import smart_bytes |
10 | 9 |
from django.utils.http import quote, urlencode |
11 | 10 | |
... | ... | |
38 | 37 | |
39 | 38 |
def sign_string(s, key, algo='sha256'): |
40 | 39 |
digestmod = getattr(hashlib, algo) |
41 |
if isinstance(key, six.text_type):
|
|
40 |
if isinstance(key, str):
|
|
42 | 41 |
key = key.encode('utf-8') |
43 | 42 |
hash = hmac.HMAC(smart_bytes(key), digestmod=digestmod, msg=smart_bytes(s)) |
44 | 43 |
return hash.digest() |
... | ... | |
74 | 73 |
if len(signature2) != len(signature): |
75 | 74 |
return False |
76 | 75 |
res = 0 |
77 |
if six.PY3: |
|
78 |
for a, b in zip(signature, signature2): |
|
79 |
res |= a ^ b |
|
80 |
else: |
|
81 |
for a, b in zip(signature, signature2): |
|
82 |
res |= ord(a) ^ ord(b) |
|
76 |
for a, b in zip(signature, signature2): |
|
77 |
res |= a ^ b |
|
83 | 78 |
return res == 0 |
passerelle/base/views.py | ||
---|---|---|
29 | 29 |
from django.utils.translation import ugettext_lazy as _ |
30 | 30 |
from django.views.generic import CreateView, DeleteView, DetailView, FormView, ListView, UpdateView, View |
31 | 31 | |
32 |
from passerelle.compat import json_loads |
|
33 | ||
34 | 32 |
from ..utils import ImportSiteError, export_site, get_trusted_services, import_site |
35 | 33 |
from ..views import GenericConnectorMixin |
36 | 34 |
from .forms import AccessRightForm, ApiUserForm, AvailabilityParametersForm, ImportSiteForm |
... | ... | |
332 | 330 | |
333 | 331 |
def form_valid(self, form): |
334 | 332 |
try: |
335 |
site_json = json_loads(self.request.FILES['site_json'].read())
|
|
333 |
site_json = json.loads(self.request.FILES['site_json'].read())
|
|
336 | 334 |
except ValueError: |
337 | 335 |
form.add_error('site_json', _('File is not in the expected JSON format.')) |
338 | 336 |
return self.form_invalid(form) |
passerelle/compat.py | ||
---|---|---|
1 |
import json |
|
2 | ||
3 |
from django.utils import six |
|
4 |
from django.utils.encoding import force_text |
|
5 | ||
6 | ||
7 |
def json_loads(value): |
|
8 |
if six.PY3: |
|
9 |
value = force_text(value) |
|
10 |
return json.loads(value) |
passerelle/contrib/dpark/models.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
import base64 |
20 | 20 |
import datetime |
21 |
import json |
|
21 | 22 | |
22 | 23 |
import pytz |
23 | 24 |
from django.conf import settings |
24 | 25 |
from django.core.cache import cache |
25 | 26 |
from django.db import models |
26 |
from django.utils import six, timezone
|
|
27 |
from django.utils import timezone |
|
27 | 28 |
from django.utils.translation import ugettext_lazy as _ |
28 | 29 |
from zeep.exceptions import Fault as WebFault |
29 | 30 |
from zeep.helpers import serialize_object |
30 | 31 | |
31 | 32 |
from passerelle.base.models import BaseResource |
32 |
from passerelle.compat import json_loads |
|
33 | 33 |
from passerelle.utils.api import endpoint |
34 | 34 |
from passerelle.utils.conversion import to_pdf |
35 | 35 |
from passerelle.utils.jsonresponse import APIError |
... | ... | |
201 | 201 |
return instance.soap_client() |
202 | 202 | |
203 | 203 | |
204 |
@six.python_2_unicode_compatible |
|
205 | 204 |
class DPark(BaseResource): |
206 | 205 |
log_requests_errors = False |
207 | 206 | |
... | ... | |
290 | 289 | |
291 | 290 |
@endpoint(perm='can_access', methods=['post'], description=_('Register a subscription application')) |
292 | 291 |
def register(self, request, *args, **kwargs): |
293 |
data = json_loads(request.body)
|
|
292 |
data = json.loads(request.body)
|
|
294 | 293 |
is_erroneous( |
295 | 294 |
data, |
296 | 295 |
( |
... | ... | |
348 | 347 | |
349 | 348 |
@endpoint(perm='can_access', methods=['post'], description=_('Link user to a subscription')) |
350 | 349 |
def link(self, request, *args, **kwargs): |
351 |
data = json_loads(request.body)
|
|
350 |
data = json.loads(request.body)
|
|
352 | 351 |
if 'nameid' not in data: |
353 | 352 |
raise WrongParameter(['nameid'], []) |
354 | 353 |
result = self.check_file_exists(data) |
... | ... | |
370 | 369 | |
371 | 370 |
@endpoint(perm='can_access', methods=['post'], description=_('Unlink user to subscription')) |
372 | 371 |
def unlink(self, request, *args, **kwargs): |
373 |
data = json_loads(request.body)
|
|
372 |
data = json.loads(request.body)
|
|
374 | 373 |
is_erroneous(data, ('nameid',)) |
375 | 374 |
pairings = Pairing.objects.filter(**data) |
376 | 375 |
if pairings.exists() is False: |
... | ... | |
479 | 478 | |
480 | 479 |
@endpoint(name='notify-payment', perm='can_access', methods=['post'], description=_('Notify a payment')) |
481 | 480 |
def payment_notification(self, request, *args, **kwargs): |
482 |
data = json_loads(request.body)
|
|
481 |
data = json.loads(request.body)
|
|
483 | 482 |
is_erroneous( |
484 | 483 |
data, |
485 | 484 |
( |
... | ... | |
519 | 518 |
) |
520 | 519 |
def send_files(self, request, *args, **kwargs): |
521 | 520 |
try: |
522 |
data = json_loads(request.body)
|
|
521 |
data = json.loads(request.body)
|
|
523 | 522 |
except ValueError as exc: |
524 | 523 |
raise APIError(str(exc), http_status=400) |
525 | 524 | |
... | ... | |
568 | 567 |
return {'data': True} |
569 | 568 | |
570 | 569 | |
571 |
@six.python_2_unicode_compatible |
|
572 | 570 |
class Pairing(models.Model): |
573 | 571 |
INFO_CACHE_DURATION = 5 * 60 |
574 | 572 |
PAYMENT_INFO_CACHE_DURATION = 20 * 60 |
passerelle/contrib/gdema/models.py | ||
---|---|---|
20 | 20 | |
21 | 21 |
from django.db import models |
22 | 22 |
from django.utils.dateparse import parse_date, parse_datetime |
23 |
from django.utils.six import string_types |
|
24 | 23 |
from django.utils.timezone import get_fixed_timezone, is_naive, make_aware, utc |
25 | 24 |
from django.utils.translation import ugettext_lazy as _ |
26 | 25 | |
27 | 26 |
from passerelle.base.models import BaseResource |
28 |
from passerelle.compat import json_loads |
|
29 | 27 |
from passerelle.utils.api import endpoint |
30 | 28 |
from passerelle.utils.jsonresponse import APIError |
31 | 29 | |
... | ... | |
68 | 66 | |
69 | 67 |
def normalize(value): |
70 | 68 |
'''convert /Date()/ to datetime, integers to strings''' |
71 |
if isinstance(value, string_types):
|
|
69 |
if isinstance(value, str): |
|
72 | 70 |
datetime = parse_gdema_datetime(value) |
73 | 71 |
if datetime: |
74 | 72 |
return datetime |
... | ... | |
253 | 251 |
) |
254 | 252 |
def create_request(self, request): |
255 | 253 |
try: |
256 |
payload = json_loads(request.body)
|
|
254 |
payload = json.loads(request.body)
|
|
257 | 255 |
except ValueError: |
258 | 256 |
raise APIError('payload must be a JSON object', http_status=400) |
259 | 257 |
if not isinstance(payload, dict): |
passerelle/contrib/grandlyon_streetsections/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import json |
|
17 | 18 |
import re |
18 | 19 | |
19 | 20 |
from django.db import models |
... | ... | |
22 | 23 |
from django.utils.translation import ugettext_lazy as _ |
23 | 24 | |
24 | 25 |
from passerelle.base.models import BaseResource |
25 |
from passerelle.compat import json_loads |
|
26 | 26 |
from passerelle.utils.api import endpoint |
27 | 27 | |
28 | 28 |
COMMUNE_EXTRA_MAPPING = {'Vaulx-en-Velin': 'VAULX'} |
... | ... | |
123 | 123 |
sections = self.requests.get( |
124 | 124 |
'https://download.data.grandlyon.com/ws/grandlyon/adr_voie_lieu.adraxevoie/all.json?maxfeatures=1000000' |
125 | 125 |
).content |
126 |
for value in json_loads(sections).get('values'):
|
|
126 |
for value in json.loads(sections).get('values'):
|
|
127 | 127 |
if not value.get('codefuv') or not value.get('codetroncon'): |
128 | 128 |
continue |
129 | 129 |
section, dummy = StreetSection.objects.get_or_create( |
passerelle/contrib/greco/models.py | ||
---|---|---|
14 | 14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 | |
16 | 16 |
import base64 |
17 |
import json |
|
17 | 18 |
import re |
18 | 19 |
from email.mime.base import MIMEBase |
19 | 20 |
from email.mime.multipart import MIMEMultipart |
... | ... | |
28 | 29 |
from suds.transport.http import HttpAuthenticated |
29 | 30 | |
30 | 31 |
from passerelle.base.models import BaseResource |
31 |
from passerelle.compat import json_loads |
|
32 | 32 |
from passerelle.soap import sudsobject_to_dict |
33 | 33 |
from passerelle.utils.api import APIError, endpoint |
34 | 34 | |
... | ... | |
258 | 258 |
def create(self, request): |
259 | 259 |
# get creation fields from payload |
260 | 260 |
try: |
261 |
formdata = FormData(json_loads(request.body), CREATION_SCHEMA)
|
|
261 |
formdata = FormData(json.loads(request.body), CREATION_SCHEMA)
|
|
262 | 262 |
except ValueError as e: |
263 | 263 |
raise ParameterTypeError(str(e)) |
264 | 264 |
# create suds object from formdata |
... | ... | |
329 | 329 |
) |
330 | 330 |
def add_information(self, request, iddemande=None, idgreco=None, information=None): |
331 | 331 |
if request.body: |
332 |
payload = json_loads(request.body)
|
|
332 |
payload = json.loads(request.body)
|
|
333 | 333 |
if not isinstance(payload, dict): |
334 | 334 |
raise ParameterTypeError('payload must be a dict') |
335 | 335 |
idgreco = payload.get('idgreco') or idgreco |
... | ... | |
356 | 356 |
) |
357 | 357 |
def update(self, request, iddemande=None, idgreco=None, comment=None): |
358 | 358 |
if request.body: |
359 |
payload = json_loads(request.body)
|
|
359 |
payload = json.loads(request.body)
|
|
360 | 360 |
if not isinstance(payload, dict): |
361 | 361 |
raise ParameterTypeError('payload must be a dict') |
362 | 362 |
idgreco = payload.get('idgreco') or idgreco |
... | ... | |
383 | 383 |
display_order=7, |
384 | 384 |
) |
385 | 385 |
def add_confirmation(self, request): |
386 |
payload = json_loads(request.body)
|
|
386 |
payload = json.loads(request.body)
|
|
387 | 387 |
if not isinstance(payload, dict): |
388 | 388 |
raise ParameterTypeError('payload must be a dict') |
389 | 389 |
idgreco = payload.get('idgreco') |
passerelle/contrib/grenoble_gru/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import json |
|
17 | 18 |
import re |
18 | 19 |
from urllib import parse as urlparse |
19 | 20 | |
... | ... | |
26 | 27 |
from lxml import etree |
27 | 28 | |
28 | 29 |
from passerelle.base.models import BaseResource |
29 |
from passerelle.compat import json_loads |
|
30 | 30 |
from passerelle.utils.api import endpoint |
31 | 31 |
from passerelle.utils.jsonresponse import APIError |
32 | 32 |
from passerelle.views import WrongParameter |
... | ... | |
237 | 237 |
@endpoint(name='create-demand', perm='can_access', methods=['post'], description=_('Create a demand')) |
238 | 238 |
def create_demand(self, request, *args, **kwargs): |
239 | 239 |
try: |
240 |
payload = self.build_gru_params(json_loads(request.body))
|
|
240 |
payload = self.build_gru_params(json.loads(request.body))
|
|
241 | 241 |
except (KeyError, ValueError) as e: |
242 | 242 |
raise APIError(e) |
243 | 243 |
response = self.request('ws_creation_demande.php', payload) |
... | ... | |
253 | 253 |
pattern=r'(?P<demand_id>[\w-]+)/add-attachment/$', |
254 | 254 |
) |
255 | 255 |
def add_attachment_to_demand(self, request, demand_id, **kwargs): |
256 |
data = json_loads(request.body)
|
|
256 |
data = json.loads(request.body)
|
|
257 | 257 |
if 'file' not in data: |
258 | 258 |
raise WrongParameter(['file'], []) |
259 | 259 |
file_data = data['file'] |
passerelle/contrib/lille_urban_card/models.py | ||
---|---|---|
16 | 16 |
# You should have received a copy of the GNU Affero General Public License |
17 | 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | |
19 |
import json |
|
19 | 20 |
import re |
20 | 21 |
from urllib.parse import urljoin |
21 | 22 | |
... | ... | |
23 | 24 |
from django.utils.translation import ugettext_lazy as _ |
24 | 25 | |
25 | 26 |
from passerelle.base.models import BaseResource |
26 |
from passerelle.compat import json_loads |
|
27 | 27 |
from passerelle.utils.api import endpoint |
28 | 28 |
from passerelle.utils.http_authenticators import HttpBearerAuth |
29 | 29 |
from passerelle.utils.jsonresponse import APIError |
... | ... | |
134 | 134 | |
135 | 135 |
@endpoint(perm='can_access', description=_('Card Request'), methods=['post']) |
136 | 136 |
def card_request(self, request, *args, **kwargs): |
137 |
data = json_loads(request.body)
|
|
137 |
data = json.loads(request.body)
|
|
138 | 138 |
self.preprocess_card_request_data(data) |
139 | 139 |
self.preprocess_contact_data(data) |
140 | 140 |
self.preprocess_service_data(data) |
... | ... | |
169 | 169 | |
170 | 170 |
@endpoint(perm='can_access', description=_('Add new subscriptions'), methods=['post']) |
171 | 171 |
def add_subscriptions(self, request, *args, **kwargs): |
172 |
data = json_loads(request.body)
|
|
172 |
data = json.loads(request.body)
|
|
173 | 173 |
self.preprocess_card_request_data(data) |
174 | 174 |
self.preprocess_contact_data(data) |
175 | 175 |
self.preprocess_service_data(data) |
... | ... | |
193 | 193 | |
194 | 194 |
@endpoint(perm='can_access', description=_('Code Change'), methods=['post']) |
195 | 195 |
def code_change(self, request, *args, **kwargs): |
196 |
data = json_loads(request.body)
|
|
196 |
data = json.loads(request.body)
|
|
197 | 197 |
response = self.requests.post( |
198 | 198 |
urljoin(self.base_url, '/clu/ws/modifierCodeSecret'), |
199 | 199 |
json=data, |
... | ... | |
211 | 211 | |
212 | 212 |
@endpoint(perm='can_access', description=_('Code check'), methods=['post']) |
213 | 213 |
def code_check(self, request, *args, **kwargs): |
214 |
data = json_loads(request.body)
|
|
214 |
data = json.loads(request.body)
|
|
215 | 215 |
if 'password' in data: |
216 | 216 |
data['code_secret'] = data.pop('password') |
217 | 217 |
response = self.requests.get( |
... | ... | |
262 | 262 | |
263 | 263 |
@endpoint(perm='can_access', description=_('Card Revocation'), methods=['post']) |
264 | 264 |
def card_revocation(self, request, *args, **kwargs): |
265 |
data = json_loads(request.body)
|
|
265 |
data = json.loads(request.body)
|
|
266 | 266 |
self.preprocess_contact_data(data) |
267 | 267 |
response = self.requests.post( |
268 | 268 |
urljoin(self.base_url, '/clu/ws/revoquerCarte'), json=data, auth=HttpBearerAuth(self.get_token()) |
... | ... | |
279 | 279 | |
280 | 280 |
@endpoint(perm='can_access', description=_('Subscription Revocation'), methods=['post']) |
281 | 281 |
def subscription_revocation(self, request, *args, **kwargs): |
282 |
data = json_loads(request.body)
|
|
282 |
data = json.loads(request.body)
|
|
283 | 283 |
self.preprocess_contact_data(data) |
284 | 284 |
self.preprocess_service_data(data) |
285 | 285 |
response = self.requests.post( |
... | ... | |
299 | 299 | |
300 | 300 |
@endpoint(perm='can_access', description=_('Subscription Renewal'), methods=['post']) |
301 | 301 |
def subscription_renewal(self, request, *args, **kwargs): |
302 |
data = json_loads(request.body)
|
|
302 |
data = json.loads(request.body)
|
|
303 | 303 |
self.preprocess_contact_data(data) |
304 | 304 |
response = self.requests.post( |
305 | 305 |
urljoin(self.base_url, '/clu/ws/renouvelerAbonnements'), |
passerelle/contrib/mdph13/models.py | ||
---|---|---|
22 | 22 | |
23 | 23 |
import requests |
24 | 24 |
from django.db import models, transaction |
25 |
from django.utils import six |
|
26 | 25 |
from django.utils.translation import ugettext_lazy as _ |
27 | 26 | |
28 | 27 |
from passerelle.base.models import BaseResource, HTTPResource |
... | ... | |
135 | 134 |
'traitée et expédiée': 'historique', |
136 | 135 |
'traitée non expédiée': 'historique', |
137 | 136 |
} |
138 |
if not all(isinstance(demande.get('typologie'), six.text_type) for demande in demandes):
|
|
137 |
if not all(isinstance(demande.get('typologie'), str) for demande in demandes):
|
|
139 | 138 |
raise APIError('typologie-must-be-a-string', data=content) |
140 | 139 |
if not all(demande['typologie'].lower() in typologies for demande in demandes): |
141 | 140 |
unknowns = set([demande['typologie'].lower() for demande in demandes]) - set( |
... | ... | |
158 | 157 | |
159 | 158 |
def check(value, path): |
160 | 159 |
if path[-1].startswith('date_'): |
161 |
if isinstance(value, six.text_type) and not self.DATE_RE.match(value):
|
|
160 |
if isinstance(value, str) and not self.DATE_RE.match(value):
|
|
162 | 161 |
errors.append('%s is not a date string' % '.'.join(path)) |
163 | 162 | |
164 | 163 |
json_walker(data, check) |
... | ... | |
297 | 296 |
raise |
298 | 297 |
file_data.update(to_json().err_to_response(e)) |
299 | 298 |
# do it later as get_filter() can modify str(link) |
300 |
file_data['text'] = six.text_type(link)
|
|
299 |
file_data['text'] = str(link)
|
|
301 | 300 |
data.append(file_data) |
302 | 301 |
if link_id: |
303 | 302 |
return {'data': data[0] if data else None} |
304 | 303 |
return {'data': data} |
305 | 304 | |
306 | 305 | |
307 |
@six.python_2_unicode_compatible |
|
308 | 306 |
class Link(models.Model): |
309 | 307 |
resource = models.ForeignKey(MDPH13Resource, on_delete=models.CASCADE) |
310 | 308 |
name_id = models.CharField(verbose_name=_('NameID'), max_length=256) |
passerelle/contrib/nancypoll/models.py | ||
---|---|---|
1 | 1 |
import csv |
2 | 2 | |
3 | 3 |
from django.db import models |
4 |
from django.utils import six |
|
5 | 4 |
from django.utils.encoding import force_text |
6 | 5 |
from django.utils.translation import ugettext_lazy as _ |
7 | 6 | |
... | ... | |
51 | 50 |
content = self.csv_file.read() |
52 | 51 |
if not content: |
53 | 52 |
raise APIError('No content found') |
54 |
if six.PY3: |
|
55 |
content = force_text(content) |
|
53 |
content = force_text(content) |
|
56 | 54 | |
57 | 55 |
reader = csv.reader(content.splitlines()) |
58 | 56 |
next(reader) |
passerelle/contrib/planitech/mste.py | ||
---|---|---|
17 | 17 |
import calendar |
18 | 18 |
from datetime import datetime |
19 | 19 | |
20 |
from django.utils import six |
|
21 | ||
22 | 20 |
ENCODE_TOKENS = { |
23 | 21 |
'integer': 16, |
24 | 22 |
'real': 19, |
... | ... | |
228 | 226 |
if ref is not None: |
229 | 227 |
self._push_token_type('ref') |
230 | 228 |
self._push(ref) |
231 |
elif isinstance(obj, six.string_types):
|
|
229 |
elif isinstance(obj, str):
|
|
232 | 230 |
self._encode_string(obj) |
233 | 231 |
elif obj is None: |
234 | 232 |
self._encode_nil() |
passerelle/contrib/solis_apa/models.py | ||
---|---|---|
23 | 23 |
from django.utils.translation import ugettext_lazy as _ |
24 | 24 | |
25 | 25 |
from passerelle.base.models import BaseResource |
26 |
from passerelle.compat import json_loads |
|
27 | 26 |
from passerelle.contrib.solis_apa import conciliation, integration, suivi |
28 | 27 |
from passerelle.utils.jsonresponse import APIError |
29 | 28 | |
... | ... | |
314 | 313 |
uri = 'importFlow?flow=ImportIntegrationDemande&application=%s' % APPLICATION |
315 | 314 |
url = self.get_resource_url(uri) |
316 | 315 | |
317 |
data = {'ImportInputWSDemandeApa': integration.build_message(json_loads(data))}
|
|
316 |
data = {'ImportInputWSDemandeApa': integration.build_message(json.loads(data))}
|
|
318 | 317 |
data = json.dumps(data) |
319 | 318 |
self.logger.debug('Demande APA: %s' % data, extra={'solis_apa_demande': data}) |
320 | 319 |
response = self.requests.post(url, data=data, headers=HEADERS) |
passerelle/contrib/strasbourg_eu/models.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import datetime |
18 |
import json |
|
18 | 19 |
from urllib import parse as urlparse |
19 | 20 | |
20 | 21 |
from django.db import models |
... | ... | |
23 | 24 |
from requests import RequestException |
24 | 25 | |
25 | 26 |
from passerelle.base.models import BaseResource |
26 |
from passerelle.compat import json_loads |
|
27 | 27 |
from passerelle.utils.api import APIError, endpoint |
28 | 28 | |
29 | 29 | |
... | ... | |
52 | 52 |
if name_id is None: |
53 | 53 |
raise APIError('missing name_id') |
54 | 54 |
# expected content: {"interests": ["123", "456"]} |
55 |
response = json_loads(request.body)
|
|
55 |
response = json.loads(request.body)
|
|
56 | 56 |
if 'error ' in response: |
57 | 57 |
return {'err': 1, 'err_desc': response.get('error')} |
58 | 58 |
interests = response.get('interests') |
... | ... | |
134 | 134 |
else: |
135 | 135 |
# expected content: {"title": ..., "description": ..., "url": ..., |
136 | 136 |
# ...}, cf https://strasbourgeurometropole.github.io/slate/#ajout-d-39-une-notification |
137 |
notification = json_loads(request.body)
|
|
137 |
notification = json.loads(request.body)
|
|
138 | 138 |
notification['userId'] = name_id |
139 | 139 |
url = urlparse.urljoin(self.liferay_api_url, 'jsonws/notification.notification/add-notification') |
140 | 140 |
try: |
... | ... | |
172 | 172 |
else: |
173 | 173 |
# expected content: {"title": ..., "url": ..., ...}, |
174 | 174 |
# cf https://strasbourgeurometropole.github.io/slate/?shell#ajout-d-39-un-favori |
175 |
favorite = json_loads(request.body)
|
|
175 |
favorite = json.loads(request.body)
|
|
176 | 176 |
# change type to typeId |
177 | 177 |
types_url = urlparse.urljoin(self.liferay_api_url, 'jsonws/favorite.favorite/get-types') |
178 | 178 |
try: |
passerelle/contrib/teamnet_axel/models.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import base64 |
18 |
import json |
|
18 | 19 |
import logging |
19 | 20 |
import xml.etree.ElementTree as ET |
20 | 21 |
from datetime import datetime |
... | ... | |
26 | 27 |
from django.utils.translation import ugettext_lazy as _ |
27 | 28 | |
28 | 29 |
from passerelle.base.models import BaseResource |
29 |
from passerelle.compat import json_loads |
|
30 | 30 |
from passerelle.soap import client_to_jsondict |
31 | 31 |
from passerelle.utils.api import endpoint |
32 | 32 |
from passerelle.utils.jsonresponse import APIError |
... | ... | |
315 | 315 |
pattern=r'^(?P<regie_id>\w+)/invoice/(?P<invoice_id>[\w,-]+)/pay/$', |
316 | 316 |
) |
317 | 317 |
def pay_invoice(self, request, regie_id, invoice_id, **kwargs): |
318 |
data = json_loads(request.body)
|
|
318 |
data = json.loads(request.body)
|
|
319 | 319 |
transaction_id = data.get('transaction_id') |
320 | 320 |
transaction_date = data.get('transaction_date') |
321 | 321 |
email = data.get('email') |
passerelle/contrib/teamnet_axel/soap.py | ||
---|---|---|
17 | 17 |
# borrowed from https://pypi.python.org/pypi/suds_requests |
18 | 18 |
# and https://docs.oracle.com/cd/E50245_01/E50253/html/vmprg-soap-example-authentication-python.html |
19 | 19 | |
20 |
from django.utils.six import BytesIO |
|
20 |
from io import BytesIO |
|
21 | ||
21 | 22 |
from suds.client import Client |
22 | 23 |
from suds.transport import Reply |
23 | 24 |
from suds.transport.http import HttpAuthenticated |
passerelle/contrib/toulouse_axel/models.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
import base64 |
18 | 18 |
import datetime |
19 |
import json |
|
19 | 20 |
import logging |
20 | 21 |
import os |
21 | 22 | |
... | ... | |
27 | 28 |
from django.utils.translation import ugettext_lazy as _ |
28 | 29 | |
29 | 30 |
from passerelle.base.models import BaseResource |
30 |
from passerelle.compat import json_loads |
|
31 | 31 |
from passerelle.contrib.utils import axel |
32 | 32 |
from passerelle.utils.api import endpoint |
33 | 33 |
from passerelle.utils.jsonresponse import APIError |
... | ... | |
873 | 873 |
}, |
874 | 874 |
) |
875 | 875 |
def pay_invoice(self, request, regie_id, invoice_id, **kwargs): |
876 |
data = json_loads(request.body)
|
|
876 |
data = json.loads(request.body)
|
|
877 | 877 |
dui, invoice_id = invoice_id.rsplit('-', 1) |
878 | 878 | |
879 | 879 |
invoice = self.get_invoice(regie_id=regie_id, dui=dui, invoice_id=invoice_id) |
passerelle/contrib/toulouse_axel/utils.py | ||
---|---|---|
20 | 20 |
import datetime |
21 | 21 |
from collections import OrderedDict |
22 | 22 | |
23 |
from django.utils.six import string_types |
|
24 | ||
25 | 23 |
from passerelle.utils.conversion import normalize |
26 | 24 | |
27 | 25 |
situation_familiale_mapping = OrderedDict( |
... | ... | |
92 | 90 |
if isinstance(data, list): |
93 | 91 |
for i, val in enumerate(data): |
94 | 92 |
data[i] = upperize(val) |
95 |
if isinstance(data, string_types):
|
|
93 |
if isinstance(data, str): |
|
96 | 94 |
data = normalize(data).upper() |
97 | 95 |
return data |
98 | 96 |
passerelle/sms/models.py | ||
---|---|---|
21 | 21 |
from django.core.validators import RegexValidator |
22 | 22 |
from django.db import models |
23 | 23 |
from django.urls import reverse |
24 |
from django.utils import six |
|
25 | 24 |
from django.utils.module_loading import import_string |
26 | 25 |
from django.utils.translation import ugettext_lazy as _ |
27 | 26 | |
... | ... | |
250 | 249 |
abstract = True |
251 | 250 | |
252 | 251 | |
253 |
@six.python_2_unicode_compatible |
|
254 | 252 |
class SMSLog(models.Model): |
255 | 253 |
timestamp = models.DateTimeField(auto_now_add=True) |
256 | 254 |
appname = models.CharField(max_length=128, verbose_name='appname', null=True) |
passerelle/utils/__init__.py | ||
---|---|---|
21 | 21 |
import time |
22 | 22 |
import warnings |
23 | 23 |
from functools import wraps |
24 |
from io import BytesIO |
|
24 | 25 |
from itertools import chain, islice |
25 | 26 | |
26 | 27 |
from django.conf import settings |
... | ... | |
33 | 34 |
from django.utils.encoding import force_bytes, force_text |
34 | 35 |
from django.utils.functional import lazy |
35 | 36 |
from django.utils.html import mark_safe |
36 |
from django.utils.six import BytesIO |
|
37 | 37 |
from django.utils.translation import ngettext_lazy |
38 | 38 |
from django.views.generic.detail import SingleObjectMixin |
39 | 39 |
from requests import Response as RequestResponse |
passerelle/utils/api.py | ||
---|---|---|
19 | 19 |
import inspect |
20 | 20 | |
21 | 21 |
from django.urls import reverse |
22 |
from django.utils import six |
|
23 | 22 |
from django.utils.safestring import mark_safe |
24 | 23 | |
25 | 24 |
# make APIError available from this module |
... | ... | |
109 | 108 |
def __call__(self, func): |
110 | 109 |
func.endpoint_info = self |
111 | 110 |
if not self.name: |
112 |
self.name = func.func_name if six.PY2 else func.__name__
|
|
111 |
self.name = func.__name__ |
|
113 | 112 |
self.func = func |
114 | 113 |
return func |
115 | 114 |
passerelle/utils/conversion.py | ||
---|---|---|
19 | 19 |
import re |
20 | 20 |
import unicodedata |
21 | 21 |
import warnings |
22 |
from io import BytesIO |
|
22 | 23 | |
23 | 24 |
import unidecode |
24 |
from django.utils import six |
|
25 | 25 |
from django.utils.encoding import force_text |
26 |
from django.utils.six import BytesIO |
|
27 | 26 |
from PIL import Image |
28 | 27 | |
29 | 28 | |
... | ... | |
74 | 73 | |
75 | 74 |
def exception_to_text(e): |
76 | 75 |
try: |
77 |
return six.text_type(e)
|
|
76 |
return str(e)
|
|
78 | 77 |
except Exception: |
79 | 78 |
pass |
80 | 79 | |
81 | 80 |
try: |
82 | 81 |
r = repr(e) |
83 |
return six.text_type(r, errors='replace')
|
|
82 |
return str(r, errors='replace')
|
|
84 | 83 |
except Exception: |
85 | 84 |
pass |
86 | 85 | |
87 | 86 |
try: |
88 | 87 |
args = e.args |
89 | 88 |
try: |
90 |
content = six.text_type(repr(args)) if args != [] else ''
|
|
89 |
content = str(repr(args)) if args != [] else ''
|
|
91 | 90 |
except Exception: |
92 | 91 |
content = '<exception-while-rendering-args>' |
93 | 92 |
except AttributeError: |
passerelle/utils/json.py | ||
---|---|---|
31 | 31 | |
32 | 32 |
from __future__ import unicode_literals |
33 | 33 | |
34 |
from django.utils import six |
|
35 | ||
36 | 34 |
from passerelle.utils.validation import is_number |
37 | 35 | |
38 | 36 |
FLATTEN_SEPARATOR = '/' |
... | ... | |
110 | 108 |
for path, value in helper(value): |
111 | 109 |
yield [str(i)] + path, value |
112 | 110 |
elif isinstance(data, dict): |
113 |
for key, value in six.iteritems(data):
|
|
111 |
for key, value in data.items():
|
|
114 | 112 |
for path, value in helper(value): |
115 | 113 |
yield [str(key)] + path, value |
116 | 114 |
else: |
passerelle/utils/sftp.py | ||
---|---|---|
27 | 27 |
from django import forms |
28 | 28 |
from django.core import validators |
29 | 29 |
from django.db import models |
30 |
from django.utils import six |
|
31 | 30 |
from django.utils.encoding import force_bytes, force_text |
32 | 31 |
from django.utils.translation import ugettext_lazy as _ |
33 | 32 |
from paramiko.dsskey import DSSKey |
... | ... | |
59 | 58 |
pass |
60 | 59 | |
61 | 60 | |
62 |
@six.python_2_unicode_compatible |
|
63 | 61 |
class SFTP: |
64 | 62 |
def __init__(self, url, private_key_content=None, private_key_password=None): |
65 | 63 |
self.url = url |
passerelle/utils/wcs.py | ||
---|---|---|
31 | 31 |
from django.conf import settings |
32 | 32 |
from django.core.cache import cache |
33 | 33 |
from django.db import models |
34 |
from django.utils import six |
|
35 | 34 | |
36 | 35 |
from passerelle.base import signature |
37 | 36 | |
... | ... | |
114 | 113 |
self.who = EvolutionUser(wcs_api, **self.who) |
115 | 114 | |
116 | 115 | |
117 |
@six.python_2_unicode_compatible |
|
118 | 116 |
class FormData(BaseObject): |
119 | 117 |
geolocations = None |
120 | 118 |
evolution = None |
... | ... | |
411 | 409 |
content_type = kwargs.get('content_type', 'application/octet-stream') |
412 | 410 |
if hasattr(value, 'read'): |
413 | 411 |
content = base64.b64encode(value.read()) |
414 |
elif isinstance(value, six.binary_type):
|
|
412 |
elif isinstance(value, bytes):
|
|
415 | 413 |
content = base64.b64encode(value) |
416 | 414 |
elif isinstance(value, dict): |
417 | 415 |
if not set(value).issuperset(set(['filename', 'content'])): |
... | ... | |
428 | 426 |
} |
429 | 427 | |
430 | 428 |
def _set_type_date(self, varname, field, value): |
431 |
if isinstance(value, six.string_types):
|
|
429 |
if isinstance(value, str):
|
|
432 | 430 |
value = datetime.datetime.strptime(value, '%Y-%m-%d').date() |
433 | 431 |
if isinstance(value, datetime.datetime): |
434 | 432 |
value = value.date() |
... | ... | |
444 | 442 |
self.data[varname] = value |
445 | 443 | |
446 | 444 |
def _set_type_bool(self, varname, field, value): |
447 |
if isinstance(value, six.string_types):
|
|
445 |
if isinstance(value, str):
|
|
448 | 446 |
value = value.lower().strip() in ['yes', 'true', 'on'] |
449 | 447 |
if not isinstance(value, bool): |
450 | 448 |
raise TypeError('value must be a boolean or a string true, yes, on, false, no, off') |
... | ... | |
454 | 452 |
raise CancelSubmitError |
455 | 453 | |
456 | 454 | |
457 |
@six.python_2_unicode_compatible |
|
458 | 455 |
class FormDef(BaseObject): |
459 | 456 |
geolocations = None |
460 | 457 | |
... | ... | |
645 | 642 |
return choices |
646 | 643 | |
647 | 644 | |
648 |
@six.python_2_unicode_compatible |
|
649 | 645 |
class FormDefRef: |
650 | 646 |
_formdef = None |
651 | 647 |
_api = None |
... | ... | |
655 | 651 |
if value2: |
656 | 652 |
self.wcs_slug, self.formdef_slug = value1, value2 |
657 | 653 |
else: |
658 |
self.wcs_slug, self.formdef_slug = six.text_type(value1).rsplit(':', 1)
|
|
654 |
self.wcs_slug, self.formdef_slug = str(value1).rsplit(':', 1)
|
|
659 | 655 | |
660 | 656 |
@property |
661 | 657 |
def api(self): |
passerelle/utils/zip.py | ||
---|---|---|
28 | 28 |
from django.template.loader import get_template |
29 | 29 |
from django.utils.encoding import force_str |
30 | 30 |
from django.utils.functional import cached_property |
31 |
from django.utils.six import python_2_unicode_compatible |
|
32 | 31 |
from jsonschema import ValidationError, validate |
33 | 32 | |
34 | 33 |
from passerelle.utils.files import atomic_write |
... | ... | |
92 | 91 |
VARIABLE_RE = re.compile(r'{{ *(\w*)') |
93 | 92 | |
94 | 93 | |
95 |
@python_2_unicode_compatible |
|
96 | 94 |
class ZipPart: |
97 | 95 |
def __init__(self, zip_template, name_template, template_path=None, content_expression=None): |
98 | 96 |
self.zip_template = zip_template |
passerelle/views.py | ||
---|---|---|
53 | 53 |
from jsonschema import ValidationError, validate, validators |
54 | 54 | |
55 | 55 |
from passerelle.base.models import BaseResource, ResourceLog |
56 |
from passerelle.compat import json_loads |
|
57 | 56 |
from passerelle.utils.conversion import normalize |
58 | 57 |
from passerelle.utils.json import unflatten |
59 | 58 |
from passerelle.utils.jsonresponse import APIError, JSONEncoder |
... | ... | |
397 | 396 |
merge_extra = hasattr(json_schema, 'items') and json_schema.get('merge_extra', False) |
398 | 397 |
pre_process = hasattr(json_schema, 'items') and json_schema.get('pre_process') |
399 | 398 |
try: |
400 |
data = json_loads(request.body)
|
|
399 |
data = json.loads(request.body)
|
|
401 | 400 |
except ValueError as e: |
402 | 401 |
raise APIError("could not decode body to json: %s" % e, http_status=400) |
403 | 402 |
if must_unflatten: |
tests/conftest.py | ||
---|---|---|
6 | 6 |
from django.contrib.auth.models import User |
7 | 7 |
from django.core.cache import cache |
8 | 8 |
from django.core.files import File |
9 |
from django.utils import six |
|
10 | 9 |
from httmock import HTTMock, remember_called, response, urlmatch |
11 | 10 | |
12 | 11 |
from tests.utils import make_resource |
13 | 12 | |
14 |
if six.PY2: |
|
15 |
collect_ignore = ['wcs/'] |
|
16 | ||
17 | 13 | |
18 | 14 |
@pytest.fixture(autouse=True) |
19 | 15 |
def media(settings, tmpdir): |
tests/test_address.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import json |
18 |
from io import StringIO |
|
18 | 19 | |
19 | 20 |
import mock |
20 | 21 |
import pytest |
21 | 22 |
from django.core.files import File |
22 |
from django.utils.six import StringIO |
|
23 | 23 | |
24 | 24 |
import tests.utils |
25 | 25 |
from passerelle.apps.base_adresse.models import BaseAdresse |
tests/test_cartads_cs.py | ||
---|---|---|
13 | 13 |
import tests.utils |
14 | 14 |
from passerelle.apps.cartads_cs.models import CartaDSCS, CartaDSDossier, CartaDSFile |
15 | 15 |
from passerelle.base.models import Job |
16 |
from passerelle.compat import json_loads |
|
17 | 16 | |
18 | 17 | |
19 | 18 |
@pytest.fixture |
... | ... | |
716 | 715 |
assert url.netloc == 'idp.example.org' |
717 | 716 |
if url.path == '/api/roles/': |
718 | 717 |
dossier = CartaDSDossier.objects.all().first() |
719 |
assert json_loads(request.body) == json.loads(
|
|
718 |
assert json.loads(request.body) == json.loads(
|
|
720 | 719 |
'{"name": "Suivi Cart@DS (%s)", "slug": "_cartads_%s"}' % (dossier.id, dossier.id) |
721 | 720 |
) |
722 | 721 |
return {'content': json.dumps({'uuid': 'role-uuid'}), 'status_code': 200} |
723 | 722 |
elif url.path == '/api/roles/role-uuid/relationships/members/': |
724 |
body = json_loads(request.body)
|
|
723 |
body = json.loads(request.body)
|
|
725 | 724 |
idp_mock.subscribed_roles = set([x['uuid'] for x in body['data']]) |
726 | 725 |
return {'content': json.dumps({'err': 0}), 'status_code': 200} |
727 | 726 |
raise Exception('unhandled http call (%s)' % url) |
tests/test_csv_datasource.py | ||
---|---|---|
17 | 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | |
19 | 19 |
import datetime |
20 |
import json |
|
20 | 21 |
import os |
21 | 22 |
import time |
22 | 23 |
import uuid |
24 |
from io import StringIO |
|
23 | 25 |
from posix import stat_result |
24 | 26 |
from stat import ST_MTIME |
25 | 27 |
from urllib.parse import urlencode |
26 | 28 | |
27 | 29 |
import mock |
28 | 30 |
import pytest |
29 |
import six |
|
30 | 31 |
import webtest |
31 | 32 |
from django.contrib.contenttypes.models import ContentType |
32 | 33 |
from django.core.files import File |
... | ... | |
35 | 36 |
from django.test import Client, override_settings |
36 | 37 |
from django.urls import reverse |
37 | 38 |
from django.utils.encoding import force_bytes, force_str, force_text |
38 |
from django.utils.six import StringIO |
|
39 | 39 |
from django.utils.timezone import now |
40 | 40 | |
41 | 41 |
from passerelle.apps.csvdatasource.models import CsvDataSource, Query, TableRow, upload_to |
42 | 42 |
from passerelle.base.models import AccessRight, ApiUser |
43 |
from passerelle.compat import json_loads |
|
44 | 43 |
from tests.test_manager import login |
45 | 44 | |
46 | 45 |
data = """121;69981;DELANOUE;Eliot;H |
... | ... | |
114 | 113 | |
115 | 114 | |
116 | 115 |
def parse_response(response): |
117 |
return json_loads(response.content)['data']
|
|
116 |
return json.loads(response.content)['data']
|
|
118 | 117 | |
119 | 118 | |
120 | 119 |
@pytest.fixture |
... | ... | |
345 | 344 |
_, url = setup(data=StringIO(data)) |
346 | 345 |
CsvDataSource.objects.all().update(_dialect_options=None) |
347 | 346 |
resp = client.get(url) |
348 |
result = json_loads(resp.content)
|
|
347 |
result = json.loads(resp.content)
|
|
349 | 348 |
assert result['err'] == 0 |
350 | 349 |
assert len(result['data']) == 20 |
351 | 350 | |
... | ... | |
353 | 352 |
def test_missing_columns(client, setup): |
354 | 353 |
_, url = setup(data=StringIO(data + 'A;B;C\n')) |
355 | 354 |
resp = client.get(url) |
356 |
result = json_loads(resp.content)
|
|
355 |
result = json.loads(resp.content)
|
|
357 | 356 |
assert result['err'] == 0 |
358 | 357 |
assert len(result['data']) == 21 |
359 | 358 |
assert result['data'][-1] == {'lname': 'C', 'sex': '', 'id': 'B', 'fname': '', 'fam': 'A'} |
... | ... | |
364 | 363 |
csvdata.sheet_name = 'unknown' |
365 | 364 |
csvdata.save() |
366 | 365 |
resp = client.get(url) |
367 |
result = json_loads(resp.content)
|
|
366 |
result = json.loads(resp.content)
|
|
368 | 367 |
assert len(result['data']) == 20 |
369 | 368 | |
370 | 369 | |
371 | 370 |
def test_cache_new_shorter_file(client, setup): |
372 | 371 |
csvdata, url = setup(data=StringIO(data + 'A;B;C\n')) |
373 | 372 |
resp = client.get(url) |
374 |
result = json_loads(resp.content)
|
|
373 |
result = json.loads(resp.content)
|
|
375 | 374 |
assert result['err'] == 0 |
376 | 375 |
assert len(result['data']) == 21 |
377 | 376 |
csvdata.csv_file = File(StringIO(data), 'data.csv') |
378 | 377 |
csvdata.save() |
379 | 378 |
resp = client.get(url) |
380 |
result = json_loads(resp.content)
|
|
379 |
result = json.loads(resp.content)
|
|
381 | 380 |
assert len(result['data']) == 20 |
382 | 381 | |
383 | 382 | |
... | ... | |
400 | 399 |
for row in response.json['data']: |
401 | 400 |
assert len(row) == 2 |
402 | 401 |
assert isinstance(row[0], int) |
403 |
assert isinstance(row[1], six.text_type)
|
|
402 |
assert isinstance(row[1], str)
|
|
404 | 403 | |
405 | 404 | |
406 | 405 |
def test_query_q_filter(app, setup, filetype): |
... | ... | |
449 | 448 |
for row in response.json['data']: |
450 | 449 |
assert len(row) == 2 |
451 | 450 |
assert isinstance(row['id'], int) |
452 |
assert isinstance(row['prenom'], six.text_type)
|
|
451 |
assert isinstance(row['prenom'], str)
|
|
453 | 452 | |
454 | 453 | |
455 | 454 |
def test_query_tuples(app, setup, filetype): |
... | ... | |
473 | 472 |
assert row[0][0] == 'id' |
474 | 473 |
assert isinstance(row[0][1], int) |
475 | 474 |
assert row[1][0] == 'prenom' |
476 |
assert isinstance(row[1][1], six.text_type)
|
|
475 |
assert isinstance(row[1][1], str)
|
|
477 | 476 | |
478 | 477 | |
479 | 478 |
def test_query_onerow(app, setup, filetype): |
tests/test_ensure_jsonbfields.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 | |
3 |
from io import BytesIO |
|
4 | ||
3 | 5 |
import pytest |
4 | 6 |
from django.core.files import File |
5 | 7 |
from django.core.management import call_command |
6 | 8 |
from django.db import connection |
7 |
from django.utils.six import BytesIO |
|
8 | 9 | |
9 | 10 |
from passerelle.apps.csvdatasource.models import CsvDataSource |
10 | 11 |
from passerelle.contrib.teamnet_axel.models import TeamnetAxel |
tests/test_grenoble_gru.py | ||
---|---|---|
20 | 20 | |
21 | 21 |
import mock |
22 | 22 |
import pytest |
23 |
import six |
|
24 | 23 |
from django.urls import reverse |
25 | 24 | |
26 | 25 |
import tests.utils |
... | ... | |
119 | 118 | |
120 | 119 |
@pytest.fixture(params=['01', '02', '10', '20', '21', '23', '4242']) |
121 | 120 |
def remote_response(request): |
122 |
text = six.text_type(request.param)
|
|
121 |
text = str(request.param)
|
|
123 | 122 |
return tests.utils.FakedResponse(index=request.param_index, text=text) |
124 | 123 | |
125 | 124 |
tests/test_import_export.py | ||
---|---|---|
3 | 3 |
import os |
4 | 4 |
import sys |
5 | 5 |
import tempfile |
6 |
from io import BytesIO, StringIO |
|
6 | 7 | |
7 | 8 |
import pytest |
8 | 9 |
from django.contrib.contenttypes.models import ContentType |
... | ... | |
12 | 13 |
from django.urls import reverse |
13 | 14 |
from django.utils import timezone |
14 | 15 |
from django.utils.encoding import force_bytes, force_text |
15 |
from django.utils.six import BytesIO, StringIO |
|
16 | 16 | |
17 | 17 |
from passerelle.apps.base_adresse.models import BaseAdresse |
18 | 18 |
from passerelle.apps.bdp.models import Bdp |
... | ... | |
20 | 20 |
from passerelle.apps.ovh.models import OVHSMSGateway |
21 | 21 |
from passerelle.apps.sector.models import SectorResource |
22 | 22 |
from passerelle.base.models import AccessRight, ApiUser |
23 |
from passerelle.compat import json_loads |
|
24 | 23 |
from passerelle.utils import ImportSiteError, export_site, import_site |
25 | 24 | |
26 | 25 |
data = """121;69981;DELANOUE;Eliot;H |
... | ... | |
91 | 90 | |
92 | 91 | |
93 | 92 |
def parse_response(response): |
94 |
return json_loads(response.content)['data']
|
|
93 |
return json.loads(response.content)['data']
|
|
95 | 94 | |
96 | 95 | |
97 | 96 |
@pytest.fixture |
... | ... | |
138 | 137 |
assert first == second |
139 | 138 | |
140 | 139 |
output = get_output_of_command('export_site') |
141 |
third = json_loads(output)
|
|
140 |
third = json.loads(output)
|
|
142 | 141 |
third['resources'][0]['csv_file']['name'] = 'whocares' |
143 | 142 |
assert first == third |
144 | 143 |
tests/test_jsonresponse.py | ||
---|---|---|
1 |
import json |
|
1 | 2 |
import logging |
2 | 3 | |
3 | 4 |
import pytest |
... | ... | |
5 | 6 |
from django.http import Http404 |
6 | 7 |
from django.test.client import RequestFactory |
7 | 8 | |
8 |
from passerelle.compat import json_loads |
|
9 | 9 |
from passerelle.utils import to_json |
10 | 10 | |
11 | 11 | |
... | ... | |
109 | 109 |
assert record.method == 'GET' |
110 | 110 |
assert "Error occurred while processing request" in record.message |
111 | 111 |
assert response.status_code == 488 |
112 |
data = json_loads(response.content)
|
|
112 |
data = json.loads(response.content)
|
|
113 | 113 |
assert data['err'] == 'logaswarningexception' |
114 | 114 |
assert data['err_desc'] == 'log as warning exception' |
115 | 115 | |
... | ... | |
124 | 124 | |
125 | 125 |
result = test_func(req) |
126 | 126 |
assert result.status_code == 200 |
127 |
data = json_loads(result.content)
|
|
127 |
data = json.loads(result.content)
|
|
128 | 128 |
assert data == {'test': 'un test', 'err': 0} |
129 | 129 | |
130 | 130 |
@to_json() |
... | ... | |
135 | 135 |
raise CustomException |
136 | 136 | |
137 | 137 |
result = test_func2(req) |
138 |
data = json_loads(result.content)
|
|
138 |
data = json.loads(result.content)
|
|
139 | 139 |
assert 'err_class' in data |
140 | 140 |
assert 'err' in data |
141 | 141 |
assert data['err'] == 1 |
... | ... | |
161 | 161 |
content_type = result.get('Content-Type') |
162 | 162 |
assert 'application/javascript' in content_type |
163 | 163 |
assert result.content.startswith(b'myfunc(') |
164 |
args = json_loads(result.content[7:-2])
|
|
164 |
args = json.loads(result.content[7:-2])
|
|
165 | 165 |
assert args == {'foo': 'bar', 'err': 0} |
166 | 166 | |
167 | 167 |
tests/test_lille_urban_card.py | ||
---|---|---|
7 | 7 |
from httmock import HTTMock |
8 | 8 | |
9 | 9 |
import tests.utils |
10 |
from passerelle.compat import json_loads |
|
11 | 10 |
from passerelle.contrib.lille_urban_card.models import LilleUrbanCard |
12 | 11 |
from passerelle.utils.jsonresponse import APIError |
13 | 12 | |
... | ... | |
29 | 28 |
if url.path == '/clu/ws/auth/connexion': |
30 | 29 |
return {'content': TOKEN_RESPONSE, 'status_code': 200} |
31 | 30 |
if url.path == '/clu/ws/demanderCarte': |
32 |
request_json = json_loads(request.body)
|
|
31 |
request_json = json.loads(request.body)
|
|
33 | 32 |
if request_json.get('simulate_error') == 'doublon': |
34 | 33 |
error = {'erreur': 'Demande 113-9166 : 1 demande(s) ...'} |
35 | 34 |
return {'content': json.dumps(error), 'status_code': 409} |
... | ... | |
50 | 49 |
} |
51 | 50 |
return {'content': json.dumps(content), 'status_code': 200} |
52 | 51 |
if url.path == '/clu/ws/ajouterAbonnements': |
53 |
request_json = json_loads(request.body)
|
|
52 |
request_json = json.loads(request.body)
|
|
54 | 53 |
if request_json.get('simulate_error') == 'data': |
55 | 54 |
error = {'statut': 'ERREUR_DONNEES', 'erreur': 'Demande vide...'} |
56 | 55 |
return {'content': json.dumps(error), 'status_code': 400} |
... | ... | |
60 | 59 |
} |
61 | 60 |
return {'content': json.dumps(content), 'status_code': 200} |
62 | 61 |
if url.path == '/clu/ws/modifierCodeSecret': |
63 |
request_json = json_loads(request.body)
|
|
62 |
request_json = json.loads(request.body)
|
|
64 | 63 |
if request_json.get('simulate_error') == 'wrong num serie': |
65 | 64 |
error = {'statut': 'ERREUR_NUM_SERIE', 'erreur': 'Le numero de serie...'} |
66 | 65 |
return {'content': json.dumps(error), 'status_code': 404} |
... | ... | |
72 | 71 |
return {'content': json.dumps(error), 'status_code': 404} |
73 | 72 |
return {'content': json.dumps({'message': 'Le mot de passe est valide'}), 'status_code': 200} |
74 | 73 |
if url.path in ('/clu/ws/revoquerCarte', '/clu/ws/revoquerAbonnement'): |
75 |
request_json = json_loads(request.body)
|
|
74 |
request_json = json.loads(request.body)
|
|
76 | 75 |
if request_json.get('simulate_error') == 'doublon': |
77 | 76 |
error = {'erreur': 'La demande xx existe...'} |
78 | 77 |
return {'content': json.dumps(error), 'status_code': 409} |
79 | 78 |
return {'content': json.dumps({'message': 'ok'}), 'status_code': 200} |
80 | 79 |
if url.path == '/clu/ws/renouvelerAbonnements': |
81 |
request_json = json_loads(request.body)
|
|
80 |
request_json = json.loads(request.body)
|
|
82 | 81 |
if request_json.get('simulate_error') == 'wrong num serie': |
83 | 82 |
error = {'statut': 'ERREUR_NUM_SERIE', 'erreur': 'Le numero de serie...'} |
84 | 83 |
return {'content': json.dumps(error), 'status_code': 409} |
tests/test_manager.py | ||
---|---|---|
2 | 2 |
import json |
3 | 3 |
import re |
4 | 4 |
import uuid |
5 |
from io import StringIO |
|
5 | 6 | |
6 | 7 |
import freezegun |
7 | 8 |
import pytest |
8 | 9 |
from django.contrib.contenttypes.models import ContentType |
9 | 10 |
from django.core.files import File |
10 | 11 |
from django.utils.encoding import force_bytes |
11 |
from django.utils.six import StringIO |
|
12 | 12 |
from django.utils.timezone import now |
13 | 13 |
from webtest import Upload |
14 | 14 |
tests/test_mdel.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
import base64 |
20 | 20 |
import copy |
21 |
import json |
|
21 | 22 |
import os |
22 | 23 |
import shutil |
23 | 24 |
import zipfile |
... | ... | |
30 | 31 |
from passerelle.apps.mdel.mdel import AttachedFile, Description, Message, get_resource_base_dir |
31 | 32 |
from passerelle.apps.mdel.models import MDEL, Demand |
32 | 33 |
from passerelle.apps.mdel.utils import parse_date |
33 |
from passerelle.compat import json_loads |
|
34 | 34 |
from passerelle.utils import SFTP |
35 | 35 | |
36 | 36 |
AEC_XSD = 'ActeEtatCivil-V1.A.xsd' |
... | ... | |
69 | 69 | |
70 | 70 |
@pytest.fixture( |
71 | 71 |
params=[ |
72 |
json_loads(get_file_from_test_base_dir('formdata_aec_naiss.json')),
|
|
73 |
json_loads(get_file_from_test_base_dir('formdata_aec_mariage.json')),
|
|
74 |
json_loads(get_file_from_test_base_dir('formdata_aec_deces.json')),
|
|
72 |
json.loads(get_file_from_test_base_dir('formdata_aec_naiss.json')),
|
|
73 |
json.loads(get_file_from_test_base_dir('formdata_aec_mariage.json')),
|
|
74 |
json.loads(get_file_from_test_base_dir('formdata_aec_deces.json')),
|
|
75 | 75 |
], |
76 | 76 |
ids=['naissance', 'mariage', 'deces'], |
77 | 77 |
) |
... | ... | |
79 | 79 |
return request.param |
80 | 80 | |
81 | 81 | |
82 |
ILE_PAYLOAD = json_loads(get_file_from_test_base_dir('formdata.json'))
|
|
82 |
ILE_PAYLOAD = json.loads(get_file_from_test_base_dir('formdata.json'))
|
|
83 | 83 | |
84 | 84 | |
85 | 85 |
def test_message(): |
... | ... | |
344 | 344 | |
345 | 345 | |
346 | 346 |
def test_create_aec_demand_type_without_date_acte(app, setup): |
347 |
payload = json_loads(get_file_from_test_base_dir('formdata_aec_deces.json'))
|
|
347 |
payload = json.loads(get_file_from_test_base_dir('formdata_aec_deces.json'))
|
|
348 | 348 |
payload['fields'].pop('date_acte') |
349 | 349 |
resp = app.post_json('/mdel/test/create', params=payload, status=200) |
350 | 350 |
assert resp.json['err_desc'] == '<date_acte> is required' |
... | ... | |
506 | 506 | |
507 | 507 |
def test_create_ile_demand_type_invalid_document_proof(app, setup): |
508 | 508 |
# test with missing key |
509 |
payload = json_loads(get_file_from_test_base_dir('formdata.json'))
|
|
509 |
payload = json.loads(get_file_from_test_base_dir('formdata.json'))
|
|
510 | 510 |
payload['fields'].pop('justificatif_domicile_hebergeur') |
511 | 511 |
resp = app.post_json('/mdel/test/create', params=payload, status=200) |
512 | 512 |
assert resp.json['err_desc'] == 'justificatif_domicile and all its attributes are required' |
513 | 513 | |
514 | 514 |
# test with invalid content |
515 |
payload = json_loads(get_file_from_test_base_dir('formdata.json'))
|
|
515 |
payload = json.loads(get_file_from_test_base_dir('formdata.json'))
|
|
516 | 516 |
payload['fields']['justificatif_identite'] = None |
517 | 517 |
payload['fields']['justificatif_identite_verso'] = None |
518 | 518 |
resp = app.post_json('/mdel/test/create', params=payload, status=200) |
... | ... | |
658 | 658 | |
659 | 659 | |
660 | 660 |
def test_aec_filenames_and_routing(app, setup): |
661 |
aec_payload = json_loads(get_file_from_test_base_dir('formdata_aec_naiss.json'))
|
|
661 |
aec_payload = json.loads(get_file_from_test_base_dir('formdata_aec_naiss.json'))
|
|
662 | 662 |
resp = app.post_json('/mdel/test/create', params=aec_payload, status=200) |
663 | 663 | |
664 | 664 |
assert resp.json['data']['demand_id'] == '15-4-AEC-LA' |
tests/test_misc.py | ||
---|---|---|
1 | 1 |
import datetime |
2 |
from io import StringIO |
|
2 | 3 | |
3 | 4 |
import mock |
4 | 5 |
import pytest |
... | ... | |
8 | 9 |
from django.db.migrations.executor import MigrationExecutor |
9 | 10 |
from django.urls import reverse |
10 | 11 |
from django.utils import timezone |
11 |
from django.utils.six import StringIO |
|
12 | 12 |
from mock import patch |
13 | 13 |
from requests.exceptions import ReadTimeout |
14 | 14 |
tests/test_nancypoll.py | ||
---|---|---|
1 |
import json |
|
2 |
from io import StringIO |
|
3 | ||
1 | 4 |
import pytest |
2 | 5 |
from django.contrib.contenttypes.models import ContentType |
3 | 6 |
from django.core.files import File |
4 | 7 |
from django.test import Client |
5 | 8 |
from django.urls import reverse |
6 |
from django.utils.six import StringIO |
|
7 | 9 | |
8 | 10 |
from passerelle.base.models import AccessRight, ApiUser |
9 |
from passerelle.compat import json_loads |
|
10 | 11 |
from passerelle.contrib.nancypoll.models import NancyPoll |
11 | 12 | |
12 | 13 |
data = """ |
... | ... | |
30 | 31 | |
31 | 32 | |
32 | 33 |
def parse_response(response): |
33 |
return json_loads(response.content)['data']
|
|
34 |
return json.loads(response.content)['data']
|
|
34 | 35 | |
35 | 36 | |
36 | 37 |
@pytest.fixture |
... | ... | |
50 | 51 |
def test_failure(setup): |
51 | 52 |
url, client = setup |
52 | 53 |
qs = {'street_no': '37000', 'street_name': 'Rue du Marechal Juin'} |
53 |
resp = json_loads(client.get(url, qs).content)
|
|
54 |
resp = json.loads(client.get(url, qs).content)
|
|
54 | 55 |
assert resp['err_desc'] == 'Polling Station Not Found' |
55 | 56 |
assert int(resp['err']) != 0 |
56 | 57 | |
... | ... | |
60 | 61 |
qs = {} |
61 | 62 |
resp = client.get(url, qs) |
62 | 63 |
assert resp.status_code == 200 |
63 |
assert json_loads(resp.content)['err_desc'] == 'All parameters are required'
|
|
64 |
assert int(json_loads(resp.content)['err']) != 0
|
|
64 |
assert json.loads(resp.content)['err_desc'] == 'All parameters are required'
|
|
65 |
assert int(json.loads(resp.content)['err']) != 0
|
|
65 | 66 | |
66 | 67 | |
67 | 68 |
def test_invalid_street_no(setup): |
... | ... | |
69 | 70 |
qs = {'street_no': 'lol', 'street_name': 'whatever'} |
70 | 71 |
resp = client.get(url, qs) |
71 | 72 |
assert resp.status_code == 200 |
72 |
assert json_loads(resp.content)['err_desc'] == 'Invalid street no value'
|
|
73 |
assert int(json_loads(resp.content)['err']) != 0
|
|
73 |
assert json.loads(resp.content)['err_desc'] == 'Invalid street no value'
|
|
74 |
assert int(json.loads(resp.content)['err']) != 0
|
|
74 | 75 | |
75 | 76 | |
76 | 77 |
def test_success_i_side(setup): |
tests/test_proxylogger.py | ||
---|---|---|
8 | 8 |
import requests |
9 | 9 |
from django.core.exceptions import ValidationError |
10 | 10 |
from django.utils.log import AdminEmailHandler |
11 |
from django.utils.six import PY2 |
|
12 | 11 |
from httmock import HTTMock |
13 | 12 | |
14 | 13 |
import tests.utils |
... | ... | |
315 | 314 |
assert not ResourceLog.objects.all()[1].extra.get('response_content') |
316 | 315 | |
317 | 316 |
# - connector error |
318 |
if PY2: |
|
319 |
assert ResourceLog.objects.all()[2].extra['body'] == "'user_query_var=11111111111111111111'" |
|
320 |
else: |
|
321 |
assert ResourceLog.objects.all()[2].extra['body'] == 'user_query_var=11111111111111111111' |
|
317 |
assert ResourceLog.objects.all()[2].extra['body'] == 'user_query_var=11111111111111111111' |
|
322 | 318 |
assert ( |
323 | 319 |
ResourceLog.objects.all()[2].extra['exception'] == "{'connector_error_var': '44444444444444444444'}" |
324 | 320 |
) |
... | ... | |
334 | 330 |
# - connector POST queries |
335 | 331 |
assert ResourceLog.objects.all()[1].extra['request_payload'] == "connector_query_var=22222222222222222222" |
336 | 332 |
assert ResourceLog.objects.all()[1].extra.get('response_headers') == {'Content-Type': 'foo/bar'} |
337 |
if PY2: |
|
338 |
assert ( |
|
339 |
ResourceLog.objects.all()[1].extra.get('response_content') |
|
340 |
== '{"service_reply_var": "33333333333333333333"}' |
|
341 |
) |
|
342 |
else: |
|
343 |
assert ( |
|
344 |
ResourceLog.objects.all()[1].extra.get('response_content') |
|
345 |
== '{"service_reply_var": "33333333333333333333"}' |
|
346 |
) |
|
333 |
assert ( |
|
334 |
ResourceLog.objects.all()[1].extra.get('response_content') |
|
335 |
== '{"service_reply_var": "33333333333333333333"}' |
|
336 |
) |
|
347 | 337 | |
348 | 338 |
# log troncated payloads |
349 | 339 |
parameters = connector.logging_parameters |
... | ... | |
361 | 351 |
assert ResourceLog.objects.all()[1].extra['request_payload'] == 'connector_query_var=22222' |
362 | 352 | |
363 | 353 |
# - connector error |
364 |
if PY2: |
|
365 |
assert ResourceLog.objects.all()[2].extra['body'] == "'user_query_var=1111111111'" |
|
366 |
else: |
|
367 |
assert ResourceLog.objects.all()[2].extra['body'] == 'user_query_var=1111111111' |
|
354 |
assert ResourceLog.objects.all()[2].extra['body'] == 'user_query_var=1111111111' |
|
368 | 355 | |
369 | 356 |
# log troncated service response |
370 | 357 |
parameters = connector.logging_parameters |
... | ... | |
376 | 363 |
assert len(ResourceLog.objects.all()) == 3 |
377 | 364 | |
378 | 365 |
# - connector POST queries |
379 |
if PY2: |
|
380 |
assert ResourceLog.objects.all()[1].extra.get('response_content') == '{"service_reply_var": "33' |
|
381 |
else: |
|
382 |
assert ResourceLog.objects.all()[1].extra.get('response_content') == '{"service_reply_var": "33' |
|
366 |
assert ResourceLog.objects.all()[1].extra.get('response_content') == '{"service_reply_var": "33' |
|
383 | 367 | |
384 | 368 | |
385 | 369 |
def test_proxy_logger_email_traceback(app, db, email_handler, settings, mailoutbox, connector, monkeypatch): |
tests/test_sector.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
import datetime |
18 | 18 |
import os |
19 |
from io import StringIO |
|
19 | 20 |
from posix import stat_result |
20 | 21 |
from stat import ST_MTIME |
21 | 22 | |
... | ... | |
26 | 27 |
from django.core.management import call_command |
27 | 28 |
from django.urls import reverse |
28 | 29 |
from django.utils.encoding import force_str, force_text |
29 |
from django.utils.six import StringIO |
|
30 | 30 |
from django.utils.timezone import now |
31 | 31 | |
32 | 32 |
import tests.utils |
tests/test_solis.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 | |
3 |
from io import StringIO |
|
4 | ||
3 | 5 |
import mock |
4 | 6 |
import pytest |
5 | 7 |
from django.contrib.contenttypes.models import ContentType |
6 | 8 |
from django.core.files import File |
7 |
from django.utils.six import StringIO |
|
8 | 9 | |
9 | 10 |
import tests.utils |
10 | 11 |
from passerelle.apps.solis.models import Solis, SolisAPALink, SolisRSALink, unflat |
tests/test_templatetags.py | ||
---|---|---|
17 | 17 |
import inspect |
18 | 18 | |
19 | 19 |
from django.apps import apps |
20 |
from django.utils import six, translation
|
|
20 |
from django.utils import translation |
|
21 | 21 | |
22 | 22 |
from passerelle.base.templatetags.passerelle import render_body_schemas, render_json_schema |
23 | 23 | |
... | ... | |
25 | 25 |
def test_render_body_schemas(db): |
26 | 26 |
# FIXME: db should be required but the way ProxyLogger is initialized force an access to the DB |
27 | 27 |
def collect_schemas(): |
28 |
predicate = inspect.isfunction if six.PY3 else inspect.ismethod |
|
29 | 28 |
for app in apps.get_app_configs(): |
30 | 29 |
connector_model = None |
31 | 30 |
if not hasattr(app, 'get_connector_model'): |
... | ... | |
33 | 32 |
connector_model = app.get_connector_model() |
34 | 33 |
if connector_model is None: |
35 | 34 |
continue |
36 |
for _, method in inspect.getmembers(connector_model, predicate):
|
|
35 |
for _, method in inspect.getmembers(connector_model, inspect.isfunction):
|
|
37 | 36 |
if not hasattr(method, 'endpoint_info'): |
38 | 37 |
continue |
39 | 38 |
if method.endpoint_info.post and method.endpoint_info.post.get('request_body', {}).get( |
tests/utils.py | ||
---|---|---|
7 | 7 |
from django.urls import reverse |
8 | 8 | |
9 | 9 |
from passerelle.base.models import AccessRight, ApiUser |
10 |
from passerelle.compat import json_loads |
|
11 | 10 | |
12 | 11 | |
13 | 12 |
def generic_endpoint_url(connector, endpoint, slug='test'): |
... | ... | |
25 | 24 |
headers = {} |
26 | 25 | |
27 | 26 |
def json(self): |
28 |
return json_loads(self.content)
|
|
27 |
return json.loads(self.content)
|
|
29 | 28 | |
30 | 29 | |
31 | 30 |
def mock_url(url=None, response='', status_code=200, headers=None, reason=None, exception=None, qs=None): |
tests/wcs/conftest.py | ||
---|---|---|
16 | 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | |
18 | 18 | |
19 |
import configparser |
|
19 | 20 |
import contextlib |
20 | 21 |
import os |
21 | 22 |
import pickle |
... | ... | |
29 | 30 |
import httmock |
30 | 31 |
import psycopg2 |
31 | 32 |
import pytest |
32 |
from django.utils.six.moves import configparser as ConfigParser |
|
33 | 33 | |
34 | 34 | |
35 | 35 |
def find_free_tcp_port(): |
... | ... | |
157 | 157 |
@property |
158 | 158 |
@contextlib.contextmanager |
159 | 159 |
def site_options(self): |
160 |
config = ConfigParser.ConfigParser()
|
|
160 |
config = configparser.ConfigParser()
|
|
161 | 161 | |
162 | 162 |
site_options_path = os.path.join(self.app_dir, 'site-options.cfg') |
163 | 163 |
if os.path.exists(site_options_path): |
164 |
- |