Projet

Général

Profil

0001-misc-remove-usage-of-six-module-63687.patch

Valentin Deniaud, 20 avril 2022 14:35

Télécharger (8,18 ko)

Voir les différences:

Subject: [PATCH] misc: remove usage of "six" module (#63687)

 bijoe/hobo_agent/management/commands/hobo_deploy.py | 11 +++++------
 bijoe/schemas.py                                    |  1 -
 bijoe/utils.py                                      |  1 -
 bijoe/visualization/signature.py                    | 11 +++++------
 tests/test_hobo_deploy.py                           |  8 ++++----
 tests/test_import_export.py                         |  2 +-
 tests/test_signature.py                             |  5 ++---
 7 files changed, 17 insertions(+), 22 deletions(-)
bijoe/hobo_agent/management/commands/hobo_deploy.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 configparser
17 18
import hashlib
18 19
import os
19

  
20
from django.utils.six.moves import configparser as ConfigParser
21
from django.utils.six.moves.urllib import parse as urlparse
20
import urllib.parse
22 21

  
23 22
try:
24 23
    import sentry_sdk
......
53 52

  
54 53

  
55 54
def schema_from_url(url, hash_length=6):
56
    netloc = urlparse.urlparse(url).netloc
55
    netloc = urllib.parse.urlparse(url).netloc
57 56
    assert netloc
58 57
    domain = netloc.split(':')[0]
59 58
    pg_identifier = domain.replace('.', '_').replace('-', '_')
......
67 66
            services = hobo_environment.get('services')
68 67
            ini_file = os.path.join(tenant.get_directory(), 'wcs-olap.ini')
69 68
            schemas_path = os.path.join(tenant.get_directory(), 'schemas')
70
            config = ConfigParser.SafeConfigParser()
69
            config = configparser.SafeConfigParser()
71 70
            config.read(ini_file)
72 71

  
73 72
            self.configure_sentry(config)
......
112 111
                    # in that case they need to be kept uptodate
113 112
                    continue
114 113
                schema = schema_from_url(base_url)
115
                orig = urlparse.urlparse(this.get('base_url')).netloc.split(':')[0]
114
                orig = urllib.parse.urlparse(this.get('base_url')).netloc.split(':')[0]
116 115
                their_key = service.get('secret_key')
117 116
                key = KnownServices.shared_secret(our_key, their_key)
118 117

  
bijoe/schemas.py
19 19
import datetime
20 20
import decimal
21 21

  
22
from django.utils import six
23 22
from django.utils.encoding import force_text
24 23
from django.utils.functional import Promise
25 24
from django.utils.translation import ugettext_lazy as _
bijoe/utils.py
21 21

  
22 22
from django.conf import settings
23 23
from django.db import connection, transaction
24
from django.utils.timezone import utc
25 24
from django.utils.translation import ugettext as _
26 25

  
27 26
try:
bijoe/visualization/signature.py
21 21
import logging
22 22
import random
23 23
import urllib
24
import urllib.parse
24 25

  
25
from django.utils import six
26 26
from django.utils.encoding import force_bytes, smart_bytes
27 27
from django.utils.http import quote, urlencode
28
from django.utils.six.moves.urllib import parse as urlparse
29 28

  
30 29
'''Simple signature scheme for query strings'''
31 30
# from http://repos.entrouvert.org/portail-citoyen.git/tree/portail_citoyen/apps/data_source_plugin/signature.py
32 31

  
33 32

  
34 33
def sign_url(url, key, algo='sha256', timestamp=None, nonce=None):
35
    parsed = urlparse.urlparse(url)
34
    parsed = urllib.parse.urlparse(url)
36 35
    new_query = sign_query(parsed.query, key, algo, timestamp, nonce)
37
    return urlparse.urlunparse(parsed[:4] + (new_query,) + parsed[5:])
36
    return urllib.parse.urlunparse(parsed[:4] + (new_query,) + parsed[5:])
38 37

  
39 38

  
40 39
def sign_query(query, key, algo='sha256', timestamp=None, nonce=None):
......
59 58

  
60 59

  
61 60
def check_url(url, key, known_nonce=None, timedelta=30):
62
    parsed = urlparse.urlparse(url, 'https')
61
    parsed = urllib.parse.urlparse(url, 'https')
63 62
    return check_query(parsed.query, key)
64 63

  
65 64

  
......
74 73

  
75 74

  
76 75
def check_query2(query, key, known_nonce, timedelta):
77
    parsed = urlparse.parse_qs(query)
76
    parsed = urllib.parse.parse_qs(query)
78 77
    try:
79 78
        signature = parsed['signature'][0]
80 79
        algo = parsed['algo'][0]
tests/test_hobo_deploy.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 configparser
17 18
from contextlib import contextmanager
18 19

  
19 20
import pytest
20 21
import sentry_sdk
21
from django.utils.six.moves import configparser as ConfigParser
22 22
from psycopg2.extensions import parse_dsn
23 23

  
24 24
from bijoe.hobo_agent.management.commands import hobo_deploy
......
80 80
    wcs_olap_ini_path = tenant_dir / 'wcs-olap.ini'
81 81
    assert wcs_olap_ini_path.exists()
82 82
    with wcs_olap_ini_path.open() as fd:
83
        config = ConfigParser.SafeConfigParser()
83
        config = configparser.SafeConfigParser()
84 84
        config.readfp(fd)
85 85
        pg_dsn = config.get('wcs-olap', 'pg_dsn')
86 86
        parsed_pg_dsn = parse_dsn(pg_dsn)
......
119 119
    }
120 120
    command.deploy_specifics(hobo_environment, tenant)
121 121
    with wcs_olap_ini_path.open() as fd:
122
        config = ConfigParser.SafeConfigParser()
122
        config = configparser.SafeConfigParser()
123 123
        config.readfp(fd)
124 124
        assert config.get(wcs_base_url, 'orig') == 'bijoe.example.net'
125 125
        assert config.get(wcs_base_url, 'schema') == 'wcs_example_net'
......
134 134
    hobo_environment['services'][0]['base_url'] = 'https://new-bijoe.example.net'
135 135
    command.deploy_specifics(hobo_environment, tenant)
136 136
    with wcs_olap_ini_path.open() as fd:
137
        config = ConfigParser.SafeConfigParser()
137
        config = configparser.SafeConfigParser()
138 138
        config.readfp(fd)
139 139
        assert config.get(wcs_base_url, 'orig') == 'new-bijoe.example.net'
tests/test_import_export.py
3 3
import shutil
4 4
import sys
5 5
import tempfile
6
from io import StringIO
6 7

  
7 8
import pytest
8 9
from django.core.management import call_command
9 10
from django.utils.encoding import force_bytes
10
from django.utils.six import StringIO
11 11

  
12 12
from bijoe.utils import import_site
13 13
from bijoe.visualization.models import Visualization
tests/test_signature.py
16 16

  
17 17
# from https://git.entrouvert.org/hobo.git/tree/tests/test_signature.py
18 18
import datetime
19

  
20
from django.utils.six.moves.urllib import parse as urllib
19
import urllib.parse
21 20

  
22 21
from bijoe.visualization import signature
23 22

  
......
55 54

  
56 55
    # Test timedelta parameter
57 56
    now = datetime.datetime.utcnow()
58
    assert '&timestamp=%s' % urllib.quote(now.strftime('%Y-%m-%dT%H:%M:%SZ')) in signature.sign_url(
57
    assert '&timestamp=%s' % urllib.parse.quote(now.strftime('%Y-%m-%dT%H:%M:%SZ')) in signature.sign_url(
59 58
        URL, KEY, timestamp=now
60 59
    )
61 60

  
62
-