get url functions from six (#38781)

This commit is contained in:
Emmanuel Cazenave 2020-01-13 17:52:24 +01:00
parent 142312ed5e
commit 8922ebb5a3
3 changed files with 8 additions and 10 deletions

View File

@ -1,14 +1,13 @@
import pprint
import random
import urllib
from django.utils.six.moves.urllib import parse
import requests
def test_main(conn):
# get days
query_string = urllib.urlencode({
query_string = parse.urlencode({
'start_days': 1, 'end_days': 90, 'start_time': '10:00', 'end_time': '11:00',
'display': 'date'
})
@ -21,7 +20,7 @@ def test_main(conn):
assert data
# get places
query_string = urllib.urlencode({
query_string = parse.urlencode({
'start_days': 1, 'end_days': 90, 'start_time': '10:00', 'end_time': '11:00',
'display': 'place'
})
@ -35,7 +34,7 @@ def test_main(conn):
place = data[random.randint(0, len(data) - 1)]['id']
# get days on one place
query_string = urllib.urlencode({
query_string = parse.urlencode({
'start_days': 1, 'end_days': 90, 'start_time': '10:00', 'end_time': '11:00',
'place_id': place, 'display': 'date'
})

View File

@ -2,7 +2,6 @@ import datetime
import base64
import hmac
import hashlib
import urllib
import random
from django.utils import six
@ -25,12 +24,12 @@ def sign_query(query, key, algo='sha256', timestamp=None, nonce=None):
new_query = query
if new_query:
new_query += '&'
new_query += urllib.urlencode((
new_query += urlparse.urlencode((
('algo', algo),
('timestamp', timestamp),
('nonce', nonce)))
signature = base64.b64encode(sign_string(new_query, key, algo=algo))
new_query += '&signature=' + urllib.quote(signature)
new_query += '&signature=' + urlparse.quote(signature)
return new_query
def sign_string(s, key, algo='sha256', timedelta=30):

View File

@ -14,11 +14,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64
import urllib
from requests.exceptions import ConnectionError
from django.db import models
from django.utils.encoding import force_text
from django.utils.six.moves.urllib import parse
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse, Http404
@ -241,7 +241,7 @@ class IParapheur(BaseResource, HTTPResource):
response = HttpResponse(document['_value_1'],
content_type=document['contentType'])
ascii_filename = filename.encode('ascii', 'replace')
encoded_filename = urllib.quote(filename.encode('utf-8'), safe='')
encoded_filename = parse.quote(filename.encode('utf-8'), safe='')
response['Content-Disposition'] = 'inline; filename=%s; filename*=UTF-8\'\'%s' % (ascii_filename, encoded_filename)
return response