misc: remove usage of "six" module (#63687)
This commit is contained in:
parent
033a6a79f8
commit
7910ee76a4
|
@ -14,11 +14,10 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import configparser
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
import urllib.parse
|
||||||
from django.utils.six.moves import configparser as ConfigParser
|
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
@ -53,7 +52,7 @@ def truncate_pg_identifier(identifier, hash_length=6, force_hash=False):
|
||||||
|
|
||||||
|
|
||||||
def schema_from_url(url, hash_length=6):
|
def schema_from_url(url, hash_length=6):
|
||||||
netloc = urlparse.urlparse(url).netloc
|
netloc = urllib.parse.urlparse(url).netloc
|
||||||
assert netloc
|
assert netloc
|
||||||
domain = netloc.split(':')[0]
|
domain = netloc.split(':')[0]
|
||||||
pg_identifier = domain.replace('.', '_').replace('-', '_')
|
pg_identifier = domain.replace('.', '_').replace('-', '_')
|
||||||
|
@ -67,7 +66,7 @@ class Command(hobo_deploy.Command):
|
||||||
services = hobo_environment.get('services')
|
services = hobo_environment.get('services')
|
||||||
ini_file = os.path.join(tenant.get_directory(), 'wcs-olap.ini')
|
ini_file = os.path.join(tenant.get_directory(), 'wcs-olap.ini')
|
||||||
schemas_path = os.path.join(tenant.get_directory(), 'schemas')
|
schemas_path = os.path.join(tenant.get_directory(), 'schemas')
|
||||||
config = ConfigParser.SafeConfigParser()
|
config = configparser.SafeConfigParser()
|
||||||
config.read(ini_file)
|
config.read(ini_file)
|
||||||
|
|
||||||
self.configure_sentry(config)
|
self.configure_sentry(config)
|
||||||
|
@ -112,7 +111,7 @@ class Command(hobo_deploy.Command):
|
||||||
# in that case they need to be kept uptodate
|
# in that case they need to be kept uptodate
|
||||||
continue
|
continue
|
||||||
schema = schema_from_url(base_url)
|
schema = schema_from_url(base_url)
|
||||||
orig = urlparse.urlparse(this.get('base_url')).netloc.split(':')[0]
|
orig = urllib.parse.urlparse(this.get('base_url')).netloc.split(':')[0]
|
||||||
their_key = service.get('secret_key')
|
their_key = service.get('secret_key')
|
||||||
key = KnownServices.shared_secret(our_key, their_key)
|
key = KnownServices.shared_secret(our_key, their_key)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ import collections
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
|
|
||||||
from django.utils import six
|
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.functional import Promise
|
from django.utils.functional import Promise
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
|
@ -21,7 +21,6 @@ import os
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
from django.utils.timezone import utc
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -21,20 +21,19 @@ import hmac
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
import urllib
|
import urllib
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
from django.utils import six
|
|
||||||
from django.utils.encoding import force_bytes, smart_bytes
|
from django.utils.encoding import force_bytes, smart_bytes
|
||||||
from django.utils.http import quote, urlencode
|
from django.utils.http import quote, urlencode
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
|
||||||
|
|
||||||
'''Simple signature scheme for query strings'''
|
'''Simple signature scheme for query strings'''
|
||||||
# from http://repos.entrouvert.org/portail-citoyen.git/tree/portail_citoyen/apps/data_source_plugin/signature.py
|
# from http://repos.entrouvert.org/portail-citoyen.git/tree/portail_citoyen/apps/data_source_plugin/signature.py
|
||||||
|
|
||||||
|
|
||||||
def sign_url(url, key, algo='sha256', timestamp=None, nonce=None):
|
def sign_url(url, key, algo='sha256', timestamp=None, nonce=None):
|
||||||
parsed = urlparse.urlparse(url)
|
parsed = urllib.parse.urlparse(url)
|
||||||
new_query = sign_query(parsed.query, key, algo, timestamp, nonce)
|
new_query = sign_query(parsed.query, key, algo, timestamp, nonce)
|
||||||
return urlparse.urlunparse(parsed[:4] + (new_query,) + parsed[5:])
|
return urllib.parse.urlunparse(parsed[:4] + (new_query,) + parsed[5:])
|
||||||
|
|
||||||
|
|
||||||
def sign_query(query, key, algo='sha256', timestamp=None, nonce=None):
|
def sign_query(query, key, algo='sha256', timestamp=None, nonce=None):
|
||||||
|
@ -59,7 +58,7 @@ def sign_string(s, key, algo='sha256', timedelta=30):
|
||||||
|
|
||||||
|
|
||||||
def check_url(url, key, known_nonce=None, timedelta=30):
|
def check_url(url, key, known_nonce=None, timedelta=30):
|
||||||
parsed = urlparse.urlparse(url, 'https')
|
parsed = urllib.parse.urlparse(url, 'https')
|
||||||
return check_query(parsed.query, key)
|
return check_query(parsed.query, key)
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,7 +73,7 @@ def check_query(query, key, known_nonce=None, timedelta=30):
|
||||||
|
|
||||||
|
|
||||||
def check_query2(query, key, known_nonce, timedelta):
|
def check_query2(query, key, known_nonce, timedelta):
|
||||||
parsed = urlparse.parse_qs(query)
|
parsed = urllib.parse.parse_qs(query)
|
||||||
try:
|
try:
|
||||||
signature = parsed['signature'][0]
|
signature = parsed['signature'][0]
|
||||||
algo = parsed['algo'][0]
|
algo = parsed['algo'][0]
|
||||||
|
|
|
@ -14,11 +14,11 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import configparser
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
from django.utils.six.moves import configparser as ConfigParser
|
|
||||||
from psycopg2.extensions import parse_dsn
|
from psycopg2.extensions import parse_dsn
|
||||||
|
|
||||||
from bijoe.hobo_agent.management.commands import hobo_deploy
|
from bijoe.hobo_agent.management.commands import hobo_deploy
|
||||||
|
@ -80,7 +80,7 @@ def test_deploy_specifics(tmpdir, settings, monkeypatch, request, with_sentry):
|
||||||
wcs_olap_ini_path = tenant_dir / 'wcs-olap.ini'
|
wcs_olap_ini_path = tenant_dir / 'wcs-olap.ini'
|
||||||
assert wcs_olap_ini_path.exists()
|
assert wcs_olap_ini_path.exists()
|
||||||
with wcs_olap_ini_path.open() as fd:
|
with wcs_olap_ini_path.open() as fd:
|
||||||
config = ConfigParser.SafeConfigParser()
|
config = configparser.SafeConfigParser()
|
||||||
config.readfp(fd)
|
config.readfp(fd)
|
||||||
pg_dsn = config.get('wcs-olap', 'pg_dsn')
|
pg_dsn = config.get('wcs-olap', 'pg_dsn')
|
||||||
parsed_pg_dsn = parse_dsn(pg_dsn)
|
parsed_pg_dsn = parse_dsn(pg_dsn)
|
||||||
|
@ -119,7 +119,7 @@ def test_deploy_specifics(tmpdir, settings, monkeypatch, request, with_sentry):
|
||||||
}
|
}
|
||||||
command.deploy_specifics(hobo_environment, tenant)
|
command.deploy_specifics(hobo_environment, tenant)
|
||||||
with wcs_olap_ini_path.open() as fd:
|
with wcs_olap_ini_path.open() as fd:
|
||||||
config = ConfigParser.SafeConfigParser()
|
config = configparser.SafeConfigParser()
|
||||||
config.readfp(fd)
|
config.readfp(fd)
|
||||||
assert config.get(wcs_base_url, 'orig') == 'bijoe.example.net'
|
assert config.get(wcs_base_url, 'orig') == 'bijoe.example.net'
|
||||||
assert config.get(wcs_base_url, 'schema') == 'wcs_example_net'
|
assert config.get(wcs_base_url, 'schema') == 'wcs_example_net'
|
||||||
|
@ -134,6 +134,6 @@ def test_deploy_specifics(tmpdir, settings, monkeypatch, request, with_sentry):
|
||||||
hobo_environment['services'][0]['base_url'] = 'https://new-bijoe.example.net'
|
hobo_environment['services'][0]['base_url'] = 'https://new-bijoe.example.net'
|
||||||
command.deploy_specifics(hobo_environment, tenant)
|
command.deploy_specifics(hobo_environment, tenant)
|
||||||
with wcs_olap_ini_path.open() as fd:
|
with wcs_olap_ini_path.open() as fd:
|
||||||
config = ConfigParser.SafeConfigParser()
|
config = configparser.SafeConfigParser()
|
||||||
config.readfp(fd)
|
config.readfp(fd)
|
||||||
assert config.get(wcs_base_url, 'orig') == 'new-bijoe.example.net'
|
assert config.get(wcs_base_url, 'orig') == 'new-bijoe.example.net'
|
||||||
|
|
|
@ -3,11 +3,11 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
from django.utils.six import StringIO
|
|
||||||
|
|
||||||
from bijoe.utils import import_site
|
from bijoe.utils import import_site
|
||||||
from bijoe.visualization.models import Visualization
|
from bijoe.visualization.models import Visualization
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
|
|
||||||
# from https://git.entrouvert.org/hobo.git/tree/tests/test_signature.py
|
# from https://git.entrouvert.org/hobo.git/tree/tests/test_signature.py
|
||||||
import datetime
|
import datetime
|
||||||
|
import urllib.parse
|
||||||
from django.utils.six.moves.urllib import parse as urllib
|
|
||||||
|
|
||||||
from bijoe.visualization import signature
|
from bijoe.visualization import signature
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@ def test_signature():
|
||||||
|
|
||||||
# Test timedelta parameter
|
# Test timedelta parameter
|
||||||
now = datetime.datetime.utcnow()
|
now = datetime.datetime.utcnow()
|
||||||
assert '×tamp=%s' % urllib.quote(now.strftime('%Y-%m-%dT%H:%M:%SZ')) in signature.sign_url(
|
assert '×tamp=%s' % urllib.parse.quote(now.strftime('%Y-%m-%dT%H:%M:%SZ')) in signature.sign_url(
|
||||||
URL, KEY, timestamp=now
|
URL, KEY, timestamp=now
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue